diff --git a/src/cargo/core/compiler/build_runner/compilation_files.rs b/src/cargo/core/compiler/build_runner/compilation_files.rs index a65bf1540e0f..1c42d5b3fa6d 100644 --- a/src/cargo/core/compiler/build_runner/compilation_files.rs +++ b/src/cargo/core/compiler/build_runner/compilation_files.rs @@ -696,6 +696,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 9b0b4d3707a6..4df04f15cc47 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 1bb7e717a578..468115dd5083 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 34695f12901a..cf3faf060190 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -1347,7 +1347,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 @@ -1357,9 +1356,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 "#]]) @@ -1367,9 +1364,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 ac190c84836c..9c59c0c441e1 100644 --- a/tests/testsuite/freshness_checksum.rs +++ b/tests/testsuite/freshness_checksum.rs @@ -1519,7 +1519,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 @@ -1530,9 +1529,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 "#]]) @@ -1541,9 +1538,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 "#]])