mirror of
https://github.com/rust-lang/cargo
synced 2024-09-13 21:11:44 +00:00
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.
This commit is contained in:
commit
65e3885ce3
|
@ -554,10 +554,24 @@ fn compute_metadata<'a, 'cfg>(
|
|||
// Throw in the rustflags we're compiling with.
|
||||
// This helps when the target directory is a shared cache for projects with different cargo configs,
|
||||
// or if the user is experimenting with different rustflags manually.
|
||||
if unit.mode.is_doc() {
|
||||
cx.bcx.rustdocflags_args(unit).hash(&mut hasher);
|
||||
let mut flags = if unit.mode.is_doc() {
|
||||
cx.bcx.rustdocflags_args(unit)
|
||||
} else {
|
||||
cx.bcx.rustflags_args(unit).hash(&mut hasher);
|
||||
cx.bcx.rustflags_args(unit)
|
||||
}
|
||||
.into_iter();
|
||||
|
||||
// Ignore some flags. These may affect reproducible builds if they affect
|
||||
// the path. The fingerprint will handle recompilation if these change.
|
||||
while let Some(flag) = flags.next() {
|
||||
if flag.starts_with("--remap-path-prefix=") {
|
||||
continue;
|
||||
}
|
||||
if flag == "--remap-path-prefix" {
|
||||
flags.next();
|
||||
continue;
|
||||
}
|
||||
flag.hash(&mut hasher);
|
||||
}
|
||||
|
||||
// Artifacts compiled for the host should have a different metadata
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
//! Target flags (test/bench/for_host/edition) | ✓ |
|
||||
//! -C incremental=… flag | ✓ |
|
||||
//! mtime of sources | ✓[^3] |
|
||||
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ |
|
||||
//! RUSTFLAGS/RUSTDOCFLAGS | ✓ | ✓
|
||||
//!
|
||||
//! [^1]: Build script and bin dependencies are not included.
|
||||
//!
|
||||
|
|
|
@ -1359,3 +1359,28 @@ fn env_rustflags_misspelled_build_script() {
|
|||
.with_stderr_contains("[WARNING] Cargo does not read `RUST_FLAGS` environment variable. Did you mean `RUSTFLAGS`?")
|
||||
.run();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reamp_path_prefix_ignored() {
|
||||
// Ensure that --remap-path-prefix does not affect metadata hash.
|
||||
let p = project().file("src/lib.rs", "").build();
|
||||
p.cargo("build").run();
|
||||
let rlibs = p
|
||||
.glob("target/debug/deps/*.rlib")
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
assert_eq!(rlibs.len(), 1);
|
||||
p.cargo("clean").run();
|
||||
|
||||
p.cargo("build")
|
||||
.env(
|
||||
"RUSTFLAGS",
|
||||
"--remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo",
|
||||
)
|
||||
.run();
|
||||
let rlibs2 = p
|
||||
.glob("target/debug/deps/*.rlib")
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
assert_eq!(rlibs, rlibs2);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue