fix: run the Android llvm-ar probe in the caller's environment - #1867
Closed
MohammedAlkindi wants to merge 3 commits into
Closed
fix: run the Android llvm-ar probe in the caller's environment#1867MohammedAlkindi wants to merge 3 commits into
MohammedAlkindi wants to merge 3 commits into
Conversation
`is_flag_supported_inner` built its probe from a fresh `Build`, dropping
`Build::env` along with the out dir and the caches. The probe therefore
resolved a bare compiler name such as `cc` through the ambient `PATH`
rather than the one the compile commands run in, and answered a question
about a different compiler than the one being built with. Compiler
family detection had the same gap at four more spawns: they applied no
environment at all, and `Tool::with_features` was never handed one.
Both now run in the environment `Build::env` sets up, and the family
lookup cache is keyed on that environment as well as the path and
arguments, so two builds that differ only in it cannot share an answer.
Reaching the right compiler means the probes now reach the test shim,
where they would have taken `out{i}` slots and shifted the numbering
every assertion depends on. Two variables opt one class of probe in by
name instead: `CC_SHIM_OUT_FILES_FOR_FAMILY_DETECTION` and
`CC_SHIM_OUT_FILES_FOR_FLAG_SUPPORT_CHECK`. cc renames the one matching
the probe it is about to spawn to `CC_SHIM_OUT_FILES`, rather than
copying `Build::env` over blindly, so a probe no test asked about
records nothing at all. That replaces the `-c` sniffing the shim did to
guess whether it was looking at a flag probe, and the panic on a missing
`CC_SHIM_OUT_DIR` that family detection relied on to keep failing.
`gnu_flag_if_supported` no longer skips Windows. It needed the probe to
reject a flag and got that from whatever compiler the machine happened
to have installed; it now says so with `CC_SHIM_FAIL_IF_ARG`.
Refs rust-lang#1859
Four things from the review, no behaviour change. The shim collected argv twice. `split_first` gives the program and the rest in one step, and `record` now takes `&[String]` rather than `&[&String]`. The probe `Build` copies the env with `clone_from` instead of replaying it key by key. `ProbeKind` and `set_probe_env` are private again, behind a `CommandExt` trait with `set_family_detection_env` and `set_flag_supported_env`, so a caller names the probe class instead of passing an enum. The test harness gained `collect_family_detection_probes` and `collect_flag_supported_probes` with matching getters, so a test opts a class in by name and `CC_SHIM_OUT_FILES_FOR_*` stays inside the harness. The getters take an index because `clang_cl_scope_all` records two flag support probes in one build, so a single file per class was not enough.
The Android branch of `get_base_archiver_variant` decides whether the NDK ships `llvm-ar` under that name by running `llvm-ar --version`, and it built that probe with a bare `Command::new`. A bare name resolves through the ambient `PATH`, not the one `Build::env` set up, so a caller that points `PATH` at its own toolchain gets the question answered about a different toolchain and cc falls back to the target-prefixed name. This is the third site of the same root cause as rust-lang#1859, after compiler family detection and `is_flag_supported`, and it is the one that made `clang_android` unable to run here: the test puts `llvm-ar` on `PATH` through `Build::env`, the probe never saw it, and the fallback `arm-linux-androideabi-ar` does not exist, so cc exited the process. The probe now goes through `set_ar_detection_env`, so it inherits `Build::env` and takes its own recording class rather than an `out{i}` slot. `Test` gains `collect_ar_detection_probes` and `get_ar_detection_probes` to match the other two classes.
NobodyXu
approved these changes
Aug 20, 2026
NobodyXu
left a comment
Contributor
There was a problem hiding this comment.
Thanks LGTM, can be merged after the other one
This was referenced Aug 20, 2026
Contributor
Author
|
Superseded by #1868, which is this same commit rebased onto #1868 is one commit instead of three and is green: |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The
clang_androidfollow-up from #1866. Related: #1859.This is stacked on #1866 and contains its two commits. Only the last one,
fix: run the Android llvm-ar probe in the caller's environment, is new here. The diff will shrink to that once #1866 lands, so this is best read after it.What broke
The Android branch of
get_base_archiver_variantworks out whether the NDK shipsllvm-arunder that name by runningllvm-ar --version, and it built that probe with a bareCommand::new:A bare name resolves through the ambient
PATH, not the oneBuild::envset up. So a caller that pointsPATHat its own toolchain gets the question answered about a different toolchain, and cc falls back to the target-prefixed name.This is the third site of the same root cause as #1859, after family detection and
is_flag_supported. It is also the one that madeclang_androidunable to run on my machine: the test putsllvm-aronPATHthroughBuild::env, the probe never saw it, and the fallbackarm-linux-androideabi-aris not there either, so cc's error path exited the process and took the whole test binary with it.Green on CI because the runners have something the probe can find in the ambient
PATH.The change
The probe goes through
set_ar_detection_env, so it inheritsBuild::envand gets its own recording class rather than consuming anout{i}slot. That is the third class you and I discussed on #1866, and it is the reason this is a separate PR: it widens the design from two classes to three.ProbeKind::ArDetectionmaps toCC_SHIM_OUT_FILES_FOR_AR_DETECTION, andTestgainscollect_ar_detection_probesandget_ar_detection_probesalongside the other two.I did not touch the fallback logic itself, only which environment the probe asks the question in.
Verified
Windows 11,
x86_64-pc-windows-msvc,rustc 1.97.1.Before, on the unmodified branch,
clang_androiddid not fail, it aborted the process, which is why the rest of that binary never reported. After:That is the whole binary green in one run for the first time here. Previously 58 of 59 passed when run one test per process, with
clang_androidkilling the shared run.Everything else, on this branch: every other test binary green, doc-tests 28 passed,
cargo clippy --workspace --all-targets -- -D warningsclean,cargo fmt --all --checkclean, and MSRVcheck -p ccon 1.65.0 clean.The new assertion is
test.get_ar_detection_probes(0).must_have("--version"), which fails on unmodified source because the probe never reaches the shim and no recording exists.One thing worth your call
The probe still runs
--versionand inherits stdio, so under the shim it is a real process spawn per Android build. That was already true, and I left it alone rather than widening the PR, but if you would rather it were quieted or cached, say so and I will fold it in.LLM usage, per the Rust policy: this change was developed with AI assistance (Claude). Adding this retroactively, since it should have been disclosed when the PR was opened.