Skip to content

Commit 52bbc67

Browse files
committed
Address some rustc inconsistency issues
We noticed when building rustc multiple time in a roll, some files will not be consistent across the build despite the fact that they are built from same source under the same environment. This patch addresses the inconsistency issue we found on libunwind.a by sorting the order of the files passed to the linker. This patch also adds a passthrough of "SOURCE_DATE_EPOCH" env arg from bootstrap to cargo to partially address the inconsistency on the cargo binary.
1 parent 1c6de21 commit 52bbc67

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,15 +2376,19 @@ pub fn run_cargo(
23762376
let mut deps = Vec::new();
23772377
let mut toplevel = Vec::new();
23782378
let ok = stream_cargo(builder, cargo, tail_args, &mut |msg| {
2379-
let (filenames, crate_types) = match msg {
2379+
let (filenames_vec, crate_types) = match msg {
23802380
CargoMessage::CompilerArtifact {
23812381
filenames,
23822382
target: CargoTarget { crate_types },
23832383
..
2384-
} => (filenames, crate_types),
2384+
} => {
2385+
let mut f: Vec<String> = filenames.into_iter().map(|s| s.into_owned()).collect();
2386+
f.sort(); // Sort the filenames
2387+
(f, crate_types)
2388+
}
23852389
_ => return,
23862390
};
2387-
for filename in filenames {
2391+
for filename in filenames_vec {
23882392
// Skip files like executables
23892393
let mut keep = false;
23902394
if filename.ends_with(".lib")

src/bootstrap/src/core/build_steps/llvm.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1528,8 +1528,12 @@ impl Step for Libunwind {
15281528

15291529
// FIXME: https://github.com/alexcrichton/cc-rs/issues/545#issuecomment-679242845
15301530
let mut count = 0;
1531-
for entry in fs::read_dir(&out_dir).unwrap() {
1532-
let file = entry.unwrap().path().canonicalize().unwrap();
1531+
let mut files = fs::read_dir(&out_dir)
1532+
.unwrap()
1533+
.map(|entry| entry.unwrap().path().canonicalize().unwrap())
1534+
.collect::<Vec<_>>();
1535+
files.sort();
1536+
for file in files {
15331537
if file.is_file() && file.extension() == Some(OsStr::new("o")) {
15341538
// Object file name without the hash prefix is "Unwind-EHABI", "Unwind-seh" or "libunwind".
15351539
let base_name = unhashed_basename(&file);

src/bootstrap/src/core/builder/cargo.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,16 @@ impl Builder<'_> {
12691269
if self.link_std_into_rustc_driver(target) { "1" } else { "0" },
12701270
);
12711271

1272+
// Crates like openssl will record current timestamp at build time.
1273+
// The current timestamp can be override by SOURCE_DATE_EPOCH
1274+
// environment variable.
1275+
// Pass through SOURCE_DATE_EPOCH environment variable to allow
1276+
// some crates to be reproducible.
1277+
let source_date_epoch_env = "SOURCE_DATE_EPOCH";
1278+
if let Ok(var) = std::env::var(&source_date_epoch_env) {
1279+
cargo.env(&source_date_epoch_env, &var);
1280+
}
1281+
12721282
// When building incrementally we default to a lower ThinLTO import limit
12731283
// (unless explicitly specified otherwise). This will produce a somewhat
12741284
// slower code but give way better compile times.

0 commit comments

Comments
 (0)