Skip to content

Commit b33de79

Browse files
committed
Distinguish "has patches" from "in-tree" again
Fixes rust-lang#102560
1 parent a6a59d2 commit b33de79

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

src/bootstrap/compile.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,17 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
352352
let compiler_builtins_c_feature = if builder.config.optimized_compiler_builtins {
353353
if !builder.is_rust_llvm(target) {
354354
panic!(
355-
"need a managed LLVM submodule for optimized intrinsics support; unset `llvm-config` or `optimized-compiler-builtins`"
355+
"LLVM must have the Rust project's patched sources to support using it for `compiler-builtins`; unset `llvm-config` or `optimized-compiler-builtins`"
356356
);
357357
}
358358

359359
builder.update_submodule(&Path::new("src").join("llvm-project"));
360360
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
361+
if !compiler_builtins_root.exists() {
362+
panic!(
363+
"needed LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true`"
364+
);
365+
}
361366
// Note that `libprofiler_builtins/build.rs` also computes this so if
362367
// you're changing something here please also change that.
363368
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);

src/bootstrap/dist.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2525
use crate::cache::{Interned, INTERNER};
2626
use crate::channel;
2727
use crate::compile;
28+
use crate::config::Target;
2829
use crate::config::TargetSelection;
2930
use crate::doc::DocumentationFormat;
3031
use crate::llvm;
@@ -1964,20 +1965,29 @@ fn install_llvm_file(builder: &Builder<'_>, source: &Path, destination: &Path) {
19641965
///
19651966
/// Returns whether the files were actually copied.
19661967
fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool {
1967-
if !builder.is_rust_llvm(target) {
1968-
// If the LLVM was externally provided, then we don't currently copy
1969-
// artifacts into the sysroot. This is not necessarily the right
1970-
// choice (in particular, it will require the LLVM dylib to be in
1971-
// the linker's load path at runtime), but the common use case for
1972-
// external LLVMs is distribution provided LLVMs, and in that case
1973-
// they're usually in the standard search path (e.g., /usr/lib) and
1974-
// copying them here is going to cause problems as we may end up
1975-
// with the wrong files and isn't what distributions want.
1976-
//
1977-
// This behavior may be revisited in the future though.
1978-
//
1968+
// If the LLVM was externally provided, then we don't currently copy
1969+
// artifacts into the sysroot. This is not necessarily the right
1970+
// choice (in particular, it will require the LLVM dylib to be in
1971+
// the linker's load path at runtime), but the common use case for
1972+
// external LLVMs is distribution provided LLVMs, and in that case
1973+
// they're usually in the standard search path (e.g., /usr/lib) and
1974+
// copying them here is going to cause problems as we may end up
1975+
// with the wrong files and isn't what distributions want.
1976+
//
1977+
// This behavior may be revisited in the future though.
1978+
//
1979+
// NOTE: this intentionally doesn't use `is_rust_llvm`; whether this is patched or not doesn't matter,
1980+
// we only care if the shared object itself is managed by bootstrap.
1981+
let should_install_llvm = match builder.config.target_config.get(&target) {
19791982
// If the LLVM is coming from ourselves (just from CI) though, we
19801983
// still want to install it, as it otherwise won't be available.
1984+
Some(Target { llvm_config: Some(_), .. }) => {
1985+
builder.config.llvm_from_ci && target == builder.config.build
1986+
}
1987+
Some(Target { llvm_config: None, .. }) | None => true,
1988+
};
1989+
1990+
if !should_install_llvm {
19811991
return false;
19821992
}
19831993

src/bootstrap/lib.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -863,18 +863,19 @@ impl Build {
863863
INTERNER.intern_path(self.out.join(&*target.triple).join("md-doc"))
864864
}
865865

866-
/// Returns `true` if no custom `llvm-config` is set for the specified target.
866+
/// Returns `true` if this is our custom, patched, version of LLVM.
867867
///
868-
/// If no custom `llvm-config` was specified then Rust's llvm will be used.
868+
/// This does not necessarily imply that we're managing the `llvm-project` submodule.
869869
fn is_rust_llvm(&self, target: TargetSelection) -> bool {
870870
match self.config.target_config.get(&target) {
871+
// We're using a pre-built version of LLVM, but the user has promised that pre-built version has our patches.
871872
Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
872-
Some(Target { llvm_config, .. }) => {
873-
// If the user set llvm-config we assume Rust is not patched,
874-
// but first check to see if it was configured by llvm-from-ci.
875-
(self.config.llvm_from_ci && target == self.config.build) || llvm_config.is_none()
873+
// We're using pre-built LLVM and the user hasn't promised the patches match.
874+
// This only has our patches if it's our managed, CI-built LLVM.
875+
Some(Target { llvm_config: Some(_), .. }) => {
876+
self.config.llvm_from_ci && target == self.config.build
876877
}
877-
None => true,
878+
Some(Target { llvm_config: None, llvm_has_rust_patches: None, .. }) | None => true,
878879
}
879880
}
880881

0 commit comments

Comments
 (0)