Skip to content

Commit 1140c52

Browse files
committed
Auto merge of #7134 - ehuss:remap-rustc, r=Eh2406
Also ignore remap-path-prefix in metadata for `cargo rustc`. Also ignore `--remap-path-prefix` in `cargo rustc`. Who knew that `BuildContext` had 3 sets of arguments? Closes #7133
2 parents 705009e + d99b7fe commit 1140c52

File tree

2 files changed

+39
-26
lines changed

2 files changed

+39
-26
lines changed

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

+24-20
Original file line numberDiff line numberDiff line change
@@ -547,32 +547,36 @@ fn compute_metadata<'a, 'cfg>(
547547
// settings like debuginfo and whatnot.
548548
unit.profile.hash(&mut hasher);
549549
unit.mode.hash(&mut hasher);
550-
if let Some(args) = bcx.extra_args_for(unit) {
551-
args.hash(&mut hasher);
552-
}
553550

554551
// Throw in the rustflags we're compiling with.
555552
// This helps when the target directory is a shared cache for projects with different cargo configs,
556553
// or if the user is experimenting with different rustflags manually.
557-
let mut flags = if unit.mode.is_doc() {
558-
cx.bcx.rustdocflags_args(unit)
559-
} else {
560-
cx.bcx.rustflags_args(unit)
561-
}
562-
.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;
554+
let mut hash_flags = |flags: &[String]| {
555+
// Ignore some flags. These may affect reproducible builds if they affect
556+
// the path. The fingerprint will handle recompilation if these change.
557+
let mut iter = flags.iter();
558+
while let Some(flag) = iter.next() {
559+
if flag.starts_with("--remap-path-prefix=") {
560+
continue;
561+
}
562+
if flag == "--remap-path-prefix" {
563+
iter.next();
564+
continue;
565+
}
566+
flag.hash(&mut hasher);
573567
}
574-
flag.hash(&mut hasher);
568+
};
569+
if let Some(args) = bcx.extra_args_for(unit) {
570+
// Arguments passed to `cargo rustc`.
571+
hash_flags(args);
575572
}
573+
// Arguments passed in via RUSTFLAGS env var.
574+
let flags = if unit.mode.is_doc() {
575+
bcx.rustdocflags_args(unit)
576+
} else {
577+
bcx.rustflags_args(unit)
578+
};
579+
hash_flags(flags);
576580

577581
// Artifacts compiled for the host should have a different metadata
578582
// piece than those compiled for the target, so make sure we throw in

tests/testsuite/rustflags.rs

+15-6
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ fn env_rustflags_misspelled_build_script() {
13611361
}
13621362

13631363
#[cargo_test]
1364-
fn reamp_path_prefix_ignored() {
1364+
fn remap_path_prefix_ignored() {
13651365
// Ensure that --remap-path-prefix does not affect metadata hash.
13661366
let p = project().file("src/lib.rs", "").build();
13671367
p.cargo("build").run();
@@ -1372,15 +1372,24 @@ fn reamp_path_prefix_ignored() {
13721372
assert_eq!(rlibs.len(), 1);
13731373
p.cargo("clean").run();
13741374

1375+
let check_metadata_same = || {
1376+
let rlibs2 = p
1377+
.glob("target/debug/deps/*.rlib")
1378+
.collect::<Result<Vec<_>, _>>()
1379+
.unwrap();
1380+
assert_eq!(rlibs, rlibs2);
1381+
};
1382+
13751383
p.cargo("build")
13761384
.env(
13771385
"RUSTFLAGS",
13781386
"--remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo",
13791387
)
13801388
.run();
1381-
let rlibs2 = p
1382-
.glob("target/debug/deps/*.rlib")
1383-
.collect::<Result<Vec<_>, _>>()
1384-
.unwrap();
1385-
assert_eq!(rlibs, rlibs2);
1389+
check_metadata_same();
1390+
1391+
p.cargo("clean").run();
1392+
p.cargo("rustc -- --remap-path-prefix=/abc=/zoo --remap-path-prefix /spaced=/zoo")
1393+
.run();
1394+
check_metadata_same();
13861395
}

0 commit comments

Comments
 (0)