Skip to content

Commit

Permalink
fix(fingerprint): Don't throwaway the cache on RUSTFLAGS changes
Browse files Browse the repository at this point in the history
Fixes #8716
  • Loading branch information
epage committed Nov 21, 2024
1 parent dff3b21 commit c762927
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
8 changes: 8 additions & 0 deletions src/cargo/core/compiler/build_runner/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,14 @@ fn compute_metadata(
.collect::<Vec<_>>();
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());
Expand Down
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/fingerprint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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` | | ✓ | ✓ | ✓
Expand Down
1 change: 0 additions & 1 deletion tests/testsuite/config_include.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions tests/testsuite/freshness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1347,19 +1346,15 @@ 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
"#]])
.run();
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
"#]])
Expand Down
9 changes: 2 additions & 7 deletions tests/testsuite/freshness_checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
"#]])
Expand All @@ -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
"#]])
Expand Down

0 comments on commit c762927

Please sign in to comment.