Skip to content

bootstrap: skip llvm-tools install when externally provided #109196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
15 changes: 15 additions & 0 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -251,6 +251,11 @@ install!((self, builder, _config),
};
);

fn should_build_llvm(config: &Config) -> bool {
// additionaly check that llvm is not externally provided
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you write this as a doc-comment on top of this function? It will be better for other devs to directly read this via LSP/rust-analyzer.

LlvmTools::should_build(config) && config.is_rust_llvm(config.build)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That code is not correct : the config.build is not the one we want...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if any of the configure_args items starts with --llvm-root

Can you do this check in here? It should do the work

}

#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct Src {
pub stage: u32,
Expand Down
17 changes: 1 addition & 16 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down