Skip to content
Draft
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
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use tracing::span;

use crate::core::backend::CodegenBackendKind;
use crate::core::build_steps::gcc::{Gcc, GccOutput, GccTargetPair};
use crate::core::build_steps::llvm::{LlvmFromCi, prebuilt_llvm_output};
use crate::core::build_steps::llvm::{LlvmFromCi, LlvmKind, prebuilt_llvm_output};
use crate::core::build_steps::tool::{RustcPrivateCompilers, SourceType, copy_lld_artifacts};
use crate::core::build_steps::{dist, llvm};
use crate::core::builder::{
Expand Down Expand Up @@ -2191,7 +2191,7 @@ impl CommandLineStep for Assemble {
let src_path = llvm_bin_dir.join(&tool_exe);

// When using `download-ci-llvm`, some of the tools may not exist, so skip trying to copy them.
if !src_path.exists() && builder.config.llvm_ci_mode.download_from_ci() {
if !src_path.exists() && llvm_output.kind() == LlvmKind::DownloadedFromCi {
eprintln!("{} does not exist; skipping copy", src_path.display());
continue;
}
Expand Down
20 changes: 6 additions & 14 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::core::build_steps::compile::{
use crate::core::build_steps::doc::DocumentationFormat;
use crate::core::build_steps::gcc::GccTargetPair;
use crate::core::build_steps::llvm::{
LLVM_CI_LINK_TYPE_PATH, LlvmBuildStatus, get_llvm_build_status,
LLVM_CI_LINK_TYPE_PATH, LlvmBuildStatus, LlvmKind, get_llvm_build_status,
};
use crate::core::build_steps::tool::{
self, RustcPrivateCompilers, ToolTargetBuildMode, get_tool_target_compiler,
Expand Down Expand Up @@ -2525,12 +2525,7 @@ fn maybe_install_llvm(
// If the LLVM is coming from ourselves (just from CI) though, we
// still want to install it, as it otherwise won't be available.

// FIXME: this should be simplified once we stop pre-setting LLVM CI llvm-config during
// config parsing.
let is_system_llvm =
builder.config.target_config.get(&target).and_then(|t| t.llvm_config.as_ref()).is_some()
&& !(builder.config.llvm_ci_mode.download_from_ci()
&& builder.config.is_host_target(target));
let is_system_llvm = llvm.llvm_output().kind() == LlvmKind::External;
if is_system_llvm {
trace!("system LLVM requested, no install");
return false;
Expand Down Expand Up @@ -2712,11 +2707,10 @@ impl CommandLineStep for LlvmTools {

let target = self.target;

let llvm_output = builder.ensure(crate::core::build_steps::llvm::Llvm { target });

// Run only if a custom llvm-config is not used
if let Some(config) = builder.config.target_config.get(&target)
&& !builder.config.llvm_ci_mode.download_from_ci()
&& config.llvm_config.is_some()
{
if llvm_output.kind() == LlvmKind::External {
builder.info(&format!("Skipping LlvmTools ({target}): external LLVM"));
return None;
}
Expand All @@ -2725,8 +2719,6 @@ impl CommandLineStep for LlvmTools {
builder.require_submodule("src/llvm-project", None);
}

let llvm_output = builder.ensure(crate::core::build_steps::llvm::Llvm { target });

let mut tarball = Tarball::new(builder, "llvm-tools", &target.triple);
tarball.set_overlay(OverlayKind::Llvm);
tarball.is_preview(true);
Expand All @@ -2738,7 +2730,7 @@ impl CommandLineStep for LlvmTools {
for tool in tools_to_install(&builder.paths) {
let exe = src_bindir.join(exe(tool, target));
// When using `download-ci-llvm`, some of the tools may not exist, so skip trying to copy them.
if !exe.exists() && builder.config.llvm_ci_mode.download_from_ci() {
if !exe.exists() && llvm_output.kind() == LlvmKind::DownloadedFromCi {
eprintln!("{} does not exist; skipping copy", exe.display());
continue;
}
Expand Down
51 changes: 37 additions & 14 deletions src/bootstrap/src/core/build_steps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::utils::helpers::{
/// Path where a file containing the link type (dynamic or static) is stored in the LLVM CI tarball.
pub const LLVM_CI_LINK_TYPE_PATH: &str = "link-type.txt";

#[derive(Copy, Clone)]
#[derive(Copy, Clone, PartialEq, Eq)]
pub enum LlvmKind {
/// The LLVM was built from in-tree sources
BuiltLocally,
Expand Down Expand Up @@ -256,26 +256,45 @@ fn llvm_output_dir(builder: &Builder<'_>, target: TargetSelection) -> PathBuf {
}

fn try_download_ci_llvm(builder: &Builder<'_>, target: TargetSelection) -> Option<DownloadedLlvm> {
match builder.config.llvm_ci_mode {
LlvmCiMode::BuildLocally => return None,
LlvmCiMode::DownloadFromCi => {}
if builder.config.llvm_ci_mode.requests_download_from_ci()
&& let Some(config) = builder.config.target_config.get(&target)
{
if config.llvm_config.is_some() {
panic!(
"Cannot configure `llvm-config` for {target} when using `llvm.download-ci-llvm`",
);
}
if config.llvm_filecheck.is_some() {
panic!(
"Cannot configure `llvm-filecheck` for {target} when using `llvm.download-ci-llvm`"
);
}
}

// FIXME: this should eventually be relaxed
if target != builder.host_target {
crate::debug!("LLVM not available on CI for non-host target {target}");
return None;
match builder.config.llvm_ci_mode {
LlvmCiMode::BuildLocally => return None,
LlvmCiMode::Download => {}
LlvmCiMode::DownloadIfUnchanged => {
builder.config.update_submodule("src/llvm-project");

// Check for untracked changes in `src/llvm-project` and other important places.
let has_changes = builder.config.has_changes_from_upstream(LLVM_INVALIDATION_PATHS);
if has_changes {
builder.info("Warning: LLVM will not be downloaded because of local changes");
return None;
}
}
}

if !is_ci_llvm_available_for_target(&target, builder.config.llvm_assertions) {
crate::debug!(
"LLVM not available on CI for target={target} and assertions={}",
builder.info(&format!(
"Warning: LLVM not available on CI for target={target} and assertions={}",
builder.config.llvm_assertions
);
));
return None;
}

let ci_llvm = builder.config.maybe_download_host_ci_llvm()?;
let ci_llvm = builder.config.maybe_download_ci_llvm(target)?;
let link_shared = if !builder.config.dry_run() {
let link_type = t!(
std::fs::read_to_string(ci_llvm.join(LLVM_CI_LINK_TYPE_PATH)),
Expand All @@ -288,7 +307,7 @@ fn try_download_ci_llvm(builder: &Builder<'_>, target: TargetSelection) -> Optio

Some(DownloadedLlvm {
output: LlvmOutput {
llvm_config: ci_llvm.join("bin").join(exe("llvm-config", builder.host_target)),
llvm_config: ci_llvm.join("bin").join(exe("llvm-config", target)),
link_shared,
llvm_root_dir: ci_llvm,
kind: LlvmKind::DownloadedFromCi,
Expand Down Expand Up @@ -405,8 +424,12 @@ impl Step for LlvmFromCi {

fn run(self, builder: &Builder<'_>) -> Self::Output {
let llvm_ci = try_download_ci_llvm(builder, self.target)?;

// Sanity check
check_llvm_version(builder, llvm_ci.output.llvm_config());
if builder.host_target == self.target {
check_llvm_version(builder, llvm_ci.output.llvm_config());
}

Some(llvm_ci)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/builder/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,9 +743,9 @@ impl Builder<'_> {
cargo.env("REAL_LIBRARY_PATH", e);
}

// Set a flag for `check`/`clippy`/`fix`, so that certain build
// scripts can do less work (i.e. not building/requiring LLVM).
if matches!(cmd_kind, Kind::Check | Kind::Clippy | Kind::Fix) {
// Set a flag for `check`/`clippy`/`fix`, so that te rustc_llvm build
// script can do less work (i.e. not building C/C++ code and requiring LLVM).
if matches!(cmd_kind, Kind::Check | Kind::Clippy | Kind::Fix) && mode == Mode::Rustc {
// If we've not yet built LLVM, or it's stale, then bust
// the rustc_llvm cache. That will always work, even though it
// may mean that on the next non-check build we'll need to rebuild
Expand Down
6 changes: 5 additions & 1 deletion src/bootstrap/src/core/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use tracing::instrument;

pub(crate) use self::cargo::{Cargo, apply_pgo, cargo_profile_var};
use crate::core::build_steps::compile::{Std, StdLink, looks_like_codegen_backend};
use crate::core::build_steps::llvm::{LlvmKind, get_llvm_build_status};
use crate::core::build_steps::tool::RustcPrivateCompilers;
use crate::core::build_steps::{
check, clean, clippy, compile, dist, doc, gcc, install, llvm, run, setup, test, tool, vendor,
Expand Down Expand Up @@ -1377,7 +1378,10 @@ Alternatively, you can set `build.local-rebuild=true` and use a stage0 compiler
let mut dylib_dirs = vec![self.rustc_libdir(compiler)];

// Ensure that the downloaded LLVM libraries can be found.
if self.config.llvm_ci_mode.download_from_ci() {
// FIXME: the libraries should be added elsewhere, not in this function...
if get_llvm_build_status(self, compiler.host).llvm_output().kind()
== LlvmKind::DownloadedFromCi
{
let ci_llvm_lib = self.out.join(compiler.host).join("ci-llvm").join("lib");
dylib_dirs.push(ci_llvm_lib);
}
Expand Down
16 changes: 8 additions & 8 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use build_helper::stage0_parser::parse_stage0_file;
use llvm::get_llvm_build_status;

use super::*;
use crate::core::build_steps::llvm::LlvmKind;
use crate::core::config::Config;
use crate::utils::cache::ExecutedStep;
use crate::utils::helpers::get_host_target;
Expand Down Expand Up @@ -293,15 +294,14 @@ fn test_prebuilt_llvm_config_path_resolution() {
"#,
);

// CI-LLVM isn't always available; check if it's enabled before testing.
if config.llvm_ci_mode.download_from_ci() {
let build = Build::new(config.clone());
let builder = Builder::new(&build);
let build = Build::new(config.clone());
let builder = Builder::new(&build);

let actual = get_llvm_build_status(&builder, builder.config.host_target)
.llvm_output()
.llvm_config()
.to_path_buf();
let llvm = get_llvm_build_status(&builder, builder.config.host_target);
let llvm = llvm.llvm_output();
// CI-LLVM isn't always available; check if it's enabled before testing.
if llvm.kind() == LlvmKind::DownloadedFromCi {
let actual = llvm.llvm_config().to_path_buf();
let expected = builder
.out
.join(builder.config.host_target)
Expand Down
Loading
Loading