From 7fb4512ee8d5aea8e362dd736fe08586db369416 Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Tue, 6 Feb 2024 23:31:52 +0300 Subject: [PATCH 1/2] fix `llvm_out` to use the correct LLVM root When `download-ci-llvm` is enabled, `llvm_out` ends up with the error below due to an incorrect path on cross-compilations. This change fixes that. ``` failed to execute command: "/rust/build/x86_64-unknown-linux-gnu/llvm/build/bin/llvm-config" "--version" ERROR: No such file or directory (os error 2) ``` Signed-off-by: onur-ozkan --- src/bootstrap/src/core/build_steps/llvm.rs | 2 +- src/bootstrap/src/lib.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 4b2d3e9ab4b75..afbbbb5bd269d 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -98,7 +98,7 @@ pub fn prebuilt_llvm_config( let out_dir = builder.llvm_out(target); let mut llvm_config_ret_dir = builder.llvm_out(builder.config.build); - if !builder.config.build.is_msvc() || builder.ninja() { + if (!builder.config.build.is_msvc() || builder.ninja()) && !builder.config.llvm_from_ci { llvm_config_ret_dir.push("build"); } llvm_config_ret_dir.push("bin"); diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 1336abf6c7aba..c6c929c90b3d3 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -796,12 +796,16 @@ impl Build { self.stage_out(compiler, mode).join(&*target.triple).join(self.cargo_dir()) } - /// Root output directory for LLVM compiled for `target` + /// Root output directory of LLVM for `target` /// /// Note that if LLVM is configured externally then the directory returned /// will likely be empty. fn llvm_out(&self, target: TargetSelection) -> PathBuf { - self.out.join(&*target.triple).join("llvm") + if self.config.llvm_from_ci && self.config.build == target { + self.config.ci_llvm_root() + } else { + self.out.join(&*target.triple).join("llvm") + } } fn lld_out(&self, target: TargetSelection) -> PathBuf { From 63cc3c7b8f4df8076422ebc74260eccaebb6897c Mon Sep 17 00:00:00 2001 From: onur-ozkan Date: Wed, 7 Feb 2024 09:47:34 +0300 Subject: [PATCH 2/2] test `llvm_out` behaviour Signed-off-by: onur-ozkan --- src/bootstrap/src/core/builder/tests.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 700ebcf5e3741..2cbebbcf4e2af 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -524,6 +524,23 @@ mod dist { ); } + #[test] + fn llvm_out_behaviour() { + let mut config = configure(&["A"], &["B"]); + config.llvm_from_ci = true; + let build = Build::new(config.clone()); + + let target = TargetSelection::from_user("A"); + assert!(build.llvm_out(target).ends_with("ci-llvm")); + let target = TargetSelection::from_user("B"); + assert!(build.llvm_out(target).ends_with("llvm")); + + config.llvm_from_ci = false; + let build = Build::new(config.clone()); + let target = TargetSelection::from_user("A"); + assert!(build.llvm_out(target).ends_with("llvm")); + } + #[test] fn build_with_empty_host() { let config = configure(&[], &["C"]);