-
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
base: master
Are you sure you want to change the base?
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 |
a68a5eb
to
e49bf62
Compare
2af0c91
to
1a326c2
Compare
I think this PR is now complete to the point that I will mark this PR as ready to review. Since the last review I have:
r? @epage |
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.
From #15104 (comment)
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.
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.
From #15104 (comment)
@epage sure, I updated the PR description but let me know if I missed anything.
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.
From #15104 (comment)
Sorry if I wasn't clear but my discussion of testing strategy was in the context of tracking the categorization of artifacts. I'm not saying we have to exhaustively test it but we should think about it and document the choice made and why.
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.
Sorry, I think I misunderstood your request. (perhaps multiple times)
I added a doc comment at the top of build_dir.rs
with a summary of the test strategy for that file and the rational why.
Let me know if that is what you were asking for.
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.
In the ideal scenario, we verify
- each file listed under artifact-dir vs build-dir is in the right place
- ensure new files get categorized correctly
I'm assuming we can't meet that ideal. I would like to understand why we can't meet that ideal and understand how close we should get to it along with a call out of what gaps are left.
1a326c2
to
56836aa
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`.
This commits implements the seperation of the intermidate artifact directory (called "build directory") from the target directory. (see rust-lang#14125)
56836aa
to
6110e7d
Compare
☔ The latest upstream changes (possibly 321f14e) made this pull request unmergeable. Please resolve the merge conflicts. |
if !self.cli_unstable().build_dir { | ||
return self.target_dir(); | ||
} | ||
if let Some(dir) = self.get_env_os("CARGO_BUILD_DIR") { |
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.
I understand CARGO_BUILD_DIR
is proposed here because we already have CARGO_TARGET_DIR
. However I feel like CARGO_TARGET_DIR
was a mistake.
The build.build-dir
config already comes with a CARGO_BUILD_BUILD_DIR
environment variable for free. We may want to stick with it and stop stacking up extra environment variables.
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.
This is open for discussions btw.
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.
However I feel like
CARGO_TARGET_DIR
was a mistake.
Can I ask why you feel it was a mistake?
As a user of cargo I think it might be a bit confusing to see BUILD
show up twice in the same variable name.
It make sense when strictly following the Cargo configuration, but newcomers are often not aware of this.
I think there is value in providing a shortcut that is easily understandable.
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.
Can I ask why you feel it was a mistake?
It's a hindsight honestly. It is ideal to me that each environment variable maps to one configuration field, and vice versa. We have cargo --config
available already if people want to pass complex value.
CARGO_TARGET_DIR
is a standalone environment variable which cargo and other community tools need to handle specially and understand the precedence of these options. If it were only one CARGO_BUILD_TARGET_DIR
then people don't need to deal with two environment variables. And the --target-dir
flag can just be a alias equivalent to --config 'build.target-dir=foo'
, and could eliminate the special handling.
It make sense when strictly following the Cargo configuration, but newcomers are often not aware of this.
Could you elaborate a bit more on this? In the book there is a list of variables for each configuration field, which I assume no discovery issue here. (Could expand the doc of CARGO_BUILD_TARGET_DIR
, if the other one is removed, yet we won't remove it for sure.)
it might be a bit confusing to see BUILD show up twice in the same variable name.
Feel like it is a naming issue, regardless whether we have CARGO_BUILD_DIR
variable or not.
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.
And the --target-dir flag can just be a alias equivalent to --config 'build.target-dir=foo', and could eliminate the special handling.
The plan was to not offer a --build-dir
CLI option and build-dir would eventually be decoupled from --target-dir
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.
I think there is value in providing a shortcut that is easily understandable.
Not sure about “shortcut”. If you meant 6-character shorter yeah it is, though usablility depends on whether people type it everyday in interactive sessions. I would assume the majority of users set it once in shell startup script, or in ~/.cargo/config.toml
. Then the length doesn't really matter.
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.
This is unstable, so we don't have to have a final decision. The question is mostly if there is enough reason for or against it for the initial implementation.
While I lean towards CARGO_BUILD_DIR
, starting with fewer features makes it easier to identify when a feature is needed compared to when you offer everything, its hard to tell what is used and could be removed.
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.
Could you elaborate a bit more on this? In the book there is a list of variables for each configuration field, which I assume no discovery issue here. (Could expand the doc of CARGO_BUILD_TARGET_DIR, if the other one is removed, yet we won't remove it for sure.)
I think that anyone remotely familiar with Rust can fairly quickly understand CARGO_TARGET_DIR
does without going to the documentation page. Seeing CARGO_BUILD_BUILD_DIR
is much less obvious and will probably require some google searching to figure out what it does.
But perhaps to your later point, if people just set it once in their shared cargo config, perhaps it does not matter that much.
While I lean towards
CARGO_BUILD_DIR
, starting with fewer features makes it easier to identify when a feature is needed compared to when you offer everything, its hard to tell what is used and could be removed.
I think this is fair. I can remove it from this PR and we can revisit if it's really needed later
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.
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