Different RUSTFLAGS
between cargo build
and cargo clippy
invalidate "core" crate when using build-std #14551
Description
Problem
Normally, I pass the flag -W missing_docs
to cargo clippy
but not cargo build
this does not affect the other's build. However, when using -Z build-std
, I've noticed that adding -W missing_docs
to my cargo clippy
command will cause my the cargo build
command to re-build the core
crate, which in turn re-builds most dependent crates.
Steps
This was reproduced on with the following environment:
rustc --version --verbose
rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7
cargo new --bin buildstdtest
cd buildstdtest
cargo clippy
with-Z build-std
and setRUSTFLAGS="-W missing_docs"
RUSTFLAGS="-W missing_docs" cargo +nightly clippy -Z build-std --target x86_64-unknown-linux-gnu
cargo build
with -Z build-stdand no
RUSTFLAGS` setcargo +nightly build -Z build-std --target x86_64-unknown-linux-gnu
- Run
cargo clippy
again. I expect nothing rebuilds since no inputs have changed.However, theRUSTFLAGS="-W missing_docs" cargo +nightly clippy -Z build-std --target x86_64-unknown-linux-gnu
core
crate re-builds due to a change in rustflags.cargo +nightly build -vv -Z build-std --target x86_64-unknown-linux-gnu Dirty compiler_builtins v0.1.125: the rustflags changed Compiling compiler_builtins v0.1.125 Dirty core v0.0.0 (/home/matsch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core): the rustflags changed ...
Possible Solution(s)
No response
Notes
I enabled tracing on fingerprinting via the following command:
CARGO_LOG=cargo::core::compiler::fingerprint=trace cargo +nightly build -vv -Z build-std --target x86_64-unknown-linux-gnu
The output shows that the core
crate did have a change in rustflags.
0.066914712s INFO prepare_target{force=false package_id=core v0.0.0 (/home/matsch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core) target="core"}: cargo::core::compiler::fingerprint: dirty: RustflagsChanged { old: ["-W", "missing_docs"], new: [] }
So the question to figure out is, why do the build-std
crates pick up on the RUSTFLAGS
change, but when I remove -Z build-std
cargo build
and cargo clippy
can run side by side without affecting eachother's build fingerprints.
Version
cargo version --verbose
cargo 1.81.0 (2dbb1af80 2024-08-20)
release: 1.81.0
commit-hash: 2dbb1af80a2914475ba76827a312e29cedfa6b2f
commit-date: 2024-08-20
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.8.0-DEV (sys:0.4.73+curl-8.8.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: Debian n/a (rodete) [64-bit]