Skip to content

Commit a142760

Browse files
committed
Distinguish "has patches" from "in-tree" again
Fixes #102560
1 parent 9221b81 commit a142760

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
@@ -312,12 +312,17 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
312312
let compiler_builtins_c_feature = if builder.config.optimized_compiler_builtins {
313313
if !builder.is_rust_llvm(target) {
314314
panic!(
315-
"need a managed LLVM submodule for optimized intrinsics support; unset `llvm-config` or `optimized-compiler-builtins`"
315+
"LLVM must have the Rust project's patched sources to support using it for `compiler-builtins`; unset `llvm-config` or `optimized-compiler-builtins`"
316316
);
317317
}
318318

319319
builder.update_submodule(&Path::new("src").join("llvm-project"));
320320
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
321+
if !compiler_builtins_root.exists() {
322+
panic!(
323+
"needed LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true`"
324+
);
325+
}
321326
// Note that `libprofiler_builtins/build.rs` also computes this so if
322327
// you're changing something here please also change that.
323328
cargo.env("RUST_COMPILER_RT_ROOT", &compiler_builtins_root);

src/bootstrap/dist.rs

+22-12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::builder::{Builder, Kind, RunConfig, ShouldRun, Step};
2222
use crate::cache::{Interned, INTERNER};
2323
use crate::channel;
2424
use crate::compile;
25+
use crate::config::Target;
2526
use crate::config::TargetSelection;
2627
use crate::doc::DocumentationFormat;
2728
use crate::tarball::{GeneratedTarball, OverlayKind, Tarball};
@@ -1890,20 +1891,29 @@ fn add_env(builder: &Builder<'_>, cmd: &mut Command, target: TargetSelection) {
18901891
///
18911892
/// Returns whether the files were actually copied.
18921893
fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir: &Path) -> bool {
1893-
if !builder.is_rust_llvm(target) {
1894-
// If the LLVM was externally provided, then we don't currently copy
1895-
// artifacts into the sysroot. This is not necessarily the right
1896-
// choice (in particular, it will require the LLVM dylib to be in
1897-
// the linker's load path at runtime), but the common use case for
1898-
// external LLVMs is distribution provided LLVMs, and in that case
1899-
// they're usually in the standard search path (e.g., /usr/lib) and
1900-
// copying them here is going to cause problems as we may end up
1901-
// with the wrong files and isn't what distributions want.
1902-
//
1903-
// This behavior may be revisited in the future though.
1904-
//
1894+
// If the LLVM was externally provided, then we don't currently copy
1895+
// artifacts into the sysroot. This is not necessarily the right
1896+
// choice (in particular, it will require the LLVM dylib to be in
1897+
// the linker's load path at runtime), but the common use case for
1898+
// external LLVMs is distribution provided LLVMs, and in that case
1899+
// they're usually in the standard search path (e.g., /usr/lib) and
1900+
// copying them here is going to cause problems as we may end up
1901+
// with the wrong files and isn't what distributions want.
1902+
//
1903+
// This behavior may be revisited in the future though.
1904+
//
1905+
// NOTE: this intentionally doesn't use `is_rust_llvm`; whether this is patched or not doesn't matter,
1906+
// we only care if the shared object itself is managed by bootstrap.
1907+
let should_install_llvm = match builder.config.target_config.get(&target) {
19051908
// If the LLVM is coming from ourselves (just from CI) though, we
19061909
// still want to install it, as it otherwise won't be available.
1910+
Some(Target { llvm_config: Some(_), .. }) => {
1911+
builder.config.llvm_from_ci && target == builder.config.build
1912+
}
1913+
Some(Target { llvm_config: None, .. }) | None => true,
1914+
};
1915+
1916+
if !should_install_llvm {
19071917
return false;
19081918
}
19091919

src/bootstrap/lib.rs

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

880-
/// Returns `true` if no custom `llvm-config` is set for the specified target.
880+
/// Returns `true` if this is our custom, patched, version of LLVM.
881881
///
882-
/// If no custom `llvm-config` was specified then Rust's llvm will be used.
882+
/// This does not necessarily imply that we're managing the `llvm-project` submodule.
883883
fn is_rust_llvm(&self, target: TargetSelection) -> bool {
884884
match self.config.target_config.get(&target) {
885+
// We're using a pre-built version of LLVM, but the user has promised that pre-built version has our patches.
885886
Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
886-
Some(Target { llvm_config, .. }) => {
887-
// If the user set llvm-config we assume Rust is not patched,
888-
// but first check to see if it was configured by llvm-from-ci.
889-
(self.config.llvm_from_ci && target == self.config.build) || llvm_config.is_none()
887+
// We're using pre-built LLVM and the user hasn't promised the patches match.
888+
// This only has our patches if it's our managed, CI-built LLVM.
889+
Some(Target { llvm_config: Some(_), .. }) => {
890+
self.config.llvm_from_ci && target == self.config.build
890891
}
891-
None => true,
892+
Some(Target { llvm_config: None, llvm_has_rust_patches: None, .. }) | None => true,
892893
}
893894
}
894895

0 commit comments

Comments
 (0)