Skip to content

Commit f33fa3f

Browse files
authored
Rollup merge of rust-lang#130918 - onur-ozkan:better-llvm-submodule-handling, r=Kobzol
simplify LLVM submodule handling Fixes rust-lang#130906.
2 parents 5e4eab4 + cd1b245 commit f33fa3f

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

src/bootstrap/src/core/build_steps/compile.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1205,7 +1205,8 @@ pub fn rustc_cargo_env(
12051205
// busting caches (e.g. like #71152).
12061206
if builder.config.llvm_enabled(target) {
12071207
let building_is_expensive =
1208-
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target).should_build();
1208+
crate::core::build_steps::llvm::prebuilt_llvm_config(builder, target, false)
1209+
.should_build();
12091210
// `top_stage == stage` might be false for `check --stage 1`, if we are building the stage 1 compiler
12101211
let can_skip_build = builder.kind == Kind::Check && builder.top_stage == stage;
12111212
let should_skip_build = building_is_expensive && can_skip_build;

src/bootstrap/src/core/build_steps/dist.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ fn maybe_install_llvm(
20362036
}
20372037
!builder.config.dry_run()
20382038
} else if let llvm::LlvmBuildStatus::AlreadyBuilt(llvm::LlvmResult { llvm_config, .. }) =
2039-
llvm::prebuilt_llvm_config(builder, target)
2039+
llvm::prebuilt_llvm_config(builder, target, true)
20402040
{
20412041
let mut cmd = command(llvm_config);
20422042
cmd.arg("--libfiles");

src/bootstrap/src/core/build_steps/llvm.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,14 @@ impl LdFlags {
8787
///
8888
/// This will return the llvm-config if it can get it (but it will not build it
8989
/// if not).
90-
pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> LlvmBuildStatus {
91-
// If we have llvm submodule initialized already, sync it.
92-
builder.update_existing_submodule("src/llvm-project");
93-
90+
pub fn prebuilt_llvm_config(
91+
builder: &Builder<'_>,
92+
target: TargetSelection,
93+
// Certain commands (like `x test mir-opt --bless`) may call this function with different targets,
94+
// which could bypass the CI LLVM early-return even if `builder.config.llvm_from_ci` is true.
95+
// This flag should be `true` only if the caller needs the LLVM sources (e.g., if it will build LLVM).
96+
handle_submodule_when_needed: bool,
97+
) -> LlvmBuildStatus {
9498
builder.config.maybe_download_ci_llvm();
9599

96100
// If we're using a custom LLVM bail out here, but we can only use a
@@ -109,9 +113,10 @@ pub fn prebuilt_llvm_config(builder: &Builder<'_>, target: TargetSelection) -> L
109113
}
110114
}
111115

112-
// Initialize the llvm submodule if not initialized already.
113-
// If submodules are disabled, this does nothing.
114-
builder.config.update_submodule("src/llvm-project");
116+
if handle_submodule_when_needed {
117+
// If submodules are disabled, this does nothing.
118+
builder.config.update_submodule("src/llvm-project");
119+
}
115120

116121
let root = "src/llvm-project/llvm";
117122
let out_dir = builder.llvm_out(target);
@@ -284,7 +289,7 @@ impl Step for Llvm {
284289
};
285290

286291
// If LLVM has already been built or been downloaded through download-ci-llvm, we avoid building it again.
287-
let Meta { stamp, res, out_dir, root } = match prebuilt_llvm_config(builder, target) {
292+
let Meta { stamp, res, out_dir, root } = match prebuilt_llvm_config(builder, target, true) {
288293
LlvmBuildStatus::AlreadyBuilt(p) => return p,
289294
LlvmBuildStatus::ShouldBuild(m) => m,
290295
};

src/bootstrap/src/core/builder.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,9 @@ impl<'a> Builder<'a> {
15371537
// rustc_llvm. But if LLVM is stale, that'll be a tiny amount
15381538
// of work comparatively, and we'd likely need to rebuild it anyway,
15391539
// so that's okay.
1540-
if crate::core::build_steps::llvm::prebuilt_llvm_config(self, target).should_build() {
1540+
if crate::core::build_steps::llvm::prebuilt_llvm_config(self, target, false)
1541+
.should_build()
1542+
{
15411543
cargo.env("RUST_CHECK", "1");
15421544
}
15431545
}

0 commit comments

Comments
 (0)