Skip to content

Commit 831faaf

Browse files
authored
Compile libgit2 deterministically by sorting read_dir (#619)
1 parent 218a2b3 commit 831faaf

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

libgit2-sys/build.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::env;
22
use std::fs;
3+
use std::io;
34
use std::path::{Path, PathBuf};
45
use std::process::Command;
56

@@ -199,8 +200,12 @@ fn cp_r(from: impl AsRef<Path>, to: impl AsRef<Path>) {
199200
}
200201

201202
fn add_c_files(build: &mut cc::Build, path: impl AsRef<Path>) {
202-
for e in path.as_ref().read_dir().unwrap() {
203-
let e = e.unwrap();
203+
// sort the C files to ensure a deterministic build for reproducible builds
204+
let dir = path.as_ref().read_dir().unwrap();
205+
let mut paths = dir.collect::<io::Result<Vec<_>>>().unwrap();
206+
paths.sort_by_key(|e| e.path());
207+
208+
for e in paths {
204209
let path = e.path();
205210
if e.file_type().unwrap().is_dir() {
206211
// skip dirs for now

0 commit comments

Comments
 (0)