From b75e6b4e7e7b12b461e70a5ffaf280b46c746575 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Sun, 17 Mar 2024 13:34:42 +0300 Subject: [PATCH 1/2] 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. Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/llvm.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 701bd585eee76..327dc04b4e516 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -94,6 +94,7 @@ pub fn prebuilt_llvm_config( } } + builder.update_submodule(&Path::new("src").join("llvm-project")); let root = "src/llvm-project/llvm"; let out_dir = builder.llvm_out(target); @@ -279,7 +280,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); } From 3683b11d212d938b5c314a0d0971b794d521046f Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Thu, 28 Mar 2024 17:27:17 +0300 Subject: [PATCH 2/2] create `Build::update_existing_submodule` and use for llvm Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/llvm.rs | 5 +++++ src/bootstrap/src/lib.rs | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 327dc04b4e516..59fdd2e3caf57 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 { + // 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,7 +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); diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index f0fe994d155d0..9568514db5101 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -625,6 +625,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 {