Skip to content

Add support to use rustc --print=cfg as fallback to resolve target information#3331

Merged
sunshowers merged 6 commits into
nextest-rs:mainfrom
mhatzl:mh/rustc-cfg-target-support
May 13, 2026
Merged

Add support to use rustc --print=cfg as fallback to resolve target information#3331
sunshowers merged 6 commits into
nextest-rs:mainfrom
mhatzl:mh/rustc-cfg-target-support

Conversation

@mhatzl

@mhatzl mhatzl commented May 8, 2026

Copy link
Copy Markdown
Contributor

closes #3319

Uses rustc --print=cfg --target=<given target> in nextest internally to resolve the platform in case target is not built-in or custom JSON target.
If this fails, heuristic check is done as before.

bumps target-spec to v3.6.0 to get support for rustc --print=cfg.
(Cargo.lock was already at v3.6.0, but Cargo.toml wasn't)

To test this feature with de upstream rustc, I created a shell script and set it for RUSTC only for this one test case.
The shell script forwards all rustc calls except when --print=cfg is the first argument.
In this case it returns a fixed cfg that is then compared in the test case.

Wouldn't know how else to test this, because rustc --print=cfg requires to pass the target as well, but upstream rustc only knows targets that would get resolved by the built-in case, so would never reach the --print=cfg fallback.

@codecov

codecov Bot commented May 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.47059% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.58%. Comparing base (d2bdbe1) to head (0a3e63e).

Files with missing lines Patch % Lines
nextest-runner/src/cargo_config/target_triple.rs 75.00% 6 Missing ⚠️
integration-tests/test-helpers/rustc-shim.rs 80.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3331      +/-   ##
==========================================
- Coverage   85.58%   85.58%   -0.01%     
==========================================
  Files         160      160              
  Lines       47893    47927      +34     
==========================================
+ Hits        40990    41019      +29     
- Misses       6903     6908       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sunshowers

Copy link
Copy Markdown
Member

Thanks for doing this! Have a look at the rustc-shim binary, you should be able to fake a rustc invocation using that: https://github.com/nextest-rs/nextest/blob/a2c4c13e16946c0c5ad06a9fedeabf10f83e4fe3/integration-tests/test-helpers/rustc-shim.rs

@mhatzl

mhatzl commented May 11, 2026

Copy link
Copy Markdown
Contributor Author

thanks @sunshowers
will try to use rustc-shim

@mhatzl mhatzl force-pushed the mh/rustc-cfg-target-support branch from 55c920b to 8a4bb8d Compare May 13, 2026 16:32
@mhatzl

mhatzl commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

switched to rustc-shim and removed the script.
CI is now failing, because I expect NEXTEST_BIN_EXE_rustc_shim to be set and pointing to the rustc-shim binary.

I don't see how this is set for the integration-test, because inside set_env_vars_for_test, the env is also only checked but not set.
Since this is the only place where I could find a mention of this env, I guess it is set in GitHub environments?

Should I hardcode the path using NEXTEST_WORKSPACE_ROOT and then target/release/rustc-shim?

@sunshowers

Copy link
Copy Markdown
Member

Hmm, nextest is responsible for setting it. I'll have a look.

@mhatzl

mhatzl commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

Hmm, nextest is responsible for setting it. I'll have a look.

my added test is still under nextest-runner/tests/integration/target_triple.rs.
didn't want to move it to integration-tests/tests, because the test is about the target triple. Maybe NEXTEST_BIN_EXE_rustc_shim is only available for integration-tests/tests?

@sunshowers

Copy link
Copy Markdown
Member

Ah yeah it has to live under integration-tests.

I would have a look at cargo nextest debug build-platforms -- you may need to add a mode which just prints out all the platform settings. The debug commands aren't stable so you can make whatever changes you need to them.

Adding a new debug command to check target arg output
@mhatzl

mhatzl commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

added cargo debug print-cargo-target-arg to compare the CargoTargetArg output of a set target and that seems to work quite good now.

not sure about the MSRV fails, because edition=2024 was already set.
the macos-latest fails are also strange

@sunshowers

Copy link
Copy Markdown
Member

The nextest-metadata MSRV thing will be addressed by #3342.

This generally looks great, thanks! I'll take care of the rest (want to make a few tweaks to the output format before landing).

@mhatzl

mhatzl commented May 13, 2026

Copy link
Copy Markdown
Contributor Author

perfect. thank you.

and thanks for the pointers

triple_str,
"--output-format",
"json-pretty",
])

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.

I added JSON output to debug build-platforms in #3343 and used it here.

Comment on lines +1 to +13
debug_assertions
panic="abort"
target_abi="eabihf"
target_arch="arm"
target_endian="little"
target_env=""
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="8"
target_has_atomic="ptr"
target_os="none"
target_pointer_width="32"
target_vendor="unknown"

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.

Moved this to a file to avoid duplicating it across the shim and the test.

source: integration-tests/tests/integration/main.rs
expression: "&stdout"
---
{

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.

This is the new snapshot.

@sunshowers

Copy link
Copy Markdown
Member

The macOS failures are definitely unrelated to the PR and I think are an infrastructure issue with GitHub.

@sunshowers sunshowers merged commit e760edc into nextest-rs:main May 13, 2026
24 of 25 checks passed
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.

Feature request: Allow custom targets that do not adhere to target-lexicon

2 participants