Skip to content

Commit c2fdea5

Browse files
committed
Make LlvmBitcodeLinker a ToolTarget tool
1 parent 5862b01 commit c2fdea5

File tree

5 files changed

+49
-37
lines changed

5 files changed

+49
-37
lines changed

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,19 +2054,20 @@ impl Step for Assemble {
20542054
}
20552055
}
20562056

2057-
let maybe_install_llvm_bitcode_linker = |compiler| {
2057+
let maybe_install_llvm_bitcode_linker = || {
20582058
if builder.config.llvm_bitcode_linker_enabled {
20592059
trace!("llvm-bitcode-linker enabled, installing");
2060-
let llvm_bitcode_linker =
2061-
builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker {
2062-
build_compiler: compiler,
2063-
target: target_compiler.host,
2064-
});
2060+
let llvm_bitcode_linker = builder.ensure(
2061+
crate::core::build_steps::tool::LlvmBitcodeLinker::for_compiler(
2062+
builder,
2063+
target_compiler,
2064+
),
2065+
);
20652066

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

20722073
t!(fs::create_dir_all(&bindir_self_contained));
@@ -2093,9 +2094,9 @@ impl Step for Assemble {
20932094
builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage = target_compiler.stage));
20942095
}
20952096

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

21002101
return target_compiler;
21012102
}
@@ -2302,7 +2303,7 @@ impl Step for Assemble {
23022303
);
23032304
}
23042305

2305-
maybe_install_llvm_bitcode_linker(target_compiler);
2306+
maybe_install_llvm_bitcode_linker();
23062307

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

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,10 @@ impl Step for Extended {
15751575
compiler: builder.compiler(stage, target),
15761576
backend: "cranelift".to_string(),
15771577
});
1578-
add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker {compiler, target});
1578+
add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker {
1579+
target_compiler: compiler,
1580+
target
1581+
});
15791582

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

@@ -2343,7 +2346,7 @@ impl Step for LlvmTools {
23432346

23442347
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
23452348
pub struct LlvmBitcodeLinker {
2346-
pub compiler: Compiler,
2349+
pub target_compiler: Compiler,
23472350
pub target: TargetSelection,
23482351
}
23492352

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

23602363
fn make_run(run: RunConfig<'_>) {
23612364
run.builder.ensure(LlvmBitcodeLinker {
2362-
compiler: run.builder.compiler_for(
2363-
run.builder.top_stage,
2364-
run.builder.config.host_target,
2365-
run.target,
2366-
),
2365+
target_compiler: run.builder.compiler(run.builder.top_stage, run.target),
23672366
target: run.target,
23682367
});
23692368
}
23702369

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

2375-
builder.ensure(compile::Rustc::new(compiler, target));
2376-
23772373
let llbc_linker =
2378-
builder.ensure(tool::LlvmBitcodeLinker { build_compiler: compiler, target });
2374+
builder.ensure(tool::LlvmBitcodeLinker::for_compiler(builder, self.target_compiler));
23792375

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

src/bootstrap/src/core/build_steps/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ install!((self, builder, _config),
287287
}
288288
};
289289
LlvmBitcodeLinker, alias = "llvm-bitcode-linker", Self::should_build(_config), only_hosts: true, {
290-
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { compiler: self.compiler, target: self.target }) {
290+
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { target_compiler: self.compiler, target: self.target }) {
291291
install_sh(builder, "llvm-bitcode-linker", self.compiler.stage, Some(self.target), &tarball);
292292
} else {
293293
builder.info(

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,21 @@ impl Step for RustAnalyzerProcMacroSrv {
11591159

11601160
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
11611161
pub struct LlvmBitcodeLinker {
1162-
pub build_compiler: Compiler,
1163-
pub target: TargetSelection,
1162+
build_compiler: Compiler,
1163+
target: TargetSelection,
1164+
}
1165+
1166+
impl LlvmBitcodeLinker {
1167+
/// Returns `LlvmBitcodeLinker` that should be **used** by the passed compiler.
1168+
pub fn for_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Self {
1169+
Self {
1170+
build_compiler: get_tool_target_compiler(
1171+
builder,
1172+
ToolTargetBuildMode::Dist(target_compiler),
1173+
),
1174+
target: target_compiler.host,
1175+
}
1176+
}
11641177
}
11651178

11661179
impl Step for LlvmBitcodeLinker {
@@ -1176,9 +1189,10 @@ impl Step for LlvmBitcodeLinker {
11761189

11771190
fn make_run(run: RunConfig<'_>) {
11781191
run.builder.ensure(LlvmBitcodeLinker {
1179-
build_compiler: run
1180-
.builder
1181-
.compiler(run.builder.top_stage, run.builder.config.host_target),
1192+
build_compiler: get_tool_target_compiler(
1193+
run.builder,
1194+
ToolTargetBuildMode::Build(run.target),
1195+
),
11821196
target: run.target,
11831197
});
11841198
}
@@ -1192,7 +1206,7 @@ impl Step for LlvmBitcodeLinker {
11921206
build_compiler: self.build_compiler,
11931207
target: self.target,
11941208
tool: "llvm-bitcode-linker",
1195-
mode: Mode::ToolRustc,
1209+
mode: Mode::ToolTarget,
11961210
path: "src/tools/llvm-bitcode-linker",
11971211
source_type: SourceType::InTree,
11981212
extra_features: vec![],

src/bootstrap/src/core/builder/tests.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -769,11 +769,11 @@ mod snapshot {
769769
[build] llvm <host>
770770
[build] rustc 0 <host> -> rustc 1 <host>
771771
[build] rustc 0 <host> -> LldWrapper 1 <host>
772-
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
772+
[build] rustc 0 <host> -> LlvmBitcodeLinker 1 <host>
773773
[build] rustc 1 <host> -> std 1 <host>
774774
[build] rustc 1 <host> -> rustc 2 <host>
775775
[build] rustc 1 <host> -> LldWrapper 2 <host>
776-
[build] rustc 2 <host> -> LlvmBitcodeLinker 3 <host>
776+
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
777777
[build] rustc 2 <host> -> std 2 <host>
778778
[build] rustdoc 1 <host>
779779
"
@@ -793,17 +793,17 @@ mod snapshot {
793793
[build] llvm <host>
794794
[build] rustc 0 <host> -> rustc 1 <host>
795795
[build] rustc 0 <host> -> LldWrapper 1 <host>
796-
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
796+
[build] rustc 0 <host> -> LlvmBitcodeLinker 1 <host>
797797
[build] rustc 1 <host> -> std 1 <host>
798798
[build] rustc 1 <host> -> rustc 2 <host>
799799
[build] rustc 1 <host> -> LldWrapper 2 <host>
800-
[build] rustc 2 <host> -> LlvmBitcodeLinker 3 <host>
800+
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
801801
[build] rustc 1 <host> -> std 1 <target1>
802802
[build] rustc 2 <host> -> std 2 <target1>
803803
[build] llvm <target1>
804804
[build] rustc 1 <host> -> rustc 2 <target1>
805805
[build] rustc 1 <host> -> LldWrapper 2 <target1>
806-
[build] rustc 2 <target1> -> LlvmBitcodeLinker 3 <target1>
806+
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <target1>
807807
[build] rustdoc 1 <target1>
808808
"
809809
);
@@ -1078,12 +1078,12 @@ mod snapshot {
10781078
[build] rustc 0 <host> -> rustc 1 <host>
10791079
[build] rustc 0 <host> -> LldWrapper 1 <host>
10801080
[build] rustc 0 <host> -> WasmComponentLd 1 <host>
1081-
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
1081+
[build] rustc 0 <host> -> LlvmBitcodeLinker 1 <host>
10821082
[build] rustc 1 <host> -> std 1 <host>
10831083
[build] rustc 1 <host> -> rustc 2 <host>
10841084
[build] rustc 1 <host> -> LldWrapper 2 <host>
10851085
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
1086-
[build] rustc 2 <host> -> LlvmBitcodeLinker 3 <host>
1086+
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
10871087
[build] rustdoc 1 <host>
10881088
[doc] std 2 <host>
10891089
[build] rustc 2 <host> -> std 2 <host>
@@ -1293,6 +1293,7 @@ mod snapshot {
12931293
[build] rustc 0 <host> -> miri 1 <target1>
12941294
[build] rustc 0 <host> -> cargo-miri 1 <target1>
12951295
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <target1>
1296+
[build] rustc 0 <host> -> LlvmBitcodeLinker 1 <host>
12961297
");
12971298
}
12981299

0 commit comments

Comments
 (0)