From a142760260685a44fabf6675a4247d1a60a30287 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 2 Oct 2022 08:22:25 -0500 Subject: [PATCH] Distinguish "has patches" from "in-tree" again Fixes https://github.com/rust-lang/rust/issues/102560 --- src/bootstrap/compile.rs | 7 ++++++- src/bootstrap/dist.rs | 34 ++++++++++++++++++++++------------ src/bootstrap/lib.rs | 15 ++++++++------- 3 files changed, 36 insertions(+), 20 deletions(-) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index f3f6c1f65e513..21a2faeb953e7 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -312,12 +312,17 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car let compiler_builtins_c_feature = if builder.config.optimized_compiler_builtins { if !builder.is_rust_llvm(target) { panic!( - "need a managed LLVM submodule for optimized intrinsics support; unset `llvm-config` or `optimized-compiler-builtins`" + "LLVM must have the Rust project's patched sources to support using it for `compiler-builtins`; unset `llvm-config` or `optimized-compiler-builtins`" ); } builder.update_submodule(&Path::new("src").join("llvm-project")); let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt"); + if !compiler_builtins_root.exists() { + panic!( + "needed LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true`" + ); + } // Note that `libprofiler_builtins/build.rs` also computes this so if // you're changing something here please also change that. cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root); diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index fb001892fe395..f039e89c06eb7 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -22,6 +22,7 @@ use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; use crate::cache::{Interned, INTERNER}; use crate::channel; use crate::compile; +use crate::config::Target; use crate::config::TargetSelection; use crate::doc::DocumentationFormat; use crate::tarball::{GeneratedTarball, OverlayKind, Tarball}; @@ -1890,20 +1891,29 @@ fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) { /// /// Returns whether the files were actually copied. fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool { - if !builder.is_rust_llvm(target) { - // If the LLVM was externally provided, then we don't currently copy - // artifacts into the sysroot. This is not necessarily the right - // choice (in particular, it will require the LLVM dylib to be in - // the linker's load path at runtime), but the common use case for - // external LLVMs is distribution provided LLVMs, and in that case - // they're usually in the standard search path (e.g., /usr/lib) and - // copying them here is going to cause problems as we may end up - // with the wrong files and isn't what distributions want. - // - // This behavior may be revisited in the future though. - // + // If the LLVM was externally provided, then we don't currently copy + // artifacts into the sysroot. This is not necessarily the right + // choice (in particular, it will require the LLVM dylib to be in + // the linker's load path at runtime), but the common use case for + // external LLVMs is distribution provided LLVMs, and in that case + // they're usually in the standard search path (e.g., /usr/lib) and + // copying them here is going to cause problems as we may end up + // with the wrong files and isn't what distributions want. + // + // This behavior may be revisited in the future though. + // + // NOTE: this intentionally doesn't use `is_rust_llvm`; whether this is patched or not doesn't matter, + // we only care if the shared object itself is managed by bootstrap. + let should_install_llvm = match builder.config.target_config.get(&target) { // If the LLVM is coming from ourselves (just from CI) though, we // still want to install it, as it otherwise won't be available. + Some(Target { llvm_config: Some(_), .. }) => { + builder.config.llvm_from_ci && target == builder.config.build + } + Some(Target { llvm_config: None, .. }) | None => true, + }; + + if !should_install_llvm { return false; } diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index f4fa556b97450..693cd7b9c2dba 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -877,18 +877,19 @@ 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. + /// Returns `true` if this is our custom, patched, version of LLVM. /// - /// If no custom `llvm-config` was specified then Rust's llvm will be used. + /// This does not necessarily imply that we're managing the `llvm-project` submodule. fn is_rust_llvm(&self, target: TargetSelection) -> bool { match self.config.target_config.get(&target) { + // We're using a pre-built version of LLVM, but the user has promised that pre-built version has our patches. 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() + // We're using pre-built LLVM and the user hasn't promised the patches match. + // This only has our patches if it's our managed, CI-built LLVM. + Some(Target { llvm_config: Some(_), .. }) => { + self.config.llvm_from_ci && target == self.config.build } - None => true, + Some(Target { llvm_config: None, llvm_has_rust_patches: None, .. }) | None => true, } }