-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Refactor Layout
into BuildDirLayout
and ArtifactDirLayout
#16092
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
Refactor Layout
into BuildDirLayout
and ArtifactDirLayout
#16092
Conversation
.all_kinds | ||
.iter() | ||
.map(|kind| build_runner.files().layout(*kind).doc()) | ||
.map(|kind| build_runner.files().layout(*kind).artifact_dir().doc()) |
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.
The separation of ArtifactDirLayout
and BuildDirLayout
makes sense, as it the actually layout of two directories a lot clearer.
However, I feel like it should be opaque to anything outside layout.rs. Other module shouldn't concern where those build caches are actually stored. Exposing fn artifact_dir()
and build_dir()
seems to expose a bit too many implementation details to me. What do you think?
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 it should be opaque to anything outside layout.rs. Other module shouldn't concern where those build caches are actually stored
I understand where you are coming from but I think exposing artifact_dir vs build_dir is necessary.
We already do that by duplicating functions like examples()
and build_examples()
. If we keep everything in Layout
we would probably eventually end up with root()
and build_root()
, dest()
and build_dest()
, etc.
At that point, I think its better to explicitly use the build_dir()
/artifact_dir()
to avoid confusion as to where the files are going.
Also I found that in most (all?) of the time I knew which directory I wanted move files to and the opaque nature of Layout
felt like it was hurting more than it was helping.
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.
For myself, I feel like exposing the split isn't about exposing implementation details but being clearer in communication and thinking about intermediate and final artifacts.
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.
Fair! Thanks for the discussion!
//! root-output | ||
//! # Stderr output from the build script. | ||
//! stderr | ||
//! |
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.
Semi-related to this PR: maybe we should update the module-level doc as well to reflect artifact-dir/build-dir changes so far
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.
Agreed! Was considering to bundle those changes in this PR but end up deferring to keep this PR focused on the refactor changes.
Will open a follow up PR for the docs
} | ||
} | ||
|
||
impl ArtifactDirLayout { |
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 generally prefer impl blocks to be next to their types.
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 can understand keeping it here in this commit to make it easier to review but would be good to move in a follow up commit
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.
sure, added that change in 6751e46
Seems there is a test in CI that started failing in Trying to hunt down which change caused this but it seemingly just needs to be blessed. |
It failed due to this rust-lang/rust#142390. We addressed it in advance by #16082 but not for nightly-only cargo tests. |
… `ArtifactDirLayout`
…rtifactDirLayout`
6751e46
to
03332a7
Compare
Update cargo 17 commits in 81c3f77a467359c8be6bc747dc93ec66a6e4ce11..367fd9f213750cd40317803dd0a5a3ce3f0c676d 2025-10-10 18:41:02 +0000 to 2025-10-15 15:01:32 +0000 - test: Don't look for a specfic ANSI color (rust-lang/cargo#16118) - docs(guide): Clarify where to set config (rust-lang/cargo#16107) - test(rustfix): re-enable disabled test due to unused variables (rust-lang/cargo#16114) - Convert the "manifest has no things" warning to annotate_snippets. (rust-lang/cargo#16113) - doc: make it clearer that `target.<cfg>.linker` is supported (rust-lang/cargo#16112) - docs(guide): Cover feature-unification (rust-lang/cargo#16108) - fix(gctx): types are unsupported not unknown (rust-lang/cargo#16109) - fix(script): Tweak cargo script build-dir / target-dir (rust-lang/cargo#16086) - docs(gctx): explain Value deserialization step-by-step (rust-lang/cargo#16105) - docs(guide): Talk about removing unused features (rust-lang/cargo#16085) - test(config): exercise unsupported TOML types (rust-lang/cargo#16100) - docs(gctx): a bit more of how config deserialization works (rust-lang/cargo#16094) - Refactor `Layout` into `BuildDirLayout` and `ArtifactDirLayout` (rust-lang/cargo#16092) - Add alternative linker to the build performance guide (rust-lang/cargo#15991) - refactor(gctx): extract error to a module (rust-lang/cargo#16091) - fix: Fixed nightly tests failing due to unused_variables lint (rust-lang/cargo#16098) - fix(script): Store cargo script lockfiles in build-dir (rust-lang/cargo#16087) r? ghost
Update cargo 17 commits in 81c3f77a467359c8be6bc747dc93ec66a6e4ce11..367fd9f213750cd40317803dd0a5a3ce3f0c676d 2025-10-10 18:41:02 +0000 to 2025-10-15 15:01:32 +0000 - test: Don't look for a specfic ANSI color (rust-lang/cargo#16118) - docs(guide): Clarify where to set config (rust-lang/cargo#16107) - test(rustfix): re-enable disabled test due to unused variables (rust-lang/cargo#16114) - Convert the "manifest has no things" warning to annotate_snippets. (rust-lang/cargo#16113) - doc: make it clearer that `target.<cfg>.linker` is supported (rust-lang/cargo#16112) - docs(guide): Cover feature-unification (rust-lang/cargo#16108) - fix(gctx): types are unsupported not unknown (rust-lang/cargo#16109) - fix(script): Tweak cargo script build-dir / target-dir (rust-lang/cargo#16086) - docs(gctx): explain Value deserialization step-by-step (rust-lang/cargo#16105) - docs(guide): Talk about removing unused features (rust-lang/cargo#16085) - test(config): exercise unsupported TOML types (rust-lang/cargo#16100) - docs(gctx): a bit more of how config deserialization works (rust-lang/cargo#16094) - Refactor `Layout` into `BuildDirLayout` and `ArtifactDirLayout` (rust-lang/cargo#16092) - Add alternative linker to the build performance guide (rust-lang/cargo#15991) - refactor(gctx): extract error to a module (rust-lang/cargo#16091) - fix: Fixed nightly tests failing due to unused_variables lint (rust-lang/cargo#16098) - fix(script): Store cargo script lockfiles in build-dir (rust-lang/cargo#16087) r? ghost
Update cargo 17 commits in 81c3f77a467359c8be6bc747dc93ec66a6e4ce11..367fd9f213750cd40317803dd0a5a3ce3f0c676d 2025-10-10 18:41:02 +0000 to 2025-10-15 15:01:32 +0000 - test: Don't look for a specfic ANSI color (rust-lang/cargo#16118) - docs(guide): Clarify where to set config (rust-lang/cargo#16107) - test(rustfix): re-enable disabled test due to unused variables (rust-lang/cargo#16114) - Convert the "manifest has no things" warning to annotate_snippets. (rust-lang/cargo#16113) - doc: make it clearer that `target.<cfg>.linker` is supported (rust-lang/cargo#16112) - docs(guide): Cover feature-unification (rust-lang/cargo#16108) - fix(gctx): types are unsupported not unknown (rust-lang/cargo#16109) - fix(script): Tweak cargo script build-dir / target-dir (rust-lang/cargo#16086) - docs(gctx): explain Value deserialization step-by-step (rust-lang/cargo#16105) - docs(guide): Talk about removing unused features (rust-lang/cargo#16085) - test(config): exercise unsupported TOML types (rust-lang/cargo#16100) - docs(gctx): a bit more of how config deserialization works (rust-lang/cargo#16094) - Refactor `Layout` into `BuildDirLayout` and `ArtifactDirLayout` (rust-lang/cargo#16092) - Add alternative linker to the build performance guide (rust-lang/cargo#15991) - refactor(gctx): extract error to a module (rust-lang/cargo#16091) - fix: Fixed nightly tests failing due to unused_variables lint (rust-lang/cargo#16098) - fix(script): Store cargo script lockfiles in build-dir (rust-lang/cargo#16087) r? ghost
What does this PR try to resolve?
After the recent
build-dir
changes, I believe theLayout
is now a bit overloaded now and no longer represents a single thing. For example its not immediately clear iffn root()
is the root of the build-dir or artifact-dir.Also duplicate functions are needed in some cases like
examples()
andbuild_examples()
.This PR splits the layout into multiple self contained
struct
s while keeping a high levelLayout
container struct.Note: I chose the
ArtifactDirLayout
overTargetDirLayout
as I believe that is the direction we are going in #6790 and there has been mention of eventually phasing out target-dir in the long term. (Though happy to change it if there is a good reason)How to test and review this PR?
The existing tests should be sufficient.
Best reviewed commit by commit.
timings()
to the layout to bring it in line with other directories intarget
Layout
internally while keeping the pub interface unchanged.Layout
public interface to expose.build_dir()
and.artifact_dir()
to make it explicit which directory is being used.