Skip to content

Commit 26ced7e

Browse files
committed
fix(fingerprint): Don't throwaway the cache on RUSTFLAGS changes
Fixes #8716
1 parent 441fbd9 commit 26ced7e

File tree

5 files changed

+13
-16
lines changed

5 files changed

+13
-16
lines changed

src/cargo/core/compiler/build_runner/compilation_files.rs

+8
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,14 @@ fn compute_metadata(
696696
.collect::<Vec<_>>();
697697
dep_c_extra_filename_hashes.sort();
698698
dep_c_extra_filename_hashes.hash(&mut c_extra_filename_hasher);
699+
// Avoid trashing the caches on RUSTFLAGS changing via `c_extra_filename`
700+
//
701+
// Limited to `c_extra_filename` to help with reproducible build / PGO issues.
702+
if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
703+
unit.rustdocflags.hash(&mut c_extra_filename_hasher);
704+
} else {
705+
unit.rustflags.hash(&mut c_extra_filename_hasher);
706+
}
699707

700708
let c_metadata = UnitHash(c_metadata_hasher.finish());
701709
let c_extra_filename = UnitHash(c_extra_filename_hasher.finish());

src/cargo/core/compiler/fingerprint/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
//! Target flags (test/bench/for_host/edition) | ✓ | | |
8484
//! -C incremental=… flag | ✓ | | |
8585
//! mtime of sources | ✓[^3] | | |
86-
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ | | |
86+
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ | | |
8787
//! [`Lto`] flags | ✓ | ✓ | ✓ | ✓
8888
//! config settings[^5] | ✓ | | |
8989
//! `is_std` | | ✓ | ✓ | ✓

tests/testsuite/config_include.rs

-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ fn works_with_cli() {
244244
p.cargo("check -v -Z config-include")
245245
.masquerade_as_nightly_cargo(&["config-include"])
246246
.with_stderr_data(str![[r#"
247-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
248247
[CHECKING] foo v0.0.1 ([ROOT]/foo)
249248
[RUNNING] `rustc [..]-W unsafe-code -W unused`
250249
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

tests/testsuite/freshness.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,6 @@ fn changing_rustflags_is_cached() {
13471347
p.cargo("build -v")
13481348
.env("RUSTFLAGS", "-C linker=cc")
13491349
.with_stderr_data(str![[r#"
1350-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
13511350
[COMPILING] foo v0.0.1 ([ROOT]/foo)
13521351
[RUNNING] `rustc [..]
13531352
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1357,19 +1356,15 @@ fn changing_rustflags_is_cached() {
13571356

13581357
p.cargo("build -v")
13591358
.with_stderr_data(str![[r#"
1360-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
1361-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1362-
[RUNNING] `rustc [..] src/lib.rs [..]
1359+
[FRESH] foo v0.0.1 ([ROOT]/foo)
13631360
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
13641361
13651362
"#]])
13661363
.run();
13671364
p.cargo("build -v")
13681365
.env("RUSTFLAGS", "-C linker=cc")
13691366
.with_stderr_data(str![[r#"
1370-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
1371-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1372-
[RUNNING] `rustc [..]
1367+
[FRESH] foo v0.0.1 ([ROOT]/foo)
13731368
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
13741369
13751370
"#]])

tests/testsuite/freshness_checksum.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,6 @@ fn changing_rustflags_is_cached() {
15191519
.masquerade_as_nightly_cargo(&["checksum-freshness"])
15201520
.env("RUSTFLAGS", "-C linker=cc")
15211521
.with_stderr_data(str![[r#"
1522-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
15231522
[COMPILING] foo v0.0.1 ([ROOT]/foo)
15241523
[RUNNING] `rustc [..]
15251524
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1530,9 +1529,7 @@ fn changing_rustflags_is_cached() {
15301529
p.cargo("build -Zchecksum-freshness -v")
15311530
.masquerade_as_nightly_cargo(&["checksum-freshness"])
15321531
.with_stderr_data(str![[r#"
1533-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
1534-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1535-
[RUNNING] `rustc [..] src/lib.rs [..]
1532+
[FRESH] foo v0.0.1 ([ROOT]/foo)
15361533
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
15371534
15381535
"#]])
@@ -1541,9 +1538,7 @@ fn changing_rustflags_is_cached() {
15411538
.masquerade_as_nightly_cargo(&["checksum-freshness"])
15421539
.env("RUSTFLAGS", "-C linker=cc")
15431540
.with_stderr_data(str![[r#"
1544-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
1545-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1546-
[RUNNING] `rustc [..]
1541+
[FRESH] foo v0.0.1 ([ROOT]/foo)
15471542
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
15481543
15491544
"#]])

0 commit comments

Comments
 (0)