Skip to content

Commit 306d515

Browse files
committed
fix(fingerprint): Don't throwaway the cache on RUSTFLAGS changes
Fixes #8716
1 parent 2bf35da commit 306d515

File tree

8 files changed

+24
-35
lines changed

8 files changed

+24
-35
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,18 @@ 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+
build_runner
707+
.bcx
708+
.extra_args_for(unit)
709+
.hash(&mut c_extra_filename_hasher);
710+
if unit.mode.is_doc() || unit.mode.is_doc_scrape() {
711+
unit.rustdocflags.hash(&mut c_extra_filename_hasher);
712+
} else {
713+
unit.rustflags.hash(&mut c_extra_filename_hasher);
714+
}
703715

704716
let c_metadata = UnitHash(c_metadata_hasher.finish());
705717
let c_extra_filename = UnitHash(c_extra_filename_hasher.finish());

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
//! -------------------------------------------|-------------|---------------------|------------------------|----------
6969
//! rustc | ✓ | ✓ | ✓ | ✓
7070
//! [`Profile`] | ✓ | ✓ | ✓ | ✓
71-
//! `cargo rustc` extra args | ✓ | | |
71+
//! `cargo rustc` extra args | ✓ | | |
7272
//! [`CompileMode`] | ✓ | ✓ | ✓ | ✓
7373
//! Target Name | ✓ | ✓ | ✓ | ✓
7474
//! `TargetKind` (bin/lib/etc.) | ✓ | ✓ | ✓ | ✓
@@ -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

+4-14
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
"#]])
@@ -1380,7 +1375,6 @@ fn changing_rustc_extra_flags_is_cached() {
13801375
.run();
13811376
p.cargo("rustc -v -- -C linker=cc")
13821377
.with_stderr_data(str![[r#"
1383-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration changed
13841378
[COMPILING] foo v0.0.1 ([ROOT]/foo)
13851379
[RUNNING] `rustc [..]
13861380
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1390,18 +1384,14 @@ fn changing_rustc_extra_flags_is_cached() {
13901384

13911385
p.cargo("rustc -v")
13921386
.with_stderr_data(str![[r#"
1393-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration changed
1394-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1395-
[RUNNING] `rustc [..]
1387+
[FRESH] foo v0.0.1 ([ROOT]/foo)
13961388
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
13971389
13981390
"#]])
13991391
.run();
14001392
p.cargo("rustc -v -- -C linker=cc")
14011393
.with_stderr_data(str![[r#"
1402-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration changed
1403-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1404-
[RUNNING] `rustc [..]
1394+
[FRESH] foo v0.0.1 ([ROOT]/foo)
14051395
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
14061396
14071397
"#]])

tests/testsuite/freshness_checksum.rs

+4-14
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
"#]])
@@ -1556,7 +1551,6 @@ fn changing_rustc_extra_flags_is_cached() {
15561551
p.cargo("rustc -Zchecksum-freshness -v -- -C linker=cc")
15571552
.masquerade_as_nightly_cargo(&["checksum-freshness"])
15581553
.with_stderr_data(str![[r#"
1559-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration changed
15601554
[COMPILING] foo v0.0.1 ([ROOT]/foo)
15611555
[RUNNING] `rustc [..]
15621556
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
@@ -1567,19 +1561,15 @@ fn changing_rustc_extra_flags_is_cached() {
15671561
p.cargo("rustc -Zchecksum-freshness -v")
15681562
.masquerade_as_nightly_cargo(&["checksum-freshness"])
15691563
.with_stderr_data(str![[r#"
1570-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration changed
1571-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1572-
[RUNNING] `rustc [..] src/lib.rs [..]
1564+
[FRESH] foo v0.0.1 ([ROOT]/foo)
15731565
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
15741566
15751567
"#]])
15761568
.run();
15771569
p.cargo("rustc -Zchecksum-freshness -v -- -C linker=cc")
15781570
.masquerade_as_nightly_cargo(&["checksum-freshness"])
15791571
.with_stderr_data(str![[r#"
1580-
[DIRTY] foo v0.0.1 ([ROOT]/foo): the profile configuration changed
1581-
[COMPILING] foo v0.0.1 ([ROOT]/foo)
1582-
[RUNNING] `rustc [..]
1572+
[FRESH] foo v0.0.1 ([ROOT]/foo)
15831573
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
15841574
15851575
"#]])

tests/testsuite/pgo.rs

-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ fn pgo_works() {
103103
),
104104
)
105105
.with_stderr_data(str![[r#"
106-
[DIRTY] foo v0.0.0 ([ROOT]/foo): the rustflags changed
107106
[COMPILING] foo v0.0.0 ([ROOT]/foo)
108107
[RUNNING] `rustc [..]-Cprofile-use=[ROOT]/foo/target/merged.profdata -Cllvm-args=-pgo-warn-missing-function`
109108
[FINISHED] `release` profile [optimized] target(s) in [ELAPSED]s

tests/testsuite/rustc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,6 @@ fn rustc_fingerprint() {
616616
p.cargo("rustc -v")
617617
.with_stderr_does_not_contain("-C debug-assertions")
618618
.with_stderr_data(str![[r#"
619-
[DIRTY] foo v0.5.0 ([ROOT]/foo): the profile configuration changed
620619
[COMPILING] foo v0.5.0 ([ROOT]/foo)
621620
[RUNNING] `rustc --crate-name foo [..]`
622621
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

tests/testsuite/rustflags.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1592,7 +1592,7 @@ fn rustflags_remap_path_prefix_ignored_for_c_extra_filename() {
15921592
.run();
15931593
let second_c_extra_filename = dbg!(get_c_extra_filename(build_output));
15941594

1595-
assert_data_eq!(first_c_extra_filename, second_c_extra_filename);
1595+
assert_ne!(first_c_extra_filename, second_c_extra_filename);
15961596
}
15971597

15981598
// `--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() {
16131613
.run();
16141614
let second_c_extra_filename = dbg!(get_c_extra_filename(build_output));
16151615

1616-
assert_data_eq!(first_c_extra_filename, second_c_extra_filename);
1616+
assert_ne!(first_c_extra_filename, second_c_extra_filename);
16171617
}
16181618

16191619
fn get_c_metadata(output: RawOutput) -> String {

0 commit comments

Comments
 (0)