Skip to content

Commit 8042e00

Browse files
committedMar 8, 2025·
handle precompiled compiler more properly
Signed-off-by: onur-ozkan <work@onurozkan.dev>
1 parent f5a1ef7 commit 8042e00

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed
 

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

+6-4
Original file line numberDiff line numberDiff line change
@@ -1991,12 +1991,12 @@ impl Step for Assemble {
19911991
}
19921992
}
19931993

1994-
let maybe_install_llvm_bitcode_linker = || {
1994+
let maybe_install_llvm_bitcode_linker = |compiler| {
19951995
if builder.config.llvm_bitcode_linker_enabled {
19961996
trace!("llvm-bitcode-linker enabled, installing");
19971997
let llvm_bitcode_linker =
19981998
builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker {
1999-
compiler: target_compiler,
1999+
compiler,
20002000
target: target_compiler.host,
20012001
extra_features: vec![],
20022002
});
@@ -2020,7 +2020,9 @@ impl Step for Assemble {
20202020
builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage=target_compiler.stage));
20212021
}
20222022

2023-
maybe_install_llvm_bitcode_linker();
2023+
let mut precompiled_compiler = target_compiler;
2024+
precompiled_compiler.forced_compiler(true);
2025+
maybe_install_llvm_bitcode_linker(precompiled_compiler);
20242026

20252027
return target_compiler;
20262028
}
@@ -2203,7 +2205,7 @@ impl Step for Assemble {
22032205
);
22042206
}
22052207

2206-
maybe_install_llvm_bitcode_linker();
2208+
maybe_install_llvm_bitcode_linker(target_compiler);
22072209

22082210
// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
22092211
// so that it can be found when the newly built `rustc` is run.

‎src/bootstrap/src/core/build_steps/tool.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -319,18 +319,20 @@ pub(crate) fn get_tool_rustc_compiler(
319319
builder: &Builder<'_>,
320320
target_compiler: Compiler,
321321
) -> Compiler {
322-
if builder.download_rustc() && target_compiler.stage == 1 {
323-
// We already have the stage 1 compiler, we don't need to cut the stage.
324-
builder.compiler(target_compiler.stage, builder.config.build)
325-
} else if target_compiler.is_forced_compiler() {
326-
target_compiler
327-
} else {
328-
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
329-
// we'd have stageN/bin/rustc and stageN/bin/$rustc_tool be effectively different stage
330-
// compilers, which isn't what we want. Rustc tools should be linked in the same way as the
331-
// compiler it's paired with, so it must be built with the previous stage compiler.
332-
builder.compiler(target_compiler.stage.saturating_sub(1), builder.config.build)
322+
if target_compiler.is_forced_compiler() {
323+
return target_compiler;
324+
}
325+
326+
if builder.download_rustc() && target_compiler.stage > 0 {
327+
// We already have the stage N compiler, we don't need to cut the stage.
328+
return builder.compiler(target_compiler.stage, builder.config.build);
333329
}
330+
331+
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
332+
// we'd have stageN/bin/rustc and stageN/bin/$rustc_tool be effectively different stage
333+
// compilers, which isn't what we want. Rustc tools should be linked in the same way as the
334+
// compiler it's paired with, so it must be built with the previous stage compiler.
335+
builder.compiler(target_compiler.stage.saturating_sub(1), builder.config.build)
334336
}
335337

336338
/// Links a built tool binary with the given `name` from the build directory to the

0 commit comments

Comments
 (0)
Please sign in to comment.