From 7cb52a6ef77aa30142b500dfeba076418437b710 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 19 Nov 2026 19:12:42 +0000 Subject: [PATCH] Add source files in name order fs::read_dir returns entries in an order that depends on the file system (on ext4 with dir_index, a per-volume filename hash), so the objects in the built archive, and the layout of binaries linking it, differ from one machine to another. Sorting the files makes the build reproducible. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01GkmLQ5nvNrfRpnUjryR3hR --- src/lib.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 95c3e4b..ad077de 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -314,12 +314,17 @@ trait AddFilesByExt { impl AddFilesByExt for cc::Build { fn add_files_by_ext(&mut self, dir: &Path, ext: &str) -> Result<&mut Self, Box> { - for entry in fs::read_dir(dir) + let mut files = fs::read_dir(dir) .context(|| format!("Cannot read '{}'", dir.display()))? .filter_map(|e| e.ok()) - .filter(|e| e.path().extension() == Some(ext.as_ref())) - { - self.file(entry.path()); + .map(|e| e.path()) + .filter(|p| p.extension() == Some(ext.as_ref())) + .collect::>(); + // `read_dir` order depends on the file system (on ext4, a per-volume hash), + // so sort to make the archive, and binaries linking it, reproducible + files.sort(); + for file in files { + self.file(file); } Ok(self) }