fix: run the Android llvm-ar probe in the caller's environment - #1868
Merged
NobodyXu merged 1 commit intoAug 20, 2026
Merged
Conversation
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.
Thank you!
A new release will be cut this weekend
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.
Replaces #1867, which you approved but which went conflicted the moment #1866 squash-merged. Same commit, rebased onto
main, now a single commit rather than three. Related: #1859.I could not update #1867 in place because rebasing a pushed branch needs a force-push and my setup gates that on a human, so a fresh branch was the clean way to give you a mergeable version. Sorry for the extra PR number.
What broke
The Android branch of
get_base_archiver_variantdecides 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 pointingPATHat 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, and it is the one that madeclang_androidunable to run here: 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.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 we discussed on #1866, and it is why this is separate: 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. The fallback logic itself is untouched; only the environment the probe asks the question in changes.Verified after the rebase, not before
Windows 11,
x86_64-pc-windows-msvc,rustc 1.97.1, run againstmainatc5cc913:That is the whole binary green in a single run. Before this change
clang_androiddid not fail, it aborted the process, which is why the rest of that binary never reported.Every other test binary green, doc-tests 28 passed,
cargo clippy --workspace --all-targets -- -D warningsclean,cargo fmt --all --checkclean, 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.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.