Skip to content

Conversation

@epage
Copy link
Contributor

@epage epage commented Dec 19, 2025

This also makes artifact deps available for consistency purposes.

What does this PR try to resolve?

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,

How to test and review this PR?

The CARGO_BIN_EXE_ code now also runs during

  • cargo rustdoc --test <name>
  • build scripts
  • doctests

For build scripts and doctests, the unit filter means that nothing has changed.

For cargo rustdoc --test <name>, this technically fixes a bug where running that on a test that calls env!("CARGO_BIN_EXE_foo") would fail. However, --test is broken more generally and we've talked about removing it (#13427) so I didn't add tests to cover this.

Seeing as this is an implicit artifact

At this new location,
it will now run as part of `cargo rustdoc --test <name>`
which technically fixes a bug
but `--test` is not really supported (rust-lang#13427)
so I didn't mark this as a `fix` nor did I add tests.
This now runs in build scripts and doctests *but* the unit check should
prevent any side effects from happening.
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 added the T-cargo Team: Cargo label Dec 19, 2025
@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 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-build-scripts Area: build.rs scripts Command-run Command-test S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 19, 2025
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will need an FCP

@rustbot
Copy link
Collaborator

rustbot commented Dec 19, 2025

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.

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-build-scripts Area: build.rs scripts Command-run Command-test S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cargo Team: Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants