Skip to content

Commit 555e773

Browse files
committed
Set ZERO_AR_DATE for archiver invocations
This should help improve determinism on OSX and lots more comments for how this works are located in the source
1 parent e2f4692 commit 555e773

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/lib.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,31 @@ impl Build {
15751575
};
15761576
} else {
15771577
let (mut ar, cmd) = self.get_ar()?;
1578+
1579+
// Set an environment variable to tell the OSX archiver to ensure
1580+
// that all dates listed in the archive are zero, improving
1581+
// determinism of builds. AFAIK there's not really official
1582+
// documentation of this but there's a lot of references to it if
1583+
// you search google.
1584+
//
1585+
// You can reproduce this locally on a mac with:
1586+
//
1587+
// $ touch foo.c
1588+
// $ cc -c foo.c -o foo.o
1589+
//
1590+
// # Notice that these two checksums are different
1591+
// $ ar crus libfoo1.a foo.o && sleep 2 && ar crus libfoo2.a foo.o
1592+
// $ md5sum libfoo*.a
1593+
//
1594+
// # Notice that these two checksums are the same
1595+
// $ export ZERO_AR_DATE=1
1596+
// $ ar crus libfoo1.a foo.o && sleep 2 && touch foo.o && ar crus libfoo2.a foo.o
1597+
// $ md5sum libfoo*.a
1598+
//
1599+
// In any case if this doesn't end up getting read, it shouldn't
1600+
// cause that many issues!
1601+
ar.env("ZERO_AR_DATE", "1");
1602+
15781603
run(
15791604
ar.arg("crs").arg(dst).args(&objects).args(&self.objects),
15801605
&cmd,

0 commit comments

Comments
 (0)