Skip to content

Commit c762927

Browse files
committed
fix(fingerprint): Don't throwaway the cache on RUSTFLAGS changes
Fixes rust-lang#8716
1 parent dff3b21 commit c762927

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
@@ -700,6 +700,14 @@ fn compute_metadata(
700700
.collect::<Vec<_>>();
701701
dep_c_extra_filename_hashes.sort();
702702
dep_c_extra_filename_hashes.hash(&mut c_extra_filename_hasher);
703+
// Avoid trashing the caches on RUSTFLAGS changing via `c_extra_filename`
704+
//
705+
// Limited to `c_extra_filename` to help with reproducible build / PGO issues.
706+
if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
707+
unit.rustdocflags.hash(&mut c_extra_filename_hasher);
708+
} else {
709+
unit.rustflags.hash(&mut c_extra_filename_hasher);
710+
}
703711

704712
let c_metadata = UnitHash(c_metadata_hasher.finish());
705713
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
@@ -1337,7 +1337,6 @@ fn changing_rustflags_is_cached() {
13371337
p.cargo("build -v")
13381338
.env("RUSTFLAGS", "-C linker=cc")
13391339
.with_stderr_data(str![[r#"
1340-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
13411340
[COMPILING] foo v0.0.1 ([ROOT]/foo)
13421341
[RUNNING] `rustc [..]
13431342
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1347,19 +1346,15 @@ fn changing_rustflags_is_cached() {
13471346

13481347
p.cargo("build -v")
13491348
.with_stderr_data(str![[r#"
1350-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
1351-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1352-
[RUNNING] `rustc [..] src/lib.rs [..]
1349+
[FRESH] foo v0.0.1 ([ROOT]/foo)
13531350
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
13541351
13551352
"#]])
13561353
.run();
13571354
p.cargo("build -v")
13581355
.env("RUSTFLAGS", "-C linker=cc")
13591356
.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 [..]
1357+
[FRESH] foo v0.0.1 ([ROOT]/foo)
13631358
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
13641359
13651360
"#]])

tests/testsuite/freshness_checksum.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,6 @@ fn changing_rustflags_is_cached() {
15091509
.masquerade_as_nightly_cargo(&["checksum-freshness"])
15101510
.env("RUSTFLAGS", "-C linker=cc")
15111511
.with_stderr_data(str![[r#"
1512-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
15131512
[COMPILING] foo v0.0.1 ([ROOT]/foo)
15141513
[RUNNING] `rustc [..]
15151514
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1520,9 +1519,7 @@ fn changing_rustflags_is_cached() {
15201519
p.cargo("build -Zchecksum-freshness -v")
15211520
.masquerade_as_nightly_cargo(&["checksum-freshness"])
15221521
.with_stderr_data(str![[r#"
1523-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
1524-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1525-
[RUNNING] `rustc [..] src/lib.rs [..]
1522+
[FRESH] foo v0.0.1 ([ROOT]/foo)
15261523
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
15271524
15281525
"#]])
@@ -1531,9 +1528,7 @@ fn changing_rustflags_is_cached() {
15311528
.masquerade_as_nightly_cargo(&["checksum-freshness"])
15321529
.env("RUSTFLAGS", "-C linker=cc")
15331530
.with_stderr_data(str![[r#"
1534-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the rustflags changed
1535-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1536-
[RUNNING] `rustc [..]
1531+
[FRESH] foo v0.0.1 ([ROOT]/foo)
15371532
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
15381533
15391534
"#]])

0 commit comments

Comments
 (0)