Skip to content

Commit c571b97

Browse files
committed
Make LldWrapper a ToolTarget tool
1 parent 89370e0 commit c571b97

File tree

3 files changed

+78
-50
lines changed

3 files changed

+78
-50
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use serde_derive::Deserialize;
1919
use tracing::{instrument, span};
2020

2121
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
22-
use crate::core::build_steps::tool::SourceType;
22+
use crate::core::build_steps::tool::{SourceType, copy_lld_artifacts};
2323
use crate::core::build_steps::{dist, llvm};
2424
use crate::core::builder;
2525
use crate::core::builder::{
@@ -2258,10 +2258,10 @@ impl Step for Assemble {
22582258
copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler);
22592259

22602260
if builder.config.lld_enabled {
2261-
builder.ensure(crate::core::build_steps::tool::LldWrapper {
2262-
build_compiler,
2263-
target_compiler,
2264-
});
2261+
let lld_wrapper = builder.ensure(
2262+
crate::core::build_steps::tool::LldWrapper::for_compiler(builder, target_compiler),
2263+
);
2264+
copy_lld_artifacts(builder, lld_wrapper, target_compiler);
22652265
}
22662266

22672267
if builder.config.llvm_enabled(target_compiler.host) && builder.config.llvm_tools_enabled {

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

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -881,17 +881,50 @@ impl Step for Cargo {
881881
}
882882
}
883883

884+
/// Represents a built LldWrapper, the `lld-wrapper` tool itself, and a directory
885+
/// containing a build of LLD.
886+
#[derive(Clone)]
887+
pub struct BuiltLldWrapper {
888+
tool: ToolBuildResult,
889+
lld_dir: PathBuf,
890+
}
891+
884892
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
885893
pub struct LldWrapper {
886894
pub build_compiler: Compiler,
887-
pub target_compiler: Compiler,
895+
pub target: TargetSelection,
896+
}
897+
898+
impl LldWrapper {
899+
/// Returns `LldWrapper` that should be **used** by the passed compiler.
900+
pub fn for_compiler(builder: &Builder<'_>, target_compiler: Compiler) -> Self {
901+
Self {
902+
build_compiler: get_tool_target_compiler(
903+
builder,
904+
ToolTargetBuildMode::Dist(target_compiler),
905+
),
906+
target: target_compiler.host,
907+
}
908+
}
888909
}
889910

890911
impl Step for LldWrapper {
891-
type Output = ToolBuildResult;
912+
type Output = BuiltLldWrapper;
913+
914+
const ONLY_HOSTS: bool = true;
892915

893916
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
894-
run.never()
917+
run.path("src/tools/lld-wrapper")
918+
}
919+
920+
fn make_run(run: RunConfig<'_>) {
921+
run.builder.ensure(LldWrapper {
922+
build_compiler: get_tool_target_compiler(
923+
run.builder,
924+
ToolTargetBuildMode::Build(run.target),
925+
),
926+
target: run.target,
927+
});
895928
}
896929

897930
#[cfg_attr(
@@ -900,64 +933,58 @@ impl Step for LldWrapper {
900933
level = "debug",
901934
name = "LldWrapper::run",
902935
skip_all,
903-
fields(build_compiler = ?self.build_compiler, target_compiler = ?self.target_compiler),
936+
fields(build_compiler = ?self.build_compiler),
904937
),
905938
)]
906-
fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
907-
if builder.config.dry_run() {
908-
return ToolBuildResult {
909-
tool_path: Default::default(),
910-
build_compiler: self.build_compiler,
911-
target_compiler: self.target_compiler,
912-
};
913-
}
914-
915-
let target = self.target_compiler.host;
916-
917-
let tool_result = builder.ensure(ToolBuild {
939+
fn run(self, builder: &Builder<'_>) -> Self::Output {
940+
let lld_dir = builder.ensure(llvm::Lld { target: self.target });
941+
let tool = builder.ensure(ToolBuild {
918942
build_compiler: self.build_compiler,
919-
target,
943+
target: self.target,
920944
tool: "lld-wrapper",
921-
mode: Mode::ToolStd,
945+
mode: Mode::ToolTarget,
922946
path: "src/tools/lld-wrapper",
923947
source_type: SourceType::InTree,
924948
extra_features: Vec::new(),
925949
allow_features: "",
926950
cargo_args: Vec::new(),
927951
artifact_kind: ToolArtifactKind::Binary,
928952
});
953+
BuiltLldWrapper { tool, lld_dir }
954+
}
955+
956+
fn metadata(&self) -> Option<StepMetadata> {
957+
Some(StepMetadata::build("LldWrapper", self.target).built_by(self.build_compiler))
958+
}
959+
}
960+
961+
pub(crate) fn copy_lld_artifacts(
962+
builder: &Builder<'_>,
963+
lld_wrapper: BuiltLldWrapper,
964+
target_compiler: Compiler,
965+
) {
966+
let target = target_compiler.host;
967+
968+
let libdir_bin = builder.sysroot_target_bindir(target_compiler, target);
969+
t!(fs::create_dir_all(&libdir_bin));
929970

930-
let libdir_bin = builder.sysroot_target_bindir(self.target_compiler, target);
931-
t!(fs::create_dir_all(&libdir_bin));
971+
let src_exe = exe("lld", target);
972+
let dst_exe = exe("rust-lld", target);
932973

933-
let lld_install = builder.ensure(llvm::Lld { target });
934-
let src_exe = exe("lld", target);
935-
let dst_exe = exe("rust-lld", target);
974+
builder.copy_link(
975+
&lld_wrapper.lld_dir.join("bin").join(src_exe),
976+
&libdir_bin.join(dst_exe),
977+
FileType::Executable,
978+
);
979+
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
980+
t!(fs::create_dir_all(&self_contained_lld_dir));
936981

982+
for name in crate::LLD_FILE_NAMES {
937983
builder.copy_link(
938-
&lld_install.join("bin").join(src_exe),
939-
&libdir_bin.join(dst_exe),
984+
&lld_wrapper.tool.tool_path,
985+
&self_contained_lld_dir.join(exe(name, target)),
940986
FileType::Executable,
941987
);
942-
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
943-
t!(fs::create_dir_all(&self_contained_lld_dir));
944-
945-
for name in crate::LLD_FILE_NAMES {
946-
builder.copy_link(
947-
&tool_result.tool_path,
948-
&self_contained_lld_dir.join(exe(name, target)),
949-
FileType::Executable,
950-
);
951-
}
952-
953-
tool_result
954-
}
955-
956-
fn metadata(&self) -> Option<StepMetadata> {
957-
Some(
958-
StepMetadata::build("LldWrapper", self.target_compiler.host)
959-
.built_by(self.build_compiler),
960-
)
961988
}
962989
}
963990

src/bootstrap/src/core/builder/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,8 @@ impl<'a> Builder<'a> {
981981
tool::CoverageDump,
982982
tool::LlvmBitcodeLinker,
983983
tool::RustcPerf,
984-
tool::WasmComponentLd
984+
tool::WasmComponentLd,
985+
tool::LldWrapper
985986
),
986987
Kind::Clippy => describe!(
987988
clippy::Std,

0 commit comments

Comments
 (0)