diff --git a/src/cargo/core/compiler/build_runner/compilation_files.rs b/src/cargo/core/compiler/build_runner/compilation_files.rs index b07b59aac4c..363529ac442 100644 --- a/src/cargo/core/compiler/build_runner/compilation_files.rs +++ b/src/cargo/core/compiler/build_runner/compilation_files.rs @@ -700,6 +700,18 @@ 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. + build_runner + .bcx + .extra_args_for(unit) + .hash(&mut c_extra_filename_hasher); + 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 7552b534f39..c92dedccdd8 100644 --- a/src/cargo/core/compiler/fingerprint/mod.rs +++ b/src/cargo/core/compiler/fingerprint/mod.rs @@ -68,7 +68,7 @@ //! -------------------------------------------|-------------|---------------------|------------------------|---------- //! rustc | ✓ | ✓ | ✓ | ✓ //! [`Profile`] | ✓ | ✓ | ✓ | ✓ -//! `cargo rustc` extra args | ✓ | | | +//! `cargo rustc` extra args | ✓ | ✓ | | ✓ //! [`CompileMode`] | ✓ | ✓ | ✓ | ✓ //! Target Name | ✓ | ✓ | ✓ | ✓ //! `TargetKind` (bin/lib/etc.) | ✓ | ✓ | ✓ | ✓ @@ -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 7e5a68a9407..d2a6135e8a5 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 "#]]) @@ -1380,7 +1375,6 @@ fn changing_rustc_extra_flags_is_cached() { .run(); p.cargo("rustc -v -- -C linker=cc") .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration changed [COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s @@ -1390,18 +1384,14 @@ fn changing_rustc_extra_flags_is_cached() { p.cargo("rustc -v") .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration 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 "#]]) .run(); p.cargo("rustc -v -- -C linker=cc") .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration 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 c2f8b65b139..5c4b88fdbc3 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 "#]]) @@ -1556,7 +1551,6 @@ fn changing_rustc_extra_flags_is_cached() { p.cargo("rustc -Zchecksum-freshness -v -- -C linker=cc") .masquerade_as_nightly_cargo(&["checksum-freshness"]) .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration changed [COMPILING] foo v0.0.1 ([ROOT]/foo) [RUNNING] `rustc [..] [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s @@ -1567,9 +1561,7 @@ fn changing_rustc_extra_flags_is_cached() { p.cargo("rustc -Zchecksum-freshness -v") .masquerade_as_nightly_cargo(&["checksum-freshness"]) .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration 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 "#]]) @@ -1577,9 +1569,7 @@ fn changing_rustc_extra_flags_is_cached() { p.cargo("rustc -Zchecksum-freshness -v -- -C linker=cc") .masquerade_as_nightly_cargo(&["checksum-freshness"]) .with_stderr_data(str![[r#" -[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration 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 32748af1732..8676e73f55f 100644 --- a/tests/testsuite/pgo.rs +++ b/tests/testsuite/pgo.rs @@ -103,7 +103,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 diff --git a/tests/testsuite/rustc.rs b/tests/testsuite/rustc.rs index 599438bc09e..2041c006706 100644 --- a/tests/testsuite/rustc.rs +++ b/tests/testsuite/rustc.rs @@ -616,7 +616,6 @@ fn rustc_fingerprint() { p.cargo("rustc -v") .with_stderr_does_not_contain("-C debug-assertions") .with_stderr_data(str![[r#" -[DIRTY] foo v0.5.0 ([ROOT]/foo): the profile configuration changed [COMPILING] foo v0.5.0 ([ROOT]/foo) [RUNNING] `rustc --crate-name foo [..]` [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s diff --git a/tests/testsuite/rustflags.rs b/tests/testsuite/rustflags.rs index 195d7a07fea..9a24371a30b 100644 --- a/tests/testsuite/rustflags.rs +++ b/tests/testsuite/rustflags.rs @@ -1592,7 +1592,7 @@ fn rustflags_remap_path_prefix_ignored_for_c_extra_filename() { .run(); let second_c_extra_filename = dbg!(get_c_extra_filename(build_output)); - assert_data_eq!(first_c_extra_filename, second_c_extra_filename); + assert_ne!(first_c_extra_filename, second_c_extra_filename); } // `--remap-path-prefix` is meant to take two different binaries and make them the same but the @@ -1613,7 +1613,7 @@ fn rustc_remap_path_prefix_ignored_for_c_extra_filename() { .run(); let second_c_extra_filename = dbg!(get_c_extra_filename(build_output)); - assert_data_eq!(first_c_extra_filename, second_c_extra_filename); + assert_ne!(first_c_extra_filename, second_c_extra_filename); } fn get_c_metadata(output: RawOutput) -> String {