diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 8b80dfc0f9b97..ebd8aef29c4cf 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -872,7 +872,7 @@ pub fn rustc_cargo_env(builder: &Builder<'_>, cargo: &mut Cargo, target: TargetS && (builder.kind != Kind::Check || crate::native::prebuilt_llvm_config(builder, target).is_ok()) { - if builder.is_rust_llvm(target) { + if builder.config.is_rust_llvm(target) { cargo.env("LLVM_RUSTLLVM", "1"); } let native::LlvmResult { llvm_config, .. } = builder.ensure(native::Llvm { target }); diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 58729f396f0b6..1f3e7401bf678 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -1606,6 +1606,21 @@ impl Config { }) } + /// Returns `true` if no custom `llvm-config` is set for the specified target. + /// + /// If no custom `llvm-config` was specified then Rust's llvm will be used. + pub fn is_rust_llvm(&self, target: TargetSelection) -> bool { + match self.target_config.get(&target) { + Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched, + Some(Target { llvm_config, .. }) => { + // If the user set llvm-config we assume Rust is not patched, + // but first check to see if it was configured by llvm-from-ci. + (self.llvm_from_ci && target == self.build) || llvm_config.is_none() + } + None => true, + } + } + pub fn submodules(&self, rust_info: &GitInfo) -> bool { self.submodules.unwrap_or(rust_info.is_managed_git_subrepository()) } diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index ac3843c3344eb..d023df19f2d3d 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -209,7 +209,7 @@ install!((self, builder, _config), ); } }; - LlvmTools, alias = "llvm-tools", Self::should_build(_config), only_hosts: true, { + LlvmTools, alias = "llvm-tools", should_build_llvm(_config), only_hosts: true, { let tarball = builder .ensure(dist::LlvmTools { target: self.target }) .expect("missing llvm-tools"); @@ -251,6 +251,11 @@ install!((self, builder, _config), }; ); +fn should_build_llvm(config: &Config) -> bool { + // additionaly check that llvm is not externally provided + LlvmTools::should_build(config) && config.is_rust_llvm(config.build) +} + #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] pub struct Src { pub stage: u32, diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index f136690592d72..dbed36d6375c6 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -28,7 +28,7 @@ use std::str; use build_helper::ci::CiEnv; use channel::GitInfo; -use config::{DryRun, Target}; +use config::DryRun; use filetime::FileTime; use once_cell::sync::OnceCell; @@ -831,21 +831,6 @@ impl Build { INTERNER.intern_path(self.out.join(&*target.triple).join("md-doc")) } - /// Returns `true` if no custom `llvm-config` is set for the specified target. - /// - /// If no custom `llvm-config` was specified then Rust's llvm will be used. - fn is_rust_llvm(&self, target: TargetSelection) -> bool { - match self.config.target_config.get(&target) { - Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched, - Some(Target { llvm_config, .. }) => { - // If the user set llvm-config we assume Rust is not patched, - // but first check to see if it was configured by llvm-from-ci. - (self.config.llvm_from_ci && target == self.config.build) || llvm_config.is_none() - } - None => true, - } - } - /// Returns the path to `FileCheck` binary for the specified target fn llvm_filecheck(&self, target: TargetSelection) -> PathBuf { let target_config = self.config.target_config.get(&target); diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index f5d680df1133b..9092992c1cb23 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1635,7 +1635,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the .arg(llvm_components.trim()); llvm_components_passed = true; } - if !builder.is_rust_llvm(target) { + if !builder.config.is_rust_llvm(target) { cmd.arg("--system-llvm"); }