handle precompiled compiler more properly

Signed-off-by: onur-ozkan <work@onurozkan.dev>
This commit is contained in:
onur-ozkan 2025-03-08 08:14:47 +03:00
parent f5a1ef7121
commit 8042e00291
2 changed files with 19 additions and 15 deletions

View file

@ -1991,12 +1991,12 @@ impl Step for Assemble {
}
}
let maybe_install_llvm_bitcode_linker = || {
let maybe_install_llvm_bitcode_linker = |compiler| {
if builder.config.llvm_bitcode_linker_enabled {
trace!("llvm-bitcode-linker enabled, installing");
let llvm_bitcode_linker =
builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker {
compiler: target_compiler,
compiler,
target: target_compiler.host,
extra_features: vec![],
});
@ -2020,7 +2020,9 @@ impl Step for Assemble {
builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage=target_compiler.stage));
}
maybe_install_llvm_bitcode_linker();
let mut precompiled_compiler = target_compiler;
precompiled_compiler.forced_compiler(true);
maybe_install_llvm_bitcode_linker(precompiled_compiler);
return target_compiler;
}
@ -2203,7 +2205,7 @@ impl Step for Assemble {
);
}
maybe_install_llvm_bitcode_linker();
maybe_install_llvm_bitcode_linker(target_compiler);
// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
// so that it can be found when the newly built `rustc` is run.

View file

@ -319,18 +319,20 @@ pub(crate) fn get_tool_rustc_compiler(
builder: &Builder<'_>,
target_compiler: Compiler,
) -> Compiler {
if builder.download_rustc() && target_compiler.stage == 1 {
// We already have the stage 1 compiler, we don't need to cut the stage.
builder.compiler(target_compiler.stage, builder.config.build)
} else if target_compiler.is_forced_compiler() {
target_compiler
} else {
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
// we'd have stageN/bin/rustc and stageN/bin/$rustc_tool be effectively different stage
// compilers, which isn't what we want. Rustc tools should be linked in the same way as the
// compiler it's paired with, so it must be built with the previous stage compiler.
builder.compiler(target_compiler.stage.saturating_sub(1), builder.config.build)
if target_compiler.is_forced_compiler() {
return target_compiler;
}
if builder.download_rustc() && target_compiler.stage > 0 {
// We already have the stage N compiler, we don't need to cut the stage.
return builder.compiler(target_compiler.stage, builder.config.build);
}
// Similar to `compile::Assemble`, build with the previous stage's compiler. Otherwise
// we'd have stageN/bin/rustc and stageN/bin/$rustc_tool be effectively different stage
// compilers, which isn't what we want. Rustc tools should be linked in the same way as the
// compiler it's paired with, so it must be built with the previous stage compiler.
builder.compiler(target_compiler.stage.saturating_sub(1), builder.config.build)
}
/// Links a built tool binary with the given `name` from the build directory to the