-
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
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.
We usually add some tests verifying a nightly flag is really gated.
@@ -290,7 +290,9 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> { | |||
}); | |||
} | |||
|
|||
super::output_depinfo(&mut self, unit)?; | |||
if !self.bcx.gctx.cli_unstable().build_dir { | |||
super::output_depinfo(&mut self, unit)?; |
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.
Why do we stop generating this when build-dir
is enabled?
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, actually I believe this is a mistake on my part 😅
My original assumption was that the /target/debug/{project-name}.d
file was the same file as /target/debug/deps/{project-name}-{hash}.d
, so I was trying to avoid copying it into target
.
But now that I compared the files they appear to be different so it looks like that was a bad assumption.
I believe this should probably be considered an intermediate build artifact so it should probably be moved to the build-dir
location.
Modifying this file in particular was a bit tricky as it was not just replacing .target_dir()
with .build_dir()
.
I think I will probably need to go to where the OutputFile
is created and modify the hardlink
to be the new build-dir path.
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.
Given this comment I am going to revert this change
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
|
## build-dir | ||
* Original Issue: [#14125](https://github.com/rust-lang/cargo/issues/14125) | ||
* Tracking Issue: [#14125](https://github.com/rust-lang/cargo/issues/14125) | ||
|
||
This feature allows you to specify the directory where intermediate build artifacts will be stored. | ||
The final artifacts will also be contained in this directory but will be hardlinked into the artifact directory (usually `target`) | ||
|
||
This can be specified in `.cargo/config.toml` files using the `build.build-dir`. | ||
|
||
Example: | ||
|
||
```toml | ||
[build] | ||
build-dir = "out" | ||
``` |
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 include documentation in this that mirrors what would be in https://doc.rust-lang.org/cargo/reference/config.html
src/cargo/core/compiler/layout.rs
Outdated
/// Same as `_lock` but for the build directory. | ||
/// | ||
/// NOTE: `_lock` and `_build_lock` can eventually be merged once #14125 is stablized. | ||
/// Will be `None` when the build-directory and target-directory are the same path as we cannot | ||
/// lock the same path twice. |
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.
How can we merge these locks?
In the short term, we'll have
- target-dir
- build-dir
which both need locking
In the long term, we'll have
- artifact-dir
- build-dir
which will both need locking
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, you are right. Not quiet sure what I was thinking when I wrote this comment.
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.
Also, we generally add (passing) tests before the change so the affect of the change is obvious.
This is more straightforward when fixing a bug. In a case like this, a common option is to write the tests without the new feature or using something similar ( like target-dir
) and then in the commit where the feature is added, you switch over the tests.
assert!(p.root().join("target/debug/foo").is_file()); | ||
} | ||
|
||
fn assert_build_dir(path: PathBuf, profile: &str, is_build_dir: bool) { |
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.
#[track_caller]
?
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 |
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. |
6dec044
to
9ee678b
Compare
9ee678b
to
dd06427
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)
This commit add the ability to use predefined variables when specifying the `build.build-dir` in the Cargo configuration. The currently supported template variables are: * `{workspace-root}` which will expand to the Cargo workspace root * `{cargo-cache}` which will expand to `CARGO_HOME` but will likely change in the future. * `{workspace-manifest-path-hash}` which will expand to a short hash of the workspace manifest's path.
dd06427
to
f53007f
Compare
I spent some more time this weekend making some progress on this PR. Here are my updates
I updated the PR description with more details as well. notably:
|
(still a work in progress)
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)Intermediate build artifact
These are files that are used internally by Cargo/Rustc during the build process
OUT_DIR
target/build
)examples
that contain the hash in the name)CARGO_TARGET_TMPDIR
files (see rational for this here)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 😅)
Testing Strategy
rand
to verify files are being output to the correct directory.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 #6790TODO
cargo clean
build.build-dir
target/examples
still containing "pre-uplifted" binariesbuild-dir
with non-bin crate types