Skip to content

Conversation

ranger-ross
Copy link
Member

@ranger-ross ranger-ross commented Oct 12, 2025

What does this PR try to resolve?

After the recent build-dir changes, I believe the Layout is now a bit overloaded now and no longer represents a single thing. For example its not immediately clear if fn root() is the root of the build-dir or artifact-dir.
Also duplicate functions are needed in some cases like examples() and build_examples().

This PR splits the layout into multiple self contained structs while keeping a high level Layout container struct.

Note: I chose the ArtifactDirLayout over TargetDirLayout 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.

  1. The first commit adds a timings() to the layout to bring it in line with other directories in target
  2. Split Layout internally while keeping the pub interface unchanged.
  3. Change the Layout public interface to expose .build_dir() and .artifact_dir() to make it explicit which directory is being used.

@rustbot
Copy link
Collaborator

rustbot commented Oct 12, 2025

r? @ehuss

rustbot has assigned @ehuss.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-build-execution Area: anything dealing with executing the compiler A-cfg-expr Area: Platform cfg expressions A-dep-info Area: dep-info, .d files A-layout Area: target output directory layout, naming, and organization A-timings Area: timings Command-clean S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 12, 2025
.all_kinds
.iter()
.map(|kind| build_runner.files().layout(*kind).doc())
.map(|kind| build_runner.files().layout(*kind).artifact_dir().doc())
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member

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
//!
Copy link
Member

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

Copy link
Member Author

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 {
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member Author

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

@ranger-ross
Copy link
Member Author

Seems there is a test in CI that started failing in nightly-2025-10-13.

Trying to hunt down which change caused this but it seemingly just needs to be blessed.

@weihanglo
Copy link
Member

It failed due to this rust-lang/rust#142390. We addressed it in advance by #16082 but not for nightly-only cargo tests.

@ranger-ross ranger-ross force-pushed the refactor-layout-struct branch from 6751e46 to 03332a7 Compare October 13, 2025 16:57
@weihanglo weihanglo enabled auto-merge October 13, 2025 16:59
@weihanglo weihanglo added this pull request to the merge queue Oct 13, 2025
Merged via the queue into rust-lang:master with commit 6f3896d Oct 13, 2025
25 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 13, 2025
@ranger-ross ranger-ross deleted the refactor-layout-struct branch October 14, 2025 14:29
bors added a commit to rust-lang/rust that referenced this pull request Oct 15, 2025
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
@rustbot rustbot added this to the 1.92.0 milestone Oct 15, 2025
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Oct 16, 2025
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
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Oct 18, 2025
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-build-execution Area: anything dealing with executing the compiler A-cfg-expr Area: Platform cfg expressions A-dep-info Area: dep-info, .d files A-layout Area: target output directory layout, naming, and organization A-timings Area: timings Command-clean

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants