From e9e45c59a7a5a1ea500fd667a56c0d0ab101365a Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Mon, 12 Aug 2019 09:34:41 -0700 Subject: [PATCH 1/2] Hash the remapped sysroot instead of the original. This will help reproducible builds, as the sysroot depends on the working directory. --- src/librustc/session/config.rs | 11 +++++++++-- .../run-make-fulldeps/reproducible-build-2/Makefile | 12 +++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 3536b2aa8fffe..0a0f72a72c00c 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -395,7 +395,8 @@ top_level_options!( output_types: OutputTypes [TRACKED], search_paths: Vec [UNTRACKED], libs: Vec<(String, Option, Option)> [TRACKED], - maybe_sysroot: Option [TRACKED], + maybe_sysroot: Option [UNTRACKED], + maybe_sysroot_remapped: Option [TRACKED], target_triple: TargetTriple [TRACKED], @@ -610,6 +611,7 @@ impl Default for Options { output_types: OutputTypes(BTreeMap::new()), search_paths: vec![], maybe_sysroot: None, + maybe_sysroot_remapped: None, target_triple: TargetTriple::from_triple(host_triple()), test: false, incremental: None, @@ -2453,7 +2455,7 @@ pub fn build_session_options_and_crate_config( let crate_name = matches.opt_str("crate-name"); - let remap_path_prefix = matches + let remap_path_prefix: Vec<(PathBuf, PathBuf)> = matches .opt_strs("remap-path-prefix") .into_iter() .map(|remap| { @@ -2470,6 +2472,10 @@ pub fn build_session_options_and_crate_config( }) .collect(); + let sysroot_remapped_opt = sysroot_opt + .clone() + .map(|sysroot| FilePathMapping::new(remap_path_prefix.clone()).map_prefix(sysroot).0); + ( Options { crate_types, @@ -2481,6 +2487,7 @@ pub fn build_session_options_and_crate_config( output_types: OutputTypes(output_types), search_paths, maybe_sysroot: sysroot_opt, + maybe_sysroot_remapped: sysroot_remapped_opt, target_triple, test, incremental, diff --git a/src/test/run-make-fulldeps/reproducible-build-2/Makefile b/src/test/run-make-fulldeps/reproducible-build-2/Makefile index b96954fea0d1e..45c9a7427230b 100644 --- a/src/test/run-make-fulldeps/reproducible-build-2/Makefile +++ b/src/test/run-make-fulldeps/reproducible-build-2/Makefile @@ -5,7 +5,8 @@ # Objects are reproducible but their path is not. all: \ - fat_lto + fat_lto \ + sysroot fat_lto: rm -rf $(TMPDIR) && mkdir $(TMPDIR) @@ -14,3 +15,12 @@ fat_lto: cp $(TMPDIR)/reproducible-build $(TMPDIR)/reproducible-build-a $(RUSTC) reproducible-build.rs -C lto=fat cmp "$(TMPDIR)/reproducible-build-a" "$(TMPDIR)/reproducible-build" || exit 1 + +sysroot: + rm -rf $(TMPDIR) && mkdir $(TMPDIR) + $(RUSTC) reproducible-build-aux.rs + $(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(shell $(RUSTC) --print sysroot) --remap-path-prefix=$(shell $(RUSTC) --print sysroot)=/sysroot + cp -r $(shell $(RUSTC) --print sysroot) $(TMPDIR)/sysroot + cp $(TMPDIR)/libreproducible_build.rlib $(TMPDIR)/libfoo.rlib + $(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(TMPDIR)/sysroot --remap-path-prefix=$(TMPDIR)/sysroot=/sysroot + cmp "$(TMPDIR)/libreproducible_build.rlib" "$(TMPDIR)/libfoo.rlib" || exit 1 From 692c0bf4ff8d1f551850962bd8d3af62033dee39 Mon Sep 17 00:00:00 2001 From: Joel Galenson Date: Tue, 13 Aug 2019 09:12:06 -0700 Subject: [PATCH 2/2] Do not track the sysroot. As suggested by @alexcrichton, the sysroot only loads libraries that are themselves tracked. --- src/librustc/session/config.rs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 0a0f72a72c00c..8e3b910e0da3a 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -396,7 +396,6 @@ top_level_options!( search_paths: Vec [UNTRACKED], libs: Vec<(String, Option, Option)> [TRACKED], maybe_sysroot: Option [UNTRACKED], - maybe_sysroot_remapped: Option [TRACKED], target_triple: TargetTriple [TRACKED], @@ -611,7 +610,6 @@ impl Default for Options { output_types: OutputTypes(BTreeMap::new()), search_paths: vec![], maybe_sysroot: None, - maybe_sysroot_remapped: None, target_triple: TargetTriple::from_triple(host_triple()), test: false, incremental: None, @@ -2455,7 +2453,7 @@ pub fn build_session_options_and_crate_config( let crate_name = matches.opt_str("crate-name"); - let remap_path_prefix: Vec<(PathBuf, PathBuf)> = matches + let remap_path_prefix = matches .opt_strs("remap-path-prefix") .into_iter() .map(|remap| { @@ -2472,10 +2470,6 @@ pub fn build_session_options_and_crate_config( }) .collect(); - let sysroot_remapped_opt = sysroot_opt - .clone() - .map(|sysroot| FilePathMapping::new(remap_path_prefix.clone()).map_prefix(sysroot).0); - ( Options { crate_types, @@ -2487,7 +2481,6 @@ pub fn build_session_options_and_crate_config( output_types: OutputTypes(output_types), search_paths, maybe_sysroot: sysroot_opt, - maybe_sysroot_remapped: sysroot_remapped_opt, target_triple, test, incremental,