-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented build.build-dir
config option
#15104
Conversation
build.build-dir
config option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to make sure I didn't miss something. From what I can tell these directories/files have been removed right?
target/<profile>/.metabuild
target/<profile>/.fingerprint
target/<profile>/deps
target/<profile>/incremental
target/<profile>/build
target/.cargo-lock
target/tmp
target/.rustc_info.json
Yes, that with the exception of Ideally in the longer term it can be removed in favor of fine grain locking like #4282 So a typical
|
It should clean the build dir |
imo The artifact for |
Can we call out explicitly what our testing strategy is? We likely should also explicitly document in the PR what is considered an artifact and what is a build output and make sure we have tests for these. |
One other question that came to my mind was the output of Perhaps symlinking the |
@epage sure, I updated the PR description but let me know if I missed anything. |
imo |
There are multiple types of depinfo files. I suspect the ones next to final artifacts are also considered final artifacts, see https://doc.rust-lang.org/cargo/reference/build-cache.html#dep-info-files |
FYI I added to the PR description a couple more intermediate artifacts
When are workspace member rlibs considered final artifacts? We're putting them in |
56836aa
to
6110e7d
Compare
This comment has been minimized.
This comment has been minimized.
let dest = root.join(dest); | ||
// If the root directory doesn't already exist go ahead and create it | ||
// here. Use this opportunity to exclude it from backups as well if the | ||
// system supports it since this is a freshly created folder. | ||
// | ||
paths::create_dir_all_excluded_from_backups_atomic(root.as_path_unlocked())?; | ||
if root != build_root { | ||
paths::create_dir_all_excluded_from_backups_atomic(build_root.as_path_unlocked())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6110e7d
to
f166762
Compare
f166762
to
d0bdff0
Compare
These ares are in preparation to split target-dir into artifact-dir and build-dir
This is in preparation for splitting the intermediate build artifacts from the `target` directory.
This commit adds a `build_dir` option to the `build` table in `config.toml` and adds the equivalent field to `Workspace` and `GlobalContext`.
d0bdff0
to
dca7eb5
Compare
Rebased to pick up the CI fixes in #15222 to hopefully make CI green |
This commits implements the seperation of the intermidate artifact directory (called "build directory") from the target directory. (see rust-lang#14125)
dca7eb5
to
5874b6f
Compare
Thanks for putting in all this work on this! |
Update cargo 11 commits in 1d1d646c06a84c1aa53967b394b7f1218f85db82..2622e844bc1e2e6123e54e94e4706f7b6195ce3d 2025-02-21 21:38:53 +0000 to 2025-02-28 12:33:57 +0000 - Bump `cc` to 1.2.16 to fix `x86` windows jobs in rust-lang/rust CI (rust-lang/cargo#15245) - refactor(tree): Abstract the concept of a NodeId (rust-lang/cargo#15237) - feat: implement RFC 3553 to add SBOM support (rust-lang/cargo#13709) - refactor(tree): Abstract the concept of an edge (rust-lang/cargo#15233) - chore: bump openssl to v3 (rust-lang/cargo#15232) - fix(package): Register workspace member renames in overlay (rust-lang/cargo#15228) - Implemented `build.build-dir` config option (rust-lang/cargo#15104) - feat: add completions for `--manifest-path` (rust-lang/cargo#15225) - chore: semver-check build-rs against beta channel (rust-lang/cargo#15223) - chore: depend on openssl-sys to correctly pin its version (rust-lang/cargo#15224) - chore: dont check cargo-util semver until 1.86 is released (rust-lang/cargo#15222)
What does this PR try to resolve?
This PR adds a new
build.build-dir
configuration option that was proposed in #14125 (comment)This new config option allows the user to specify a directory where intermediate build artifacts should be stored.
I have shortened it to just
build-dir
fromtarget-build-dir
, although naming is still subject to change.What is a final artifact vs an intermediate build artifact
Final artifacts
These are the files that end users will typically want to access directly or indirectly via a third party tool.
.crate
files output fromcargo package
.d
files) for third party build-system integrations (see https://github.com/rust-lang/cargo/blob/master/src/cargo/core/compiler/fingerprint/mod.rs#L194)cargo doc
output (html/css/js/etc)--timings
HTML reportIntermediate build artifact, caches, and state
These are files that are used internally by Cargo/Rustc during the build process
OUT_DIR
target/build
)cargo package
verify step.rustc_info.json
)examples
that contain the hash in the name, bins forbenches
, proc macros, build scripts)CARGO_TARGET_TMPDIR
files (see rational for this here).future-incompat-report.json
fileFeature Gating Strategy
We are following the "Ignore the feature that is used without a gate" approach as described here.
The rational for this is:
The
build.build-dir
is likely going to be set by by users "globally" (ie.$CARGO_HOME/config.toml
) to set a shared build directory to reduce rebuilding dependencies. For users that multiple cargo versions having having an error would be disrupted.The fallback behavior is to revert to the behavior of the current stable release (building in
$CARGO_TARGET_DIR
)Testing Strategy
rand
to verify files are being output to the correct directory.How should we test and review this PR?
This is probably best reviewed commit by commit. I documented each commit.
I tied to follow the atomic commits recommendation in the Cargo contributors guide, but I split out some commits for ease of review. (Otherwise I think this would have ended up being 1 or 2 large commits 😅)
Questions
cargo clean
?target
and does not impact the build-dir but this is easily changable.build.build-dir
config option #15104 (comment)cargo package
are was expecting just the.crate
file to be intarget
while all other output be stored inbuild.build-dir
? Not sure if we consider things likeCargo.toml
,Cargo.toml.orig
,.cargo_vcs_info.json
part of the user facing interface..crate
is considered a final artifactcargo doc
output go? HTML/JS for many crates can be pretty large. Moving to the build-dir would help reduce duplication if we find the that acceptable. Forcargo doc --open
this is not a problem but may be problematic for other use cases?build.build-dir
config option #15104 (comment)benches
considered final artifacts?examples
are considered final artifacts, it seems natural thatbenches
should also be considered final artifacts. However, unlikeexamples
thebenches
bins are stored intarget/{profile}/deps
instead of a dedicated directory (liketarget/{profile}/examples
). We could move them into a dedicated directory (target/{profile}/benches
) but that mean would also be changing the structure of thetarget
directory which feels out of scope for this change. If we decide thatbenches
are final artifacts, it would probably be better to consider that changes as part of--artifact-dir
(nee--out-dir
) Tracking Issue #6790build.build-dir
config option #15104 (comment)CARGO_BUILD_DIR
shortcut env var?CARGO_BUILD_DIR
shortcut. This can be removed before merging if there a good reason to.TODO
cargo clean
Implement templating forbuild.build-dir
target/examples
still containing "pre-uplifted" binariesbuild-dir
with non-bin crate types