Skip to content

Commit e9e45c5

Browse files
committed
Hash the remapped sysroot instead of the original.
This will help reproducible builds, as the sysroot depends on the working directory.
1 parent c01be67 commit e9e45c5

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/librustc/session/config.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,8 @@ top_level_options!(
395395
output_types: OutputTypes [TRACKED],
396396
search_paths: Vec<SearchPath> [UNTRACKED],
397397
libs: Vec<(String, Option<String>, Option<cstore::NativeLibraryKind>)> [TRACKED],
398-
maybe_sysroot: Option<PathBuf> [TRACKED],
398+
maybe_sysroot: Option<PathBuf> [UNTRACKED],
399+
maybe_sysroot_remapped: Option<PathBuf> [TRACKED],
399400

400401
target_triple: TargetTriple [TRACKED],
401402

@@ -610,6 +611,7 @@ impl Default for Options {
610611
output_types: OutputTypes(BTreeMap::new()),
611612
search_paths: vec![],
612613
maybe_sysroot: None,
614+
maybe_sysroot_remapped: None,
613615
target_triple: TargetTriple::from_triple(host_triple()),
614616
test: false,
615617
incremental: None,
@@ -2453,7 +2455,7 @@ pub fn build_session_options_and_crate_config(
24532455

24542456
let crate_name = matches.opt_str("crate-name");
24552457

2456-
let remap_path_prefix = matches
2458+
let remap_path_prefix: Vec<(PathBuf, PathBuf)> = matches
24572459
.opt_strs("remap-path-prefix")
24582460
.into_iter()
24592461
.map(|remap| {
@@ -2470,6 +2472,10 @@ pub fn build_session_options_and_crate_config(
24702472
})
24712473
.collect();
24722474

2475+
let sysroot_remapped_opt = sysroot_opt
2476+
.clone()
2477+
.map(|sysroot| FilePathMapping::new(remap_path_prefix.clone()).map_prefix(sysroot).0);
2478+
24732479
(
24742480
Options {
24752481
crate_types,
@@ -2481,6 +2487,7 @@ pub fn build_session_options_and_crate_config(
24812487
output_types: OutputTypes(output_types),
24822488
search_paths,
24832489
maybe_sysroot: sysroot_opt,
2490+
maybe_sysroot_remapped: sysroot_remapped_opt,
24842491
target_triple,
24852492
test,
24862493
incremental,

src/test/run-make-fulldeps/reproducible-build-2/Makefile

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
# Objects are reproducible but their path is not.
66

77
all: \
8-
fat_lto
8+
fat_lto \
9+
sysroot
910

1011
fat_lto:
1112
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
@@ -14,3 +15,12 @@ fat_lto:
1415
cp $(TMPDIR)/reproducible-build $(TMPDIR)/reproducible-build-a
1516
$(RUSTC) reproducible-build.rs -C lto=fat
1617
cmp "$(TMPDIR)/reproducible-build-a" "$(TMPDIR)/reproducible-build" || exit 1
18+
19+
sysroot:
20+
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
21+
$(RUSTC) reproducible-build-aux.rs
22+
$(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(shell $(RUSTC) --print sysroot) --remap-path-prefix=$(shell $(RUSTC) --print sysroot)=/sysroot
23+
cp -r $(shell $(RUSTC) --print sysroot) $(TMPDIR)/sysroot
24+
cp $(TMPDIR)/libreproducible_build.rlib $(TMPDIR)/libfoo.rlib
25+
$(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(TMPDIR)/sysroot --remap-path-prefix=$(TMPDIR)/sysroot=/sysroot
26+
cmp "$(TMPDIR)/libreproducible_build.rlib" "$(TMPDIR)/libfoo.rlib" || exit 1

0 commit comments

Comments
 (0)