Skip to content

Commit d069a7c

Browse files
authored
Rollup merge of #142357 - Kobzol:simplify-llvm-bitcode-linker, r=jieyouxu
Simplify LLVM bitcode linker in bootstrap and add tests for it This PR tries to simplify the `LlvmBitcodeLinker` step a little bit, and add tests for it. It also adds tests for `LldWrapper`. r? `@jieyouxu`
2 parents 34097a3 + 961bac0 commit d069a7c

File tree

5 files changed

+82
-30
lines changed

5 files changed

+82
-30
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,14 +2057,20 @@ impl Step for Assemble {
20572057
trace!("llvm-bitcode-linker enabled, installing");
20582058
let llvm_bitcode_linker =
20592059
builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker {
2060-
compiler,
2060+
build_compiler: compiler,
20612061
target: target_compiler.host,
2062-
extra_features: vec![],
20632062
});
2063+
2064+
// Copy the llvm-bitcode-linker to the self-contained binary directory
2065+
let bindir_self_contained = builder
2066+
.sysroot(compiler)
2067+
.join(format!("lib/rustlib/{}/bin/self-contained", compiler.host));
20642068
let tool_exe = exe("llvm-bitcode-linker", target_compiler.host);
2069+
2070+
t!(fs::create_dir_all(&bindir_self_contained));
20652071
builder.copy_link(
20662072
&llvm_bitcode_linker.tool_path,
2067-
&libdir_bin.join(tool_exe),
2073+
&bindir_self_contained.join(tool_exe),
20682074
FileType::Executable,
20692075
);
20702076
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ impl Step for LlvmBitcodeLinker {
23752375
builder.ensure(compile::Rustc::new(compiler, target));
23762376

23772377
let llbc_linker =
2378-
builder.ensure(tool::LlvmBitcodeLinker { compiler, target, extra_features: vec![] });
2378+
builder.ensure(tool::LlvmBitcodeLinker { build_compiler: compiler, target });
23792379

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

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,13 @@ impl Step for LldWrapper {
910910

911911
tool_result
912912
}
913+
914+
fn metadata(&self) -> Option<StepMetadata> {
915+
Some(
916+
StepMetadata::build("LldWrapper", self.target_compiler.host)
917+
.built_by(self.build_compiler),
918+
)
919+
}
913920
}
914921

915922
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
@@ -1014,9 +1021,8 @@ impl Step for RustAnalyzerProcMacroSrv {
10141021

10151022
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
10161023
pub struct LlvmBitcodeLinker {
1017-
pub compiler: Compiler,
1024+
pub build_compiler: Compiler,
10181025
pub target: TargetSelection,
1019-
pub extra_features: Vec<String>,
10201026
}
10211027

10221028
impl Step for LlvmBitcodeLinker {
@@ -1032,8 +1038,9 @@ impl Step for LlvmBitcodeLinker {
10321038

10331039
fn make_run(run: RunConfig<'_>) {
10341040
run.builder.ensure(LlvmBitcodeLinker {
1035-
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target),
1036-
extra_features: Vec::new(),
1041+
build_compiler: run
1042+
.builder
1043+
.compiler(run.builder.top_stage, run.builder.config.host_target),
10371044
target: run.target,
10381045
});
10391046
}
@@ -1043,35 +1050,22 @@ impl Step for LlvmBitcodeLinker {
10431050
instrument(level = "debug", name = "LlvmBitcodeLinker::run", skip_all)
10441051
)]
10451052
fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
1046-
let tool_result = builder.ensure(ToolBuild {
1047-
compiler: self.compiler,
1053+
builder.ensure(ToolBuild {
1054+
compiler: self.build_compiler,
10481055
target: self.target,
10491056
tool: "llvm-bitcode-linker",
10501057
mode: Mode::ToolRustc,
10511058
path: "src/tools/llvm-bitcode-linker",
10521059
source_type: SourceType::InTree,
1053-
extra_features: self.extra_features,
1060+
extra_features: vec![],
10541061
allow_features: "",
10551062
cargo_args: Vec::new(),
10561063
artifact_kind: ToolArtifactKind::Binary,
1057-
});
1064+
})
1065+
}
10581066

1059-
if tool_result.target_compiler.stage > 0 {
1060-
let bindir_self_contained = builder
1061-
.sysroot(tool_result.target_compiler)
1062-
.join(format!("lib/rustlib/{}/bin/self-contained", self.target.triple));
1063-
t!(fs::create_dir_all(&bindir_self_contained));
1064-
let bin_destination = bindir_self_contained
1065-
.join(exe("llvm-bitcode-linker", tool_result.target_compiler.host));
1066-
builder.copy_link(&tool_result.tool_path, &bin_destination, FileType::Executable);
1067-
ToolBuildResult {
1068-
tool_path: bin_destination,
1069-
build_compiler: tool_result.build_compiler,
1070-
target_compiler: tool_result.target_compiler,
1071-
}
1072-
} else {
1073-
tool_result
1074-
}
1067+
fn metadata(&self) -> Option<StepMetadata> {
1068+
Some(StepMetadata::build("LlvmBitcodeLinker", self.target).built_by(self.build_compiler))
10751069
}
10761070
}
10771071

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,58 @@ mod snapshot {
757757
");
758758
}
759759

760+
#[test]
761+
fn build_compiler_tools() {
762+
let ctx = TestCtx::new();
763+
insta::assert_snapshot!(
764+
ctx
765+
.config("build")
766+
.stage(2)
767+
.args(&["--set", "rust.lld=true", "--set", "rust.llvm-bitcode-linker=true"])
768+
.render_steps(), @r"
769+
[build] llvm <host>
770+
[build] rustc 0 <host> -> rustc 1 <host>
771+
[build] rustc 0 <host> -> LldWrapper 1 <host>
772+
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
773+
[build] rustc 1 <host> -> std 1 <host>
774+
[build] rustc 1 <host> -> rustc 2 <host>
775+
[build] rustc 1 <host> -> LldWrapper 2 <host>
776+
[build] rustc 2 <host> -> LlvmBitcodeLinker 3 <host>
777+
[build] rustc 2 <host> -> std 2 <host>
778+
[build] rustdoc 1 <host>
779+
"
780+
);
781+
}
782+
783+
#[test]
784+
fn build_compiler_tools_cross() {
785+
let ctx = TestCtx::new();
786+
insta::assert_snapshot!(
787+
ctx
788+
.config("build")
789+
.stage(2)
790+
.args(&["--set", "rust.lld=true", "--set", "rust.llvm-bitcode-linker=true"])
791+
.hosts(&[TEST_TRIPLE_1])
792+
.render_steps(), @r"
793+
[build] llvm <host>
794+
[build] rustc 0 <host> -> rustc 1 <host>
795+
[build] rustc 0 <host> -> LldWrapper 1 <host>
796+
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
797+
[build] rustc 1 <host> -> std 1 <host>
798+
[build] rustc 1 <host> -> rustc 2 <host>
799+
[build] rustc 1 <host> -> LldWrapper 2 <host>
800+
[build] rustc 2 <host> -> LlvmBitcodeLinker 3 <host>
801+
[build] rustc 1 <host> -> std 1 <target1>
802+
[build] rustc 2 <host> -> std 2 <target1>
803+
[build] llvm <target1>
804+
[build] rustc 1 <host> -> rustc 2 <target1>
805+
[build] rustc 1 <host> -> LldWrapper 2 <target1>
806+
[build] rustc 2 <target1> -> LlvmBitcodeLinker 3 <target1>
807+
[build] rustdoc 1 <target1>
808+
"
809+
);
810+
}
811+
760812
#[test]
761813
fn build_library_no_explicit_stage() {
762814
let ctx = TestCtx::new();
@@ -1040,6 +1092,7 @@ mod snapshot {
10401092
[build] rustc 0 <host> -> cargo-clippy 1 <host>
10411093
[build] rustc 0 <host> -> miri 1 <host>
10421094
[build] rustc 0 <host> -> cargo-miri 1 <host>
1095+
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
10431096
");
10441097
}
10451098

@@ -1230,6 +1283,7 @@ mod snapshot {
12301283
[build] rustc 0 <host> -> cargo-clippy 1 <target1>
12311284
[build] rustc 0 <host> -> miri 1 <target1>
12321285
[build] rustc 0 <host> -> cargo-miri 1 <target1>
1286+
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <target1>
12331287
");
12341288
}
12351289

src/bootstrap/src/utils/tests/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ impl ConfigBuilder {
9696
// in-tree LLVM from sources.
9797
self.args.push("--set".to_string());
9898
self.args.push("llvm.download-ci-llvm=false".to_string());
99-
self.args.push("--set".to_string());
100-
self.args.push(format!("target.'{}'.llvm-config=false", get_host_target()));
10199

102100
// Do not mess with the local rustc checkout build directory
103101
self.args.push("--build-dir".to_string());

0 commit comments

Comments
 (0)