Skip to content

Enable build-dir layout v2 on nightly by default#17258

Merged
weihanglo merged 2 commits into
rust-lang:masterfrom
ranger-ross:enable-build-dir-layout-nightly
Jul 24, 2026
Merged

Enable build-dir layout v2 on nightly by default#17258
weihanglo merged 2 commits into
rust-lang:masterfrom
ranger-ross:enable-build-dir-layout-nightly

Conversation

@ranger-ross

Copy link
Copy Markdown
Member

What does this PR try to resolve?

This PR enables the new build-dir on nightly by default.

The majority of changes were taken/adapted from #16807

Tracked in #15010

How to test and review this PR?

Same as the original stabilization PR.
The notable changes are:

  • A handful of tests may recompile crates when test's p.cargo() use a mixture of stable and nightly
    • For checksum freshness specifically, I enabled nightly on all of the p.cargo() as the tests are specifically testing for rebuilds.

@rustbot rustbot added the A-unstable Area: nightly unstable support label Jul 23, 2026
@ranger-ross
ranger-ross force-pushed the enable-build-dir-layout-nightly branch 7 times, most recently from 3f297a4 to d34b4b3 Compare July 23, 2026 15:27
@ranger-ross
ranger-ross marked this pull request as ready for review July 23, 2026 17:01
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2026
@rustbot

rustbot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

r? @epage

rustbot has assigned @epage.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @epage, @weihanglo
  • @epage, @weihanglo expanded to epage, weihanglo
  • Random selection from epage, weihanglo

@ranger-ross

Copy link
Copy Markdown
Member Author

Marking this as ready to review.

I spent some time trying to reproduce sccache failures with argfiles on windows, and couldn't get a failure. (tested on zed again, with __CARGO_TEST_FORCE_ARGFILE but it just worked)
I still wanna tinker on it some more, but I think it should at least be okay on the happy path which makes me more comfortable at least trying it on nightly.

Comment thread src/workspace/features.rs
/// gating unstable functionality to Cargo. These flags are only available on
/// the nightly channel of Cargo.
#[derive(Default, Debug, Deserialize)]
#[derive(Debug, Deserialize)]

@epage epage Jul 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a way to do this without removing Default? This makes it more invasive to undo and redo.

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ehh its get awkward to avoid, specially due to #[serde(default)].

I split out a refactor commit and manually impl'd Default in the macro to reduce the bloat and need to update the Default impl when adding new features.
It's still not ideal but maybe a bit better?

@ranger-ross
ranger-ross force-pushed the enable-build-dir-layout-nightly branch from d34b4b3 to 4bb796b Compare July 24, 2026 01:49
@rustbot rustbot added the A-dependency-resolution Area: dependency resolution and the resolver label Jul 24, 2026
@rustbot

This comment has been minimized.

@ranger-ross
ranger-ross force-pushed the enable-build-dir-layout-nightly branch from 4bb796b to 7b66084 Compare July 24, 2026 01:50
@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Comment thread src/workspace/features.rs Outdated
// Defaults to enabled on nightly unless explicitly opted out.
let c = &channel();
unstable.build_dir_new_layout =
(c == "nightly" || c == "dev") && !is_new_build_dir_layout_opt_out();

@weihanglo weihanglo Jul 24, 2026

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.

Josh (or someone I don't remember) has mentioned there are people using stable toolchains but enable RUSTC_BOOTSTRAP=1 for enabling some unstable features. Should we avoid enable it if the toolchain is stable/beta?

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It was @Mark-Simulacrum that mentioned it here.
Yeah, I think that makes sense. When that comment was made it kind of went over my head (we have so many bespoke config options 😆)

If I understand it correctly, enabling RUSTC_BOOTSTRAP=1 will result in Cargo using the dev channel.

if let Ok(staging) = env::var("RUSTC_BOOTSTRAP") {
if staging == "1" {
return "dev".to_string();
}

So the logic should be updated to

let is_rustc_bootstrap = env::var("RUSTC_BOOTSTRAP").map(|o| &o == "1");
unstable.build_dir_new_layout = (c == "nightly" || c == "dev") && !is_new_build_dir_layout_opt_out() && !is_rustc_bootstrap;

Will this cause an issues in bootstrap? I guess not since bootstrap explicitly passes -Zbuild-dir-new-layout and this is just for the defaults.

Does that all sound correct?

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.

Either that or just something like crate::version().release_channel == Some("nightly" | "dev")?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ah yeah that should work. I wish I had thought of this before updating all of the tests again. 🫠

Since this skips __CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS none of the tests need to be updated

@ranger-ross
ranger-ross force-pushed the enable-build-dir-layout-nightly branch from 7b66084 to d035da6 Compare July 24, 2026 04:53

@weihanglo weihanglo left a comment

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.

@weihanglo
weihanglo added this pull request to the merge queue Jul 24, 2026
Merged via the queue into rust-lang:master with commit 95303e6 Jul 24, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 24, 2026
weihanglo added a commit to weihanglo/rust that referenced this pull request Jul 24, 2026
Cargo enables build-dir layout v2 by default on nightly
(rust-lang/cargo#17258).
Intermediate build artifacts no longer live in
`<target-dir>/<triple>/<profile>/deps/`
but in per-unit `build/<pkg>/<hash>/out/` directories.

Search the target directory recursively
instead of hardcoding the artifact location,
so these tests pass under both the old and the new layout.
weihanglo added a commit to weihanglo/rust that referenced this pull request Jul 24, 2026
Cargo enables build-dir layout v2 by default on nightly
(rust-lang/cargo#17258).
Intermediate build artifacts no longer live in
`<target-dir>/<triple>/<profile>/deps/`
but in per-unit `build/<pkg>/<hash>/out/` directories.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-dependency-resolution Area: dependency resolution and the resolver A-unstable Area: nightly unstable support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants