Skip to content

Set a target for build scripts' products #5457

@kornelski

Description

@kornelski

From tmccombs:

Cargo exports an “OUT_DIR” environment variable to build scripts so that build scripts can store outputs there. And for generated source code this is fine. However when generating final artifacts that should be distributed with the binary, such as documentation (man pages) or shell completion scripts, storing them in the OUT_DIR is somewhat problematic. Not only is OUT_DIR different per package, but the path has some kind of hash in it, and isn’t included in the output of cargo metadata. Which makes such artifacts difficult to discover with tools like cargo-deb or to write robust packaging scripts.

As a specific example, ripgrep uses clap to generate shell completion scripts, which it stores in the OUT_DIR, and the maintainer uses cargo-deb to produce debian packages. However, the resulting debs don’t contain the completion scripts. cargo-deb has a way to specify additional assets by path to include, but since the OUT_DIR isn’t fixed, it isn’t possible to specify a fixed path for the completion scripts.


Currently CARGO_TARGET_DIR is read by Cargo. It would be useful if Cargo also set it (if not set already) to the actual value it uses.

It doesn't have to be literally CARGO_TARGET_DIR env variable, it could also be a directive that tells Cargo to place a file there, or another OUT_DIR-like directory for more permanent products.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions