Skip to content

Commit 65e3885

Browse files
committed
Auto merge of #6966 - ehuss:reamp-path-prefix-hash, r=@alexcrichton
Ignore remap-path-prefix in metadata hash. Including this flag in the metadata hash causes problems with reproducible builds. I spent some time considering the different alternatives (such as providing a config option, or an unhashed RUSTFLAGS alternative), and decided this might be the best option. - It is a very simple, small change. - It should be safe. - It is transparent to the user, they don't need to do anything special. - It doesn't expand Cargo's interface. Fixes #6914.
2 parents 24439f8 + c8a9f88 commit 65e3885

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

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

+17-3
Original file line numberDiff line numberDiff line change
@@ -554,10 +554,24 @@ fn compute_metadata<'a, 'cfg>(
554554
// Throw in the rustflags we're compiling with.
555555
// This helps when the target directory is a shared cache for projects with different cargo configs,
556556
// or if the user is experimenting with different rustflags manually.
557-
if unit.mode.is_doc() {
558-
cx.bcx.rustdocflags_args(unit).hash(&mut hasher);
557+
let mut flags = if unit.mode.is_doc() {
558+
cx.bcx.rustdocflags_args(unit)
559559
} else {
560-
cx.bcx.rustflags_args(unit).hash(&mut hasher);
560+
cx.bcx.rustflags_args(unit)
561+
}
562+
.into_iter();
563+
564+
// Ignore some flags. These may affect reproducible builds if they affect
565+
// the path. The fingerprint will handle recompilation if these change.
566+
while let Some(flag) = flags.next() {
567+
if flag.starts_with("--remap-path-prefix=") {
568+
continue;
569+
}
570+
if flag == "--remap-path-prefix" {
571+
flags.next();
572+
continue;
573+
}
574+
flag.hash(&mut hasher);
561575
}
562576

563577
// Artifacts compiled for the host should have a different metadata

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/rustflags.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1359,3 +1359,28 @@ fn env_rustflags_misspelled_build_script() {
13591359
.with_stderr_contains("[WARNING] Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?")
13601360
.run();
13611361
}
1362+
1363+
#[test]
1364+
fn reamp_path_prefix_ignored() {
1365+
// Ensure that --remap-path-prefix does not affect metadata hash.
1366+
let p = project().file("src/lib.rs", "").build();
1367+
p.cargo("build").run();
1368+
let rlibs = p
1369+
.glob("target/debug/deps/*.rlib")
1370+
.collect::<Result<Vec<_>, _>>()
1371+
.unwrap();
1372+
assert_eq!(rlibs.len(), 1);
1373+
p.cargo("clean").run();
1374+
1375+
p.cargo("build")
1376+
.env(
1377+
"RUSTFLAGS",
1378+
"--remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo",
1379+
)
1380+
.run();
1381+
let rlibs2 = p
1382+
.glob("target/debug/deps/*.rlib")
1383+
.collect::<Result<Vec<_>, _>>()
1384+
.unwrap();
1385+
assert_eq!(rlibs, rlibs2);
1386+
}

0 commit comments

Comments
 (0)