Skip to content

Commit a8b210d

Browse files
committed
address review comments
1 parent 7945458 commit a8b210d

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
@@ -310,17 +310,15 @@ pub fn std_cargo(builder: &Builder<'_>, target: TargetSelection, stage: u32, car
310310
// `compiler-builtins` crate is enabled and it's configured to learn where
311311
// `compiler-rt` is located.
312312
let compiler_builtins_c_feature = if builder.config.optimized_compiler_builtins {
313-
if !builder.is_rust_llvm(target) {
314-
panic!(
315-
"LLVM must have the Rust project's patched sources to support using it for `compiler-builtins`; unset `llvm-config` or `optimized-compiler-builtins`"
316-
);
317-
}
318-
313+
// NOTE: this interacts strangely with `llvm-has-rust-patches`. In that case, we enforce `submodules = false`, so this is a no-op.
314+
// But, the user could still decide to manually use an in-tree submodule.
315+
//
316+
// Using system llvm is not supported.
319317
builder.update_submodule(&Path::new("src").join("llvm-project"));
320318
let compiler_builtins_root = builder.src.join("src/llvm-project/compiler-rt");
321-
if !compiler_builtins_root.exists() {
319+
if !compiler_builtins_root.exists() || builder.is_system_llvm(target) {
322320
panic!(
323-
"needed LLVM sources available to build `compiler-rt`, but they weren't present; consider enabling `build.submodules = true`"
321+
"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`"
324322
);
325323
}
326324
// 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
@@ -1229,7 +1229,10 @@ impl Config {
12291229
target.llvm_config = Some(config.src.join(s));
12301230
}
12311231
if let Some(patches) = cfg.llvm_has_rust_patches {
1232-
assert!(config.submodules.is_some(), "cannot set `llvm-hash-rust-patches` for a managed submodule");
1232+
assert!(
1233+
config.submodules.is_some(),
1234+
"cannot set `llvm-has-rust-patches` for a managed submodule"
1235+
);
12331236
target.llvm_has_rust_patches = Some(patches);
12341237
}
12351238
if let Some(ref s) = cfg.llvm_filecheck {

src/bootstrap/dist.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ 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;
2625
use crate::config::TargetSelection;
2726
use crate::doc::DocumentationFormat;
2827
use crate::tarball::{GeneratedTarball, OverlayKind, Tarball};
@@ -1904,16 +1903,10 @@ fn maybe_install_llvm(builder: &Builder<'_>, target: TargetSelection, dst_libdir
19041903
//
19051904
// NOTE: this intentionally doesn't use `is_rust_llvm`; whether this is patched or not doesn't matter,
19061905
// we only care if the shared object itself is managed by bootstrap.
1907-
let should_install_llvm = match builder.config.target_config.get(&target) {
1908-
// If the LLVM is coming from ourselves (just from CI) though, we
1909-
// 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 {
1906+
//
1907+
// If the LLVM is coming from ourselves (just from CI) though, we
1908+
// still want to install it, as it otherwise won't be available.
1909+
if builder.is_system_llvm(target) {
19171910
return false;
19181911
}
19191912

src/bootstrap/lib.rs

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

880+
/// Returns `true` if this is an external version of LLVM not managed by bootstrap.
881+
/// In particular, we expect llvm sources to be available when this is false.
882+
///
883+
/// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set.
884+
fn is_system_llvm(&self, target: TargetSelection) -> bool {
885+
match self.config.target_config.get(&target) {
886+
Some(Target { llvm_config: Some(_), .. }) => {
887+
!self.config.llvm_from_ci || target != self.config.build
888+
}
889+
Some(Target { llvm_config: None, .. }) | None => false,
890+
}
891+
}
892+
880893
/// Returns `true` if this is our custom, patched, version of LLVM.
881894
///
882895
/// This does not necessarily imply that we're managing the `llvm-project` submodule.
883896
fn is_rust_llvm(&self, target: TargetSelection) -> bool {
884897
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.
898+
// We're using a user-controlled version of LLVM. The user has explicitly told us whether the version has our patches.
899+
// (They might be wrong, but that's not a supported use-case.)
900+
// 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`.
886901
Some(Target { llvm_has_rust_patches: Some(patched), .. }) => *patched,
887902
// We're using pre-built LLVM and the user hasn't promised the patches match.
888903
// 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
@@ -1551,6 +1551,8 @@ note: if you're sure you want to do this, please open an issue as to why. In the
15511551
llvm_components_passed = true;
15521552
}
15531553
if !builder.is_rust_llvm(target) {
1554+
// FIXME: missing Rust patches is not the same as being system llvm; we should rename the flag at some point.
1555+
// Inspecting the tests with `// no-system-llvm` in src/test *looks* like this is doing the right thing, though.
15541556
cmd.arg("--system-llvm");
15551557
}
15561558

0 commit comments

Comments
 (0)