Skip to content

Commit 99c034a

Browse files
committed
Auto merge of #7417 - alexcrichton:less-hashing, r=Eh2406
Go back to not hashing `RUSTFLAGS` in `-Cmetadata` This is a moral revert of #6503 but not a literal code revert. This switches Cargo's behavior to avoid hashing compiler flags into `-Cmetadata` since we've now had multiple requests of excluding flags from the `-Cmetadata` hash: usage of `--remap-path-prefix` and PGO options. These options should only affect how the compiler is invoked/compiled and not radical changes such as symbol names, but symbol names are changed based on `-Cmetadata`. Instead Cargo will still track these flags internally, but only for reinvoking rustc, and not for caching separately based on rustc flags. Closes #7416
2 parents 3cd05e2 + f3c92ed commit 99c034a

File tree

3 files changed

+23
-54
lines changed

3 files changed

+23
-54
lines changed

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

-30
Original file line numberDiff line numberDiff line change
@@ -541,36 +541,6 @@ fn compute_metadata<'a, 'cfg>(
541541
unit.profile.hash(&mut hasher);
542542
unit.mode.hash(&mut hasher);
543543

544-
// Throw in the rustflags we're compiling with.
545-
// This helps when the target directory is a shared cache for projects with different cargo configs,
546-
// or if the user is experimenting with different rustflags manually.
547-
let mut hash_flags = |flags: &[String]| {
548-
// Ignore some flags. These may affect reproducible builds if they affect
549-
// the path. The fingerprint will handle recompilation if these change.
550-
let mut iter = flags.iter();
551-
while let Some(flag) = iter.next() {
552-
if flag.starts_with("--remap-path-prefix=") {
553-
continue;
554-
}
555-
if flag == "--remap-path-prefix" {
556-
iter.next();
557-
continue;
558-
}
559-
flag.hash(&mut hasher);
560-
}
561-
};
562-
if let Some(args) = bcx.extra_args_for(unit) {
563-
// Arguments passed to `cargo rustc`.
564-
hash_flags(args);
565-
}
566-
// Arguments passed in via RUSTFLAGS env var.
567-
let flags = if unit.mode.is_doc() {
568-
bcx.rustdocflags_args(unit)
569-
} else {
570-
bcx.rustflags_args(unit)
571-
};
572-
hash_flags(flags);
573-
574544
// Artifacts compiled for the host should have a different metadata
575545
// piece than those compiled for the target, so make sure we throw in
576546
// the unit's `kind` as well

src/cargo/core/compiler/fingerprint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
//! Target flags (test/bench/for_host/edition) | ✓ |
6060
//! -C incremental=… flag | ✓ |
6161
//! mtime of sources | ✓[^3] |
62-
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ |
62+
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ |
6363
//!
6464
//! [^1]: Build script and bin dependencies are not included.
6565
//!

tests/testsuite/freshness.rs

+22-23
Original file line numberDiff line numberDiff line change
@@ -1151,23 +1151,24 @@ fn reuse_shared_build_dep() {
11511151
fn changing_rustflags_is_cached() {
11521152
let p = project().file("src/lib.rs", "").build();
11531153

1154-
p.cargo("build").run();
1155-
p.cargo("build")
1156-
.env("RUSTFLAGS", "-C linker=cc")
1157-
.with_stderr(
1158-
"\
1154+
// This isn't ever cached, we always have to recompile
1155+
for _ in 0..2 {
1156+
p.cargo("build")
1157+
.with_stderr(
1158+
"\
11591159
[COMPILING] foo v0.0.1 ([..])
11601160
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
1161-
)
1162-
.run();
1163-
// This should not recompile!
1164-
p.cargo("build")
1165-
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
1166-
.run();
1167-
p.cargo("build")
1168-
.env("RUSTFLAGS", "-C linker=cc")
1169-
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
1170-
.run();
1161+
)
1162+
.run();
1163+
p.cargo("build")
1164+
.env("RUSTFLAGS", "-C linker=cc")
1165+
.with_stderr(
1166+
"\
1167+
[COMPILING] foo v0.0.1 ([..])
1168+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
1169+
)
1170+
.run();
1171+
}
11711172
}
11721173

11731174
#[cargo_test]
@@ -1257,6 +1258,9 @@ fn fingerprint_cleaner_does_not_rebuild() {
12571258
12581259
[dependencies]
12591260
bar = { path = "bar" }
1261+
1262+
[features]
1263+
a = []
12601264
"#,
12611265
)
12621266
.file("src/lib.rs", "")
@@ -1267,12 +1271,10 @@ fn fingerprint_cleaner_does_not_rebuild() {
12671271
p.cargo("build -Z mtime-on-use")
12681272
.masquerade_as_nightly_cargo()
12691273
.run();
1270-
p.cargo("build -Z mtime-on-use")
1274+
p.cargo("build -Z mtime-on-use --features a")
12711275
.masquerade_as_nightly_cargo()
1272-
.env("RUSTFLAGS", "-C linker=cc")
12731276
.with_stderr(
12741277
"\
1275-
[COMPILING] bar v0.0.1 ([..])
12761278
[COMPILING] foo v0.0.1 ([..])
12771279
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
12781280
)
@@ -1285,24 +1287,21 @@ fn fingerprint_cleaner_does_not_rebuild() {
12851287
sleep_ms(1000);
12861288
}
12871289
// This does not make new files, but it does update the mtime.
1288-
p.cargo("build -Z mtime-on-use")
1290+
p.cargo("build -Z mtime-on-use --features a")
12891291
.masquerade_as_nightly_cargo()
1290-
.env("RUSTFLAGS", "-C linker=cc")
12911292
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
12921293
.run();
12931294
fingerprint_cleaner(p.target_debug_dir(), timestamp);
12941295
// This should not recompile!
1295-
p.cargo("build -Z mtime-on-use")
1296+
p.cargo("build -Z mtime-on-use --features a")
12961297
.masquerade_as_nightly_cargo()
1297-
.env("RUSTFLAGS", "-C linker=cc")
12981298
.with_stderr("[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]")
12991299
.run();
13001300
// But this should be cleaned and so need a rebuild
13011301
p.cargo("build -Z mtime-on-use")
13021302
.masquerade_as_nightly_cargo()
13031303
.with_stderr(
13041304
"\
1305-
[COMPILING] bar v0.0.1 ([..])
13061305
[COMPILING] foo v0.0.1 ([..])
13071306
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]",
13081307
)

0 commit comments

Comments
 (0)