about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHaowei Wu <haowei@google.com>2025-07-17 16:12:28 -0700
committerHaowei Wu <haowei@google.com>2025-07-30 14:25:33 -0700
commitb3f369d9252e4c0d5dd9bd28b950c7730fcd2c3d (patch)
treeaecdea1b175f4ffb7829b23d2d63778367dbf5a3
parent1c6de215099bbe33668de762f9591187f6c25eef (diff)
downloadrust-b3f369d9252e4c0d5dd9bd28b950c7730fcd2c3d.tar.gz
rust-b3f369d9252e4c0d5dd9bd28b950c7730fcd2c3d.zip
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.
-rw-r--r--src/bootstrap/src/core/build_steps/compile.rs10
-rw-r--r--src/bootstrap/src/core/build_steps/llvm.rs8
2 files changed, 13 insertions, 5 deletions
diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs
index 09bb2e35bda..11a5554691d 100644
--- a/src/bootstrap/src/core/build_steps/compile.rs
+++ b/src/bootstrap/src/core/build_steps/compile.rs
@@ -2376,15 +2376,19 @@ pub fn run_cargo(
     let mut deps = Vec::new();
     let mut toplevel = Vec::new();
     let ok = stream_cargo(builder, cargo, tail_args, &mut |msg| {
-        let (filenames, crate_types) = match msg {
+        let (filenames_vec, crate_types) = match msg {
             CargoMessage::CompilerArtifact {
                 filenames,
                 target: CargoTarget { crate_types },
                 ..
-            } => (filenames, crate_types),
+            } => {
+                let mut f: Vec<String> = filenames.into_iter().map(|s| s.into_owned()).collect();
+                f.sort(); // Sort the filenames
+                (f, crate_types)
+            }
             _ => return,
         };
-        for filename in filenames {
+        for filename in filenames_vec {
             // Skip files like executables
             let mut keep = false;
             if filename.ends_with(".lib")
diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs
index b2056f5cf37..721ba6ca459 100644
--- a/src/bootstrap/src/core/build_steps/llvm.rs
+++ b/src/bootstrap/src/core/build_steps/llvm.rs
@@ -1528,8 +1528,12 @@ impl Step for Libunwind {
 
         // FIXME: https://github.com/alexcrichton/cc-rs/issues/545#issuecomment-679242845
         let mut count = 0;
-        for entry in fs::read_dir(&out_dir).unwrap() {
-            let file = entry.unwrap().path().canonicalize().unwrap();
+        let mut files = fs::read_dir(&out_dir)
+            .unwrap()
+            .map(|entry| entry.unwrap().path().canonicalize().unwrap())
+            .collect::<Vec<_>>();
+        files.sort();
+        for file in files {
             if file.is_file() && file.extension() == Some(OsStr::new("o")) {
                 // Object file name without the hash prefix is "Unwind-EHABI", "Unwind-seh" or "libunwind".
                 let base_name = unhashed_basename(&file);