Skip to content

Add ToolTarget to bootstrap #143641

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

Merged
merged 12 commits into from
Jul 19, 2025
25 changes: 13 additions & 12 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2052,19 +2052,20 @@ impl Step for Assemble {
}
}

let maybe_install_llvm_bitcode_linker = |compiler| {
let maybe_install_llvm_bitcode_linker = || {
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 {
build_compiler: compiler,
target: target_compiler.host,
});
let llvm_bitcode_linker = builder.ensure(
crate::core::build_steps::tool::LlvmBitcodeLinker::for_compiler(
builder,
target_compiler,
),
);

// Copy the llvm-bitcode-linker to the self-contained binary directory
let bindir_self_contained = builder
.sysroot(compiler)
.join(format!("lib/rustlib/{}/bin/self-contained", compiler.host));
.sysroot(target_compiler)
.join(format!("lib/rustlib/{}/bin/self-contained", target_compiler.host));
let tool_exe = exe("llvm-bitcode-linker", target_compiler.host);

t!(fs::create_dir_all(&bindir_self_contained));
Expand All @@ -2091,9 +2092,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));
}

let mut precompiled_compiler = target_compiler;
precompiled_compiler.forced_compiler(true);
maybe_install_llvm_bitcode_linker(precompiled_compiler);
// FIXME: this is incomplete, we do not copy a bunch of other stuff to the downloaded
// sysroot...
maybe_install_llvm_bitcode_linker();

return target_compiler;
}
Expand Down Expand Up @@ -2300,7 +2301,7 @@ impl Step for Assemble {
);
}

maybe_install_llvm_bitcode_linker(target_compiler);
maybe_install_llvm_bitcode_linker();

// 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.
Expand Down
18 changes: 7 additions & 11 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,10 @@ impl Step for Extended {
compiler: builder.compiler(stage, target),
backend: "cranelift".to_string(),
});
add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker {compiler, target});
add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker {
target_compiler: compiler,
target
});

let etc = builder.src.join("src/etc/installer");

Expand Down Expand Up @@ -2343,7 +2346,7 @@ impl Step for LlvmTools {

#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
pub struct LlvmBitcodeLinker {
pub compiler: Compiler,
pub target_compiler: Compiler,
pub target: TargetSelection,
}

Expand All @@ -2359,23 +2362,16 @@ impl Step for LlvmBitcodeLinker {

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(LlvmBitcodeLinker {
compiler: run.builder.compiler_for(
run.builder.top_stage,
run.builder.config.host_target,
run.target,
),
target_compiler: run.builder.compiler(run.builder.top_stage, run.target),
target: run.target,
});
}

fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
let compiler = self.compiler;
let target = self.target;

builder.ensure(compile::Rustc::new(compiler, target));

let llbc_linker =
builder.ensure(tool::LlvmBitcodeLinker { build_compiler: compiler, target });
builder.ensure(tool::LlvmBitcodeLinker::for_compiler(builder, self.target_compiler));

let self_contained_bin_dir = format!("lib/rustlib/{}/bin/self-contained", target.triple);

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ install!((self, builder, _config),
}
};
LlvmBitcodeLinker, alias = "llvm-bitcode-linker", Self::should_build(_config), only_hosts: true, {
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { compiler: self.compiler, target: self.target }) {
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { target_compiler: self.compiler, target: self.target }) {
install_sh(builder, "llvm-bitcode-linker", self.compiler.stage, Some(self.target), &tarball);
} else {
builder.info(
Expand Down
26 changes: 20 additions & 6 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1159,8 +1159,21 @@ impl Step for RustAnalyzerProcMacroSrv {

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct LlvmBitcodeLinker {
pub build_compiler: Compiler,
pub target: TargetSelection,
build_compiler: Compiler,
target: TargetSelection,
}

impl LlvmBitcodeLinker {
/// Returns `LlvmBitcodeLinker` that should be **used** by the passed compiler.
pub fn for_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Self {
Self {
build_compiler: get_tool_target_compiler(
builder,
ToolTargetBuildMode::Dist(target_compiler),
),
target: target_compiler.host,
}
}
}

impl Step for LlvmBitcodeLinker {
Expand All @@ -1176,9 +1189,10 @@ impl Step for LlvmBitcodeLinker {

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(LlvmBitcodeLinker {
build_compiler: run
.builder
.compiler(run.builder.top_stage, run.builder.config.host_target),
build_compiler: get_tool_target_compiler(
run.builder,
ToolTargetBuildMode::Build(run.target),
),
target: run.target,
});
}
Expand All @@ -1192,7 +1206,7 @@ impl Step for LlvmBitcodeLinker {
build_compiler: self.build_compiler,
target: self.target,
tool: "llvm-bitcode-linker",
mode: Mode::ToolRustc,
mode: Mode::ToolTarget,
path: "src/tools/llvm-bitcode-linker",
source_type: SourceType::InTree,
extra_features: vec![],
Expand Down
15 changes: 8 additions & 7 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -769,11 +769,11 @@ mod snapshot {
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> LldWrapper 1 <host>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
[build] rustc 0 <host> -> LlvmBitcodeLinker 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 1 <host> -> LldWrapper 2 <host>
[build] rustc 2 <host> -> LlvmBitcodeLinker 3 <host>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
[build] rustc 2 <host> -> std 2 <host>
[build] rustdoc 1 <host>
"
Expand All @@ -793,17 +793,17 @@ mod snapshot {
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> LldWrapper 1 <host>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
[build] rustc 0 <host> -> LlvmBitcodeLinker 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 1 <host> -> LldWrapper 2 <host>
[build] rustc 2 <host> -> LlvmBitcodeLinker 3 <host>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 2 <host> -> std 2 <target1>
[build] llvm <target1>
[build] rustc 1 <host> -> rustc 2 <target1>
[build] rustc 1 <host> -> LldWrapper 2 <target1>
[build] rustc 2 <target1> -> LlvmBitcodeLinker 3 <target1>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <target1>
[build] rustdoc 1 <target1>
"
);
Expand Down Expand Up @@ -1078,12 +1078,12 @@ mod snapshot {
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustc 0 <host> -> LldWrapper 1 <host>
[build] rustc 0 <host> -> WasmComponentLd 1 <host>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
[build] rustc 0 <host> -> LlvmBitcodeLinker 1 <host>
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 1 <host> -> LldWrapper 2 <host>
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
[build] rustc 2 <host> -> LlvmBitcodeLinker 3 <host>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
[build] rustdoc 1 <host>
[doc] std 2 <host>
[build] rustc 2 <host> -> std 2 <host>
Expand Down Expand Up @@ -1293,6 +1293,7 @@ mod snapshot {
[build] rustc 0 <host> -> miri 1 <target1>
[build] rustc 0 <host> -> cargo-miri 1 <target1>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <target1>
[build] rustc 0 <host> -> LlvmBitcodeLinker 1 <host>
");
}

Expand Down
Loading