Skip to content

Enable Cargo's new build-dir layout in boostrap#155439

Open
ranger-ross wants to merge 1 commit intorust-lang:mainfrom
ranger-ross:cargo-new-build-dir-layout
Open

Enable Cargo's new build-dir layout in boostrap#155439
ranger-ross wants to merge 1 commit intorust-lang:mainfrom
ranger-ross:cargo-new-build-dir-layout

Conversation

@ranger-ross
Copy link
Copy Markdown
Member

This PR enables the new Cargo build-dir layout in boostrap builds with -Zbuild-dir-new-layout.

See: #t-infra/bootstrap > Has anyone tested `./x` with the new build-dir layout?

Tracked in: rust-lang/cargo#15010

r? @bjorn3

cc: @epage

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Apr 17, 2026
let target_root_dir = stamp.path().parent().unwrap();
// `target_deps_dir` looks like $dir/$target/release/deps
let target_deps_dir = target_root_dir.join("deps");
// `target_deps_dir` looks like $dir/$target/release/build
Copy link
Copy Markdown
Member

@bjorn3 bjorn3 Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// `target_deps_dir` looks like $dir/$target/release/build
// `target_build_dir` looks like $dir/$target/release/build

View changes since the review

// got a list of prefix/extensions and we basically just need to find the
// most recent file in the `deps` folder corresponding to each one.
let contents = target_deps_dir
// most recent file in the `build` folder corresponding to each one.
Copy link
Copy Markdown
Member

@weihanglo weihanglo Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet read the code by myself. Just wonder why bootstrap are doing this? And if bootstrap needs to do it, it should be a feature in Cargo, at least a (perma-)unstable feature.

View changes since the review

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the commit block around line 2374. Basically we need the non-uplifted name that contains the unique hash. The artifact notifications provide the uplifted name where possible.

@rust-log-analyzer

This comment has been minimized.

@ranger-ross ranger-ross force-pushed the cargo-new-build-dir-layout branch from bf07fb8 to eae2cbf Compare April 17, 2026 15:27
//
// Cargo's build folder is structured as `build/<pkg>/<hash>/out/<artifacts>` so
// we need to traverse multiple directory layers to get to actual files.
let read_dir = |path: &Path| path.read_dir().ok().into_iter().flatten().filter_map(Result::ok);
Copy link
Copy Markdown
Member Author

@ranger-ross ranger-ross Apr 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checks failed because if there are any lingering files/dirs in <build-dir>/<target>/build that are not using the new layout it panics.

Update the original code to not panic if we call .read_dir() on a non-directory. Lets see if CI is happy with this

View changes since the review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants