Rebuild and rerun build scripts when RUSTC_WRAPPER has changed #10973
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.
What does this PR try to resolve?
The current behavior of Cargo, which I think is a bug, is that if you run
cargo build
followed byRUSTC_WRAPPER=… cargo build
, Cargo will rebuild your crate using the given rustc wrapper, but will not rebuild or rerun any build scripts. The same is true of those commands in the opposite order: Cargo will rebuild your crate with no wrapper, but not build scripts.This PR fixes this to rebuild build scripts too (and rerun them) when RUSTC_WRAPPER has changed.
In general, whatever rationale justifies rebuilding an already successfully built crate on a RUSTC_WRAPPER change (maybe the wrapper is in charge of munging rustc flags somehow?) should apply just as much to justify rebuilding build scripts.
The immediate motivation for the PR is that we had a problematic experience in the
anyhow
crate where compiling via rust-analyzer using rust-analyzer's RUSTC_WRAPPER would break all subsequent command-line cargo invocations, due to the RUSTC_WRAPPER-using build of the build script being cached and not rerun.How should we test and review this PR?
I tested by
cargo test --test testsuite -- rerun_build_script_if_add_rustc_wrapper
.