Skip to content

Commit 012d60d

Browse files
committed
address review comments
1 parent e315053 commit 012d60d

File tree

5 files changed

+32
-21
lines changed

5 files changed

+32
-21
lines changed

src/bootstrap/compile.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -350,17 +350,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
350350
// `compiler-builtins` crate is enabled and it's configured to learn where
351351
// `compiler-rt` is located.
352352
let compiler_builtins_c_feature = if builder.config.optimized_compiler_builtins {
353-
if !builder.is_rust_llvm(target) {
354-
panic!(
355-
"LLVM must have the Rust project's patched sources to support using it for `compiler-builtins`; unset `llvm-config` or `optimized-compiler-builtins`"
356-
);
357-
}
358-
353+
// NOTE: this interacts strangely with `llvm-has-rust-patches`. In that case, we enforce `submodules = false`, so this is a no-op.
354+
// But, the user could still decide to manually use an in-tree submodule.
355+
//
356+
// Using system llvm is not supported.
359357
builder.update_submodule(&Path::new("src").join("llvm-project"));
360358
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
361-
if !compiler_builtins_root.exists() {
359+
if !compiler_builtins_root.exists() || builder.is_system_llvm(target) {
362360
panic!(
363-
"needed LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true`"
361+
"needed LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true`, disabling `optimized-compiler-builtins`, or unsetting `llvm-config`"
364362
);
365363
}
366364
// Note that `libprofiler_builtins/build.rs` also computes this so if

src/bootstrap/config.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1515,7 +1515,10 @@ impl Config {
15151515
target.llvm_config = Some(config.src.join(s));
15161516
}
15171517
if let Some(patches) = cfg.llvm_has_rust_patches {
1518-
assert!(config.submodules.is_some(), "cannot set `llvm-hash-rust-patches` for a managed submodule");
1518+
assert!(
1519+
config.submodules.is_some(),
1520+
"cannot set `llvm-has-rust-patches` for a managed submodule"
1521+
);
15191522
target.llvm_has_rust_patches = Some(patches);
15201523
}
15211524
if let Some(ref s) = cfg.llvm_filecheck {

src/bootstrap/dist.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ 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;
2928
use crate::config::TargetSelection;
3029
use crate::doc::DocumentationFormat;
3130
use crate::llvm;
@@ -1978,16 +1977,10 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
19781977
//
19791978
// NOTE: this intentionally doesn't use `is_rust_llvm`; whether this is patched or not doesn't matter,
19801979
// we only care if the shared object itself is managed by bootstrap.
1981-
let should_install_llvm = match builder.config.target_config.get(&target) {
1982-
// If the LLVM is coming from ourselves (just from CI) though, we
1983-
// 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 {
1980+
//
1981+
// If the LLVM is coming from ourselves (just from CI) though, we
1982+
// still want to install it, as it otherwise won't be available.
1983+
if builder.is_system_llvm(target) {
19911984
return false;
19921985
}
19931986

src/bootstrap/lib.rs

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

866+
/// Returns `true` if this is an external version of LLVM not managed by bootstrap.
867+
/// In particular, we expect llvm sources to be available when this is false.
868+
///
869+
/// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
870+
fn is_system_llvm(&self, target: TargetSelection) -> bool {
871+
match self.config.target_config.get(&target) {
872+
Some(Target { llvm_config: Some(_), .. }) => {
873+
!self.config.llvm_from_ci || target != self.config.build
874+
}
875+
Some(Target { llvm_config: None, .. }) | None => false,
876+
}
877+
}
878+
866879
/// Returns `true` if this is our custom, patched, version of LLVM.
867880
///
868881
/// This does not necessarily imply that we're managing the `llvm-project` submodule.
869882
fn is_rust_llvm(&self, target: TargetSelection) -> bool {
870883
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.
884+
// We're using a user-controlled version of LLVM. The user has explicitly told us whether the version has our patches.
885+
// (They might be wrong, but that's not a supported use-case.)
886+
// In particular, this tries to support `submodules = false` and `patches = false`, for using a newer version of LLVM that's not through `rust-lang/llvm-project`.
872887
Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
873888
// We're using pre-built LLVM and the user hasn't promised the patches match.
874889
// This only has our patches if it's our managed, CI-built LLVM.

src/bootstrap/test.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,8 @@ note: if you're sure you want to do this, please open an issue as to why. In the
16931693
llvm_components_passed = true;
16941694
}
16951695
if !builder.is_rust_llvm(target) {
1696+
// FIXME: missing Rust patches is not the same as being system llvm; we should rename the flag at some point.
1697+
// Inspecting the tests with `// no-system-llvm` in src/test *looks* like this is doing the right thing, though.
16961698
cmd.arg("--system-llvm");
16971699
}
16981700

0 commit comments

Comments
 (0)