Skip to content

Commit f16016a

Browse files
committed
Fix compiler for dist LLVM bitcode linker
1 parent 4f1b3e3 commit f16016a

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ impl Step for Assemble {
20562056
if builder.config.llvm_bitcode_linker_enabled {
20572057
trace!("llvm-bitcode-linker enabled, installing");
20582058
let llvm_bitcode_linker = builder.ensure(
2059-
crate::core::build_steps::tool::LlvmBitcodeLinker::for_use_by_compiler(
2059+
crate::core::build_steps::tool::LlvmBitcodeLinker::from_target_compiler(
20602060
builder,
20612061
target_compiler,
20622062
),

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,7 +1576,7 @@ impl Step for Extended {
15761576
backend: "cranelift".to_string(),
15771577
});
15781578
add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker {
1579-
target_compiler: compiler,
1579+
build_compiler: compiler,
15801580
target
15811581
});
15821582

@@ -2344,9 +2344,13 @@ impl Step for LlvmTools {
23442344
}
23452345
}
23462346

2347+
/// Distributes the `llvm-bitcode-linker` tool so that it can be used by a compiler whose host
2348+
/// is `target`.
23472349
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
23482350
pub struct LlvmBitcodeLinker {
2349-
pub target_compiler: Compiler,
2351+
/// The linker will be compiled by this compiler.
2352+
pub build_compiler: Compiler,
2353+
/// The linker will by usable by rustc on this host.
23502354
pub target: TargetSelection,
23512355
}
23522356

@@ -2362,7 +2366,10 @@ impl Step for LlvmBitcodeLinker {
23622366

23632367
fn make_run(run: RunConfig<'_>) {
23642368
run.builder.ensure(LlvmBitcodeLinker {
2365-
target_compiler: run.builder.compiler(run.builder.top_stage, run.target),
2369+
build_compiler: tool::LlvmBitcodeLinker::get_build_compiler_for_target(
2370+
run.builder,
2371+
run.target,
2372+
),
23662373
target: run.target,
23672374
});
23682375
}
@@ -2371,7 +2378,7 @@ impl Step for LlvmBitcodeLinker {
23712378
let target = self.target;
23722379

23732380
let llbc_linker = builder
2374-
.ensure(tool::LlvmBitcodeLinker::for_use_by_compiler(builder, self.target_compiler));
2381+
.ensure(tool::LlvmBitcodeLinker::from_build_compiler(self.build_compiler, target));
23752382

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

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 { target_compiler: self.compiler, target: self.target }) {
290+
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { build_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: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,8 +1171,14 @@ pub struct LlvmBitcodeLinker {
11711171
}
11721172

11731173
impl LlvmBitcodeLinker {
1174+
/// Returns `LlvmBitcodeLinker` that will be **compiled** by the passed compiler, for the given
1175+
/// `target`.
1176+
pub fn from_build_compiler(build_compiler: Compiler, target: TargetSelection) -> Self {
1177+
Self { build_compiler, target }
1178+
}
1179+
11741180
/// Returns `LlvmBitcodeLinker` that should be **used** by the passed compiler.
1175-
pub fn for_use_by_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Self {
1181+
pub fn from_target_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Self {
11761182
Self {
11771183
build_compiler: get_tool_target_compiler(
11781184
builder,
@@ -1181,6 +1187,14 @@ impl LlvmBitcodeLinker {
11811187
target: target_compiler.host,
11821188
}
11831189
}
1190+
1191+
/// Return a compiler that is able to build this tool for the given `target`.
1192+
pub fn get_build_compiler_for_target(
1193+
builder: &Builder<'_>,
1194+
target: TargetSelection,
1195+
) -> Compiler {
1196+
get_tool_target_compiler(builder, ToolTargetBuildMode::Build(target))
1197+
}
11841198
}
11851199

11861200
impl Step for LlvmBitcodeLinker {
@@ -1196,10 +1210,7 @@ impl Step for LlvmBitcodeLinker {
11961210

11971211
fn make_run(run: RunConfig<'_>) {
11981212
run.builder.ensure(LlvmBitcodeLinker {
1199-
build_compiler: get_tool_target_compiler(
1200-
run.builder,
1201-
ToolTargetBuildMode::Build(run.target),
1202-
),
1213+
build_compiler: Self::get_build_compiler_for_target(run.builder, run.target),
12031214
target: run.target,
12041215
});
12051216
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,6 @@ 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>
12971296
");
12981297
}
12991298

0 commit comments

Comments
 (0)