From 624acc8e2be3cda315772c388feabf6bc6f69d2e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 7 Aug 2020 14:46:15 -0700 Subject: [PATCH] Build manpage archive deterministically Keep deterministic builds for Cargo! The changes here are: * Sort files being added to the archive to ensure they're added in the same order on all platforms. * Flag the archive builder as "deterministic mode" which means it won't pick up fields like mtime. Closes #8599 --- build.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index 0542fef11..8c33c72b0 100644 --- a/build.rs +++ b/build.rs @@ -14,10 +14,15 @@ fn compress_man() { .filename("man.tar") .write(dst, Compression::best()); let mut ar = tar::Builder::new(encoder); + ar.mode(tar::HeaderMode::Deterministic); let mut add_files = |dir, extension| { - for entry in fs::read_dir(dir).unwrap() { - let path = entry.unwrap().path(); + let mut files = fs::read_dir(dir) + .unwrap() + .map(|e| e.unwrap().path()) + .collect::>(); + files.sort(); + for path in files { if path.extension() != Some(extension) { continue; }