-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(test): Make CARGO_BIN_EXE_ available at runtime #16421
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
epage
wants to merge
7
commits into
rust-lang:master
Choose a base branch
from
epage:test
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
Collaborator
epage
commented
Dec 19, 2025
Contributor
Author
There was a problem hiding this comment.
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
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. |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_cmdhas 2300+ dependents and it seemslike making
assert_cmd::cargo_binwork would be a better use of timethan 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).
See https://rust-lang.zulipchat.com/#narrow/channel/246057-t-cargo/topic/cargo_bin_exe.20and.20tests/near/513638220
However,
-vvto see the env variables that are setCARGO_TARGET_..._RUNNER=gdbcargo 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
How to test and review this PR?
The
CARGO_BIN_EXE_code now also runs duringcargo rustdoc --test <name>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 callsenv!("CARGO_BIN_EXE_foo")would fail. However,--testis broken more generally and we've talked about removing it (#13427) so I didn't add tests to cover this.