Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle precompiled compiler more properly #138205

Merged
merged 2 commits into from
Mar 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
@@ -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.
24 changes: 13 additions & 11 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &str, Option<&[&'static str]>)] = &[
pub struct Compiler {
stage: u32,
host: TargetSelection,
/// Indicates whether `compiler_for` was used to force a specific compiler stage.
/// Indicates whether the compiler was forced to use a specific stage.
/// This field is ignored in `Hash` and `PartialEq` implementations as only the `stage`
/// and `host` fields are relevant for those.
forced_compiler: bool,
@@ -1998,7 +1998,7 @@ impl Compiler {
self.stage == 0 && self.host == build.build
}

/// Indicates whether `compiler_for` was used to force a specific compiler stage.
/// Indicates whether the compiler was forced to use a specific stage.
pub fn is_forced_compiler(&self) -> bool {
self.forced_compiler
}