Skip to content

Crater run for cargo build-dir changes#149852

Closed
ranger-ross wants to merge 1 commit into
rust-lang:mainfrom
ranger-ross:crater-run-cargo-build-dir-layout
Closed

Crater run for cargo build-dir changes#149852
ranger-ross wants to merge 1 commit into
rust-lang:mainfrom
ranger-ross:crater-run-cargo-build-dir-layout

Conversation

@ranger-ross

@ranger-ross ranger-ross commented Dec 10, 2025

Copy link
Copy Markdown
Member

View all comments

PR for crater run of rust-lang/cargo#16336
Before running, we should probably get a sanity check from @epage that there is nothing I missed.

See Zulip Thread

r? @Mark-Simulacrum

@rustbot

rustbot commented Dec 10, 2025

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/cargo

cc @ehuss

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 10, 2025
@rustbot

This comment has been minimized.

@ehuss

ehuss commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

Do you happen to know the crater command you want to run? (The command syntax is documented at https://github.com/rust-lang/crater/blob/master/docs/bot-usage.md)

@Kivooeo

Kivooeo commented Dec 10, 2025

Copy link
Copy Markdown
Member

Let's do try first and then run crater in check-only mode, at least this is how I understand this process

@bors try

@rust-bors

This comment has been minimized.

rust-bors Bot added a commit that referenced this pull request Dec 10, 2025
…, r=<try>

Crater run for cargo build-dir changes
@ehuss

ehuss commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

@Kivooeo IIUC, that's not going to be sufficient for this because the new layout is not enabled by default. There may be some special settings like environment variables that will be needed to test this properly. And as for the mode, I suspect we want to build, not check, because we'll want to see if build scripts or proc-macros are doing any shenanigans that are required for linking correctly. (Or maybe test I don't know.)

@rust-bors

rust-bors Bot commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 3117848 (311784882baa42a9638298cb325fa01a062c9d0f, parent: 198328ad7960b1bece0dc48496bff6c62dd5d339)

@epage

epage commented Dec 10, 2025

Copy link
Copy Markdown
Contributor

For this, you can either set -Zbuild-dir-new-layout or CARGO_BUILD_DIR_LAYOUT_V2=true.

Note that x.py can't build with this enabled, see #t-infra/bootstrap > Preparing for the new `build-dir` layout @ 💬

I guess build-only is desirable over check-only to ensure -sys crates link?

A full build-and-test run would help uncover how much people's tests are relying on internals (e.g. I recently fixed rustfmts tests).

@Mark-Simulacrum

Copy link
Copy Markdown
Member

@craterbot run mode=build-and-test start=master#198328ad7960b1bece0dc48496bff6c62dd5d339 end=try#311784882baa42a9638298cb325fa01a062c9d0f+cargoflags=-Zbuild-dir-new-layout crates=random-1000 p=1

Small run just to make sure it mostly works.

@craterbot

Copy link
Copy Markdown
Collaborator

👌 Experiment pr-149852 created and queued.
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 13, 2025
@bors

bors commented Dec 13, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #149934) made this pull request unmergeable. Please resolve the merge conflicts.

@craterbot

Copy link
Copy Markdown
Collaborator

🚧 Experiment pr-149852 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot

Copy link
Copy Markdown
Collaborator

🎉 Experiment pr-149852 is completed!
📊 2 regressed and 0 fixed (1000 total)
📊 0 spurious results on the retry-regessed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-149852/retry-regressed-list.txt

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Dec 17, 2025
@epage

epage commented Dec 17, 2025

Copy link
Copy Markdown
Contributor

Example from https://github.com/ikorason/headr at 7f4ae60bfd5efd605d9a7e2572ba482b3ac02551

[INFO] [stdout] ---- dies_bad_lines stdout ----
[INFO] [stdout] Error: CargoError { cause: Some(NotFoundError { path: "/opt/rustwide/target/debug/build/headr/757f0ead74b5dd7c/headr" }) }
  • Using assert_cmds deprecated Command::cargo_bin which I believe will fail even with a split target-dir / build-dir

Example from chute-kun 0.1.0

[INFO] [stdout] thread 'init_config_writes_default_toml_to_env_path' (150) panicked at tests/cli_init_config_test.rs:12:47:
[INFO] [stdout] called `Result::unwrap()` on an `Err` value: CargoError { cause: Some(NotFoundError { path: "/opt/rustwide/target/debug/build/chute-kun/f8f797d1537351f6/chute" }) }
  • Using assert_cmds deprecated Command::cargo_bin which I believe will fail even with a split target-dir / build-dir

@epage

epage commented Dec 18, 2025

Copy link
Copy Markdown
Contributor

Opened issues for assert_cmd's dependents that use the deprecated cargo_bin:

(skipped all with download counts below 100,000)

epage added a commit to epage/cargo that referenced this pull request Dec 19, 2025
This also makes artifact deps available for consistency purposes.

I originally proposed this for when moving Cargo off of Cargo's own
internals but went with a different solution.

Re-visiting this because `assert_cmd` has 2300+ dependents and it seems
like making `assert_cmd::cargo_bin` work would be a better use of time
than migrating all of those users to `assert_cmd::cargo_bin!`.
For example, within the top 130 dependents (100,000 downloads or more),
I found 66 that used `assert_cmd::cargo_bin`
(rust-lang/rust#149852).

> The reason to make `CARGO_BIN_EXE` set only at build-time was to
> address the concern of manually running the test executable.
> It's not
> too common for tests to look at any runtime environment variables
> (that I know of), so it usually just works (like running
> `gdb target/debug/.../test-xxx`).
> The concern was that if it were set at
> runtime it would move more down the path where directly running the test
> executable doesn't "just work".

See https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/cargo_bin_exe.20and.20tests/near/513638220

However,
- This is user opt-in
- Users can run with `-vv` to see the env variables that are set
- Users can run `CARGO_TARGET_..._RUNNER=gdb`
- We can notify the `cargo nextest`, the main third-party test runner,
  about this.  It should be easy to support as they have their own
  version of this, see https://nexte.st/docs/configuration/env-vars/?h=nextest_bin_exe#environment-variables-nextest-sets
@epage

epage commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

Realized a better route for this might be to move forward with making CARGO_BIN_EXE_* available at runtime, which I had previously proposed. cargo_bin could be updated to check that and people will just need to cargo update assert_cmd and it will just work. There will be a span of Cargo versions where CARGO_BUILD_BUILD_DIR will break the tests.

First step is rust-lang/cargo#16421

@Skgland

Skgland commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

making CARGO_BIN_EXE_* available at runtime, which I had previously proposed. cargo_bin could be updated to check that

Unless I'm mistaken it already does that.

Command::cargo_bin calls crate::cargo::cargo_bin_cmd1, which calls crate::cargo::cargo_bin2, which calls crate::cargo::cargo_bin_str which checks the env var3

Footnotes

  1. https://docs.rs/crate/assert_cmd/latest/source/src/cmd.rs#68

  2. https://docs.rs/crate/assert_cmd/latest/source/src/cargo.rs#155

  3. https://docs.rs/crate/assert_cmd/latest/source/src/cargo.rs#247-248

@epage

epage commented Dec 19, 2025

Copy link
Copy Markdown
Contributor

which checks the env var3

That is a bug and it always falls back to the unwrap_or_else case.

This was referenced Mar 11, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Apr 16, 2026
ranger-ross pushed a commit to ranger-ross/cargo that referenced this pull request Jul 6, 2026
*[View all
comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/cargo/pull/16807)*

### What does this PR try to resolve?

[FCP](rust-lang#16807 (comment))

This PR stabilizes the `build-dir` reorg tracked in rust-lang#15010

We have completed a crater runs
(rust-lang/rust#149852) as well a call for
testing
(https://blog.rust-lang.org/2026/03/13/call-for-testing-build-dir-layout-v2/)
with no issues reported.

At a recent Cargo meeting, we discussed the path towards stabilization:
* Stabilize `build-dir` layout v2, and merge into nightly shortly after
the 1.96 beta branch
* Allow a full nightly cycle for nightly users to report issues.
* Pending no major blockers, allow the stabilization to be included in
the Rust 1.97 beta (otherwise revert before beta branching)

This stabilization does NOT remove the code for the legacy `build-dir`
layout and enables `-Zbuild-dir-new-layout` by default. We also provide
a temporary `__CARGO_TEMPORARY_BUILD_DIR_NEW_LAYOUT_OPT_OUT` env var
that users can use to opt out. Note that this flag is temporary and only
meant to mitigate the transition. It will be removed in the next release
along with the legacy layout code.

The rational for this approach is that we may need to rollback the
changes before the next stabilization and removing the feature flag
would be a lot of changes that could result in a conflict. Keeping the
feature flag minimizes the code changes needed to stabilize and makes it
less risky if we need to revert.
The opt out flag is to provide a short term way for users opt if. This
is primarily intended for users that absolutely must use nightly and
rely on tools that expect the old layout.

closes rust-lang#15010

Flag/opt out priority: (highest to lowest)
* `-Zfine-grain-locking` (will always force enable the new layout)
* `__CARGO_TEMPORARY_BUILD_DIR_NEW_LAYOUT_OPT_OUT=1`
* `-Zbuild-dir-new-layout` (this will exist on nightly but be enabled by
default)

Note on the locking design:

We will defer changing `.cargo-artifact-lock` to `.cargo-lock` to reduce
the scope of this PR.
See
rust-lang#16807 (comment)
for the rational for why this is safe to do and forward compatible

### Pending tasks

- [x] Finish update tests
- [x] Update Cargo docs
- [x] Rustc bootstrap is blocking this PR [#t-infra/bootstrap > Has
anyone tested &rust-lang#96;./x&rust-lang#96; with the new build-dir
layout?](https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/Has.20anyone.20tested.20.60.2E.2Fx.60.20with.20the.20new.20build-dir.20layout.3F/with/581660716)
rust-lang/rust#155439

### How to test and review this PR?

There are a LOT of changes and I did my best to separate them into
isolated commits.
However the stabilization commit has a lot of path updates in many
tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants