diff --git a/src/cargo/core/compiler/build_runner/compilation_files.rs b/src/cargo/core/compiler/build_runner/compilation_files.rs index b07b59aac4c..70cba8c1993 100644 --- a/src/cargo/core/compiler/build_runner/compilation_files.rs +++ b/src/cargo/core/compiler/build_runner/compilation_files.rs @@ -700,6 +700,14 @@ fn compute_metadata( .collect::>(); dep_c_extra_filename_hashes.sort(); dep_c_extra_filename_hashes.hash(&mut c_extra_filename_hasher); + // Avoid trashing the caches on RUSTFLAGS changing via `c_extra_filename` + // + // Limited to `c_extra_filename` to help with reproducible build / PGO issues. + if unit.mode.is_doc() || unit.mode.is_doc_scrape() { + unit.rustdocflags.hash(&mut c_extra_filename_hasher); + } else { + unit.rustflags.hash(&mut c_extra_filename_hasher); + } let c_metadata = UnitHash(c_metadata_hasher.finish()); let c_extra_filename = UnitHash(c_extra_filename_hasher.finish()); diff --git a/src/cargo/core/compiler/fingerprint/mod.rs b/src/cargo/core/compiler/fingerprint/mod.rs index 9b0b4d3707a..4df04f15cc4 100644 --- a/src/cargo/core/compiler/fingerprint/mod.rs +++ b/src/cargo/core/compiler/fingerprint/mod.rs @@ -83,7 +83,7 @@ //! Target flags (test/bench/for_host/edition) | ✓ | | | //! -C incremental=… flag | ✓ | | | //! mtime of sources | ✓[^3] | | | -//! RUSTFLAGS/RUSTDOCFLAGS | ✓ | | | +//! RUSTFLAGS/RUSTDOCFLAGS | ✓ | ✓ | | ✓ //! [`Lto`] flags | ✓ | ✓ | ✓ | ✓ //! config settings[^5] | ✓ | | | //! `is_std` | | ✓ | ✓ | ✓ diff --git a/tests/testsuite/config_include.rs b/tests/testsuite/config_include.rs index 1bb7e717a57..468115dd508 100644 --- a/tests/testsuite/config_include.rs +++ b/tests/testsuite/config_include.rs @@ -244,7 +244,6 @@ fn works_with_cli() { p.cargo("check -v -Z config-include") .masquerade_as_nightly_cargo(&["config-include"]) .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed [CHECKING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..]-W unsafe-code -W unused` [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index e01adc6564b..60c0aec1abf 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1337,7 +1337,6 @@ fn changing_rustflags_is_cached() { p.cargo("build -v") .env("RUSTFLAGS", "-C linker=cc") .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed [COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s @@ -1347,9 +1346,7 @@ fn changing_rustflags_is_cached() { p.cargo("build -v") .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed -[COMPILING] foo v0.0.1 ([ROOT]/foo) -[RUNNING] `rustc [..] src/lib.rs [..] +[FRESH] foo v0.0.1 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) @@ -1357,9 +1354,7 @@ fn changing_rustflags_is_cached() { p.cargo("build -v") .env("RUSTFLAGS", "-C linker=cc") .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed -[COMPILING] foo v0.0.1 ([ROOT]/foo) -[RUNNING] `rustc [..] +[FRESH] foo v0.0.1 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) diff --git a/tests/testsuite/freshness_checksum.rs b/tests/testsuite/freshness_checksum.rs index 386ee11a31a..a49f9796a3f 100644 --- a/tests/testsuite/freshness_checksum.rs +++ b/tests/testsuite/freshness_checksum.rs @@ -1509,7 +1509,6 @@ fn changing_rustflags_is_cached() { .masquerade_as_nightly_cargo(&["checksum-freshness"]) .env("RUSTFLAGS", "-C linker=cc") .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed [COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s @@ -1520,9 +1519,7 @@ fn changing_rustflags_is_cached() { p.cargo("build -Zchecksum-freshness -v") .masquerade_as_nightly_cargo(&["checksum-freshness"]) .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed -[COMPILING] foo v0.0.1 ([ROOT]/foo) -[RUNNING] `rustc [..] src/lib.rs [..] +[FRESH] foo v0.0.1 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) @@ -1531,9 +1528,7 @@ fn changing_rustflags_is_cached() { .masquerade_as_nightly_cargo(&["checksum-freshness"]) .env("RUSTFLAGS", "-C linker=cc") .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed -[COMPILING] foo v0.0.1 ([ROOT]/foo) -[RUNNING] `rustc [..] +[FRESH] foo v0.0.1 ([ROOT]/foo) [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) diff --git a/tests/testsuite/pgo.rs b/tests/testsuite/pgo.rs index 631a80c9000..f0441b5889a 100644 --- a/tests/testsuite/pgo.rs +++ b/tests/testsuite/pgo.rs @@ -101,7 +101,6 @@ fn pgo_works() { ), ) .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.0 ([ROOT]/foo): the rustflags changed [COMPILING] foo v0.0.0 ([ROOT]/foo) [RUNNING] `rustc [..]-Cprofile-use=[ROOT]/foo/target/merged.profdata -Cllvm-args=-pgo-warn-missing-function` [FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s