Skip to content

Enable Cargo's new build-dir layout in tests+ci#6879

Merged
ytmimi merged 2 commits intorust-lang:mainfrom
ranger-ross:build-with-cargo-build-dir-new-layout
Apr 29, 2026
Merged

Enable Cargo's new build-dir layout in tests+ci#6879
ytmimi merged 2 commits intorust-lang:mainfrom
ranger-ross:build-with-cargo-build-dir-new-layout

Conversation

@ranger-ross
Copy link
Copy Markdown
Member

Split out of rust-lang/rust#155439 which enables Cargo's new build-dir layout in tests and CI.

Background

Cargo is planning to stabilize a rework to the build-dir file layout tracked in rust-lang/cargo#15010. (Stabilization PR is currently in FPC rust-lang/cargo#16807)
Our last remaining blocker to merging is preparing rust-lang/rust to work with the new layout so the Cargo submodule can be merged after stabilization.

The build-dirs file system layout is considered an implementation detail of Cargo is subject to changes. Note that this is different than artifact-dir which is stable. (Together these are usually referred to as the target-dir)

Changes

This PR has 2 commits:

  1. Add backwards compatible changes to the rustfmt tests to properly handle the new layout
  2. Enable the new layout in CI using CARGO_UNSTABLE_BUILD_DIR_NEW_LAYOUT

cc: @ytmimi

@rustbot rustbot added A-CI Area: CI S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Apr 29, 2026
Comment thread src/test/mod.rs Outdated
if me.ends_with("deps") {
// Chop off `deps`.
me.pop();
} else {
Copy link
Copy Markdown
Contributor

@ytmimi ytmimi Apr 29, 2026

Choose a reason for hiding this comment

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

Let's keep things consistent with cargo_fmt. Ideally we'd have a single helper function that we could reuse for both so that we didn't have to duplicate this logic.

Suggested change
} else {
} else if bin_dir.ends_with("out") {

View changes since the review

Copy link
Copy Markdown
Member Author

@ranger-ross ranger-ross Apr 29, 2026

Choose a reason for hiding this comment

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

Sure good catch. Added!

I didn't see an easy way to share a helper function here, so I kept it as duplicated :/
Lmk if you think there is a nice way to do that or if we should keep it duplicated.

@rustbot ready

Comment thread tests/cargo-fmt/main.rs
@@ -12,6 +12,11 @@ fn cargo_fmt(args: &[&str]) -> (String, String) {
bin_dir.pop(); // chop off test exe name
if bin_dir.ends_with("deps") {
Copy link
Copy Markdown
Contributor

@ytmimi ytmimi Apr 29, 2026

Choose a reason for hiding this comment

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

Would be great to add the same comment here about the v1 and v2 build dirs:

    // Handle Cargo's old and new filesystem layouts
    // * v1: `target/<profile>/deps/test-bin-[HASH][EXE]`
    // * v2: `target/<profile>/build/<pkgname>/[HASH]/out/test-bin-[HASH][EXE]`

View changes since the review

@ytmimi
Copy link
Copy Markdown
Contributor

ytmimi commented Apr 29, 2026

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Apr 29, 2026
@ranger-ross ranger-ross force-pushed the build-with-cargo-build-dir-new-layout branch from f5d8a90 to 2ae5398 Compare April 29, 2026 13:46
@rustbot rustbot added S-waiting-on-review Status: awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: awaiting some action (such as code changes or more information) from the author. labels Apr 29, 2026
Copy link
Copy Markdown
Contributor

@ytmimi ytmimi left a comment

Choose a reason for hiding this comment

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

We can keep it duplicated for now. Thanks for working on this.

View changes since this review

@ytmimi ytmimi merged commit ef22670 into rust-lang:main Apr 29, 2026
26 checks passed
@rustbot rustbot added release-notes Needs an associated changelog entry and removed S-waiting-on-review Status: awaiting review from the assignee but also interested parties. labels Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-CI Area: CI release-notes Needs an associated changelog entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants