Skip to content

Commit 5239f5c

Browse files
committed
Auto merge of #71931 - alexcrichton:reproducible-macos, r=eddyb
Export ZERO_AR_DATE for macos linker invocations This commit attempts to improve reproducibility of builds on macOS by exporting the `ZERO_AR_DATE=1` environment variable for all invocations of the linker. While it looks like this env var is targeted at just the `ar` command (which does actually read this) it appears that recent-ish versions of the linker *also* read this environment variable. This env var forces the linker to set a deterministic zero value for the mtime in the N_OSO field of the object file. Currently it's believe that older versions of the linker will simply ignore this env var, while newer versions will read it and produce a deterministic output for compilations with debuginfo. Closes #47086 Closes #66568
2 parents aeca4d6 + afd88f2 commit 5239f5c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/librustc_target/spec/apple_base.rs

+11
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ pub fn opts() -> TargetOptions {
3131
has_elf_tls: version >= (10, 7),
3232
abi_return_struct_as_int: true,
3333
emit_debug_gdb_scripts: false,
34+
35+
// This environment variable is pretty magical but is intended for
36+
// producing deterministic builds. This was first discovered to be used
37+
// by the `ar` tool as a way to control whether or not mtime entries in
38+
// the archive headers were set to zero or not. It appears that
39+
// eventually the linker got updated to do the same thing and now reads
40+
// this environment variable too in recent versions.
41+
//
42+
// For some more info see the commentary on #47086
43+
link_env: vec![("ZERO_AR_DATE".to_string(), "1".to_string())],
44+
3445
..Default::default()
3546
}
3647
}

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
# ignore-musl
44
# ignore-windows
5-
# ignore-macos (rust-lang/rust#66568)
65
# Objects are reproducible but their path is not.
76

87
all: \
@@ -21,7 +20,7 @@ sysroot:
2120
rm -rf $(TMPDIR) && mkdir $(TMPDIR)
2221
$(RUSTC) reproducible-build-aux.rs
2322
$(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(shell $(RUSTC) --print sysroot) --remap-path-prefix=$(shell $(RUSTC) --print sysroot)=/sysroot
24-
cp -r $(shell $(RUSTC) --print sysroot) $(TMPDIR)/sysroot
23+
cp -R $(shell $(RUSTC) --print sysroot) $(TMPDIR)/sysroot
2524
cp $(TMPDIR)/libreproducible_build.rlib $(TMPDIR)/libfoo.rlib
2625
$(RUSTC) reproducible-build.rs --crate-type rlib --sysroot $(TMPDIR)/sysroot --remap-path-prefix=$(TMPDIR)/sysroot=/sysroot
2726
cmp "$(TMPDIR)/libreproducible_build.rlib" "$(TMPDIR)/libfoo.rlib" || exit 1

0 commit comments

Comments
 (0)