Skip to content

Commit b3f369d

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.
1 parent 1c6de21 commit b3f369d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-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);

0 commit comments

Comments
 (0)