Implemented `build.build-dir` config option by ranger-ross · Pull Request #15104 · rust-lang/cargo
ranger-ross
changed the title
Added build-directory unstable feature flag
Implemented build.build-dir config option
epage
mentioned this pull request
22 tasks
This commits implements the seperation of the intermidate artifact directory (called "build directory") from the target directory. (see rust-lang#14125)
epage
mentioned this pull request
JeillZhang pushed a commit to JeillZhang/cargo that referenced this pull request
Mar 17, 2025### What does this PR try to resolve? This PR is a follow up on rust-lang#15104 and and adds support for the path templating in `build.build-dir` as defined in rust-lang#14125. Supported templates: * `{workspace-root}` * `{cargo-cache}` (pointing to `CARGO_HOME` for now) * `{workspace-manifest-path-hash}` #### Unresolved questions What should we name `{workspace-manifest-path-hash}` and what should it include? Should we shorten to `{workspace-hash}` or even just `{hash}`? Should we include the Cargo version so we get unique whole-target directories for easier cleanup (rust-lang#13136) How should this handle unknown variables (error) or unclosed `{` / `}` (ignored), see rust-lang#15236 (comment) When using `{workspace-manifest-path-hash}` this hash will change based on the project path. In the event of a cargo being executed in a symlinked project, the hash will change. For example, given the following directory ``` /Users/ └─ user1/ └─ projects/ ├─ actual-crate/ │ └─ Cargo.toml └─ symlink-to-crate/ -> actual-crate/ ``` the hash will be unique when running cargo from each of the following directories. * `/Users/user1/actual-crate` * `/Users/user1/symlink-to-crate` Figuring out whether to handle this is deferred out, see - rust-lang#15236 (comment) - https://github.com/poliorcetics/rfcs/blob/cargo-target-directories/text/3371-cargo-target-dir-templates.md#symbolic-links - rust-lang#12207 (comment) ### How should we test and review this PR? This PR is fairly small. I included tests for each template variable. You can also clone my branch and test it locally with ```console CARGO_BUILD_BUILD_DIR='{workspace-root}/foo' cargo -Z build-dir build ``` ### Additional information While searching Cargo for any prior art for path templating, I found [`sources/registry/download.rs`](https://github.com/rust-lang/cargo/blob/master/src/cargo/sources/registry/download.rs#L84) doing a simple string replace. Thus I followed the same behavior. r? @epage
sylfn
mentioned this pull request
11 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters