about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-04-16 17:54:39 +0200
committerGitHub <noreply@github.com>2024-04-16 17:54:39 +0200
commit592b1ca99a0a87c780bc0d4c2ef7ff8b8c6e9715 (patch)
tree77ae3dd7bb3a66cd3b138f3fa4067f9fa69d1447
parent1dea922ea6e74f99a0e97de5cdb8174e4dea0444 (diff)
parent3683b11d212d938b5c314a0d0971b794d521046f (diff)
downloadrust-592b1ca99a0a87c780bc0d4c2ef7ff8b8c6e9715.tar.gz
rust-592b1ca99a0a87c780bc0d4c2ef7ff8b8c6e9715.zip
Rollup merge of #122632 - onur-ozkan:fix-llvm-caching-bug, r=albertlarsan68
fetch submodule before checking llvm stamp

Previously, we were checking the LLVM stamp before fetching the submodule which leads to not being able to compile llvm on submodule updates.

Fixes #122612
Fixes #122787
-rw-r--r--src/bootstrap/src/core/build_steps/llvm.rs7
-rw-r--r--src/bootstrap/src/lib.rs12
2 files changed, 18 insertions, 1 deletions
diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs
index 420336fee14..7cb15fe5590 100644
--- a/src/bootstrap/src/core/build_steps/llvm.rs
+++ b/src/bootstrap/src/core/build_steps/llvm.rs
@@ -76,6 +76,9 @@ pub fn prebuilt_llvm_config(
     builder: &Builder<'_>,
     target: TargetSelection,
 ) -> Result<LlvmResult, Meta> {
+    // If we have llvm submodule initialized already, sync it.
+    builder.update_existing_submodule(&Path::new("src").join("llvm-project"));
+
     builder.config.maybe_download_ci_llvm();
 
     // If we're using a custom LLVM bail out here, but we can only use a
@@ -94,6 +97,9 @@ pub fn prebuilt_llvm_config(
         }
     }
 
+    // Initialize the llvm submodule if not initialized already.
+    builder.update_submodule(&Path::new("src").join("llvm-project"));
+
     let root = "src/llvm-project/llvm";
     let out_dir = builder.llvm_out(target);
 
@@ -280,7 +286,6 @@ impl Step for Llvm {
             Err(m) => m,
         };
 
-        builder.update_submodule(&Path::new("src").join("llvm-project"));
         if builder.llvm_link_shared() && target.is_windows() {
             panic!("shared linking to LLVM is not currently supported on {}", target.triple);
         }
diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs
index 1a8322c0dfd..a609bbbffb6 100644
--- a/src/bootstrap/src/lib.rs
+++ b/src/bootstrap/src/lib.rs
@@ -630,6 +630,18 @@ impl Build {
         }
     }
 
+    /// Updates the given submodule only if it's initialized already; nothing happens otherwise.
+    pub fn update_existing_submodule(&self, submodule: &Path) {
+        // Avoid running git when there isn't a git checkout.
+        if !self.config.submodules(self.rust_info()) {
+            return;
+        }
+
+        if GitInfo::new(false, submodule).is_managed_git_subrepository() {
+            self.update_submodule(submodule);
+        }
+    }
+
     /// Executes the entire build, as configured by the flags and configuration.
     pub fn build(&mut self) {
         unsafe {