Skip to content

Commit bb1a90f

Browse files
committed
reduce compiler Assemble complexity
`compile::Assemble` is already complicated by its nature (as it handles core internals like recursive building logic, etc.) and also handles half of `LldWrapper` tool logic for no good reason since it should be done in the build step directly. This change moves it there to reduce complexity of `compile::Assemble` logic. Signed-off-by: onur-ozkan <[email protected]>
1 parent 7caf35b commit bb1a90f

File tree

2 files changed

+34
-30
lines changed

2 files changed

+34
-30
lines changed

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

+4-21
Original file line numberDiff line numberDiff line change
@@ -1892,12 +1892,6 @@ impl Step for Assemble {
18921892
});
18931893
}
18941894

1895-
let lld_install = if builder.config.lld_enabled {
1896-
Some(builder.ensure(llvm::Lld { target: target_compiler.host }))
1897-
} else {
1898-
None
1899-
};
1900-
19011895
let stage = target_compiler.stage;
19021896
let host = target_compiler.host;
19031897
let (host_info, dir_name) = if build_compiler.host == host {
@@ -1958,22 +1952,11 @@ impl Step for Assemble {
19581952

19591953
copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler);
19601954

1961-
if let Some(lld_install) = lld_install {
1962-
let src_exe = exe("lld", target_compiler.host);
1963-
let dst_exe = exe("rust-lld", target_compiler.host);
1964-
builder.copy_link(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
1965-
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
1966-
t!(fs::create_dir_all(&self_contained_lld_dir));
1967-
let lld_wrapper_exe = builder.ensure(crate::core::build_steps::tool::LldWrapper {
1968-
compiler: build_compiler,
1969-
target: target_compiler.host,
1955+
if builder.config.lld_enabled {
1956+
builder.ensure(crate::core::build_steps::tool::LldWrapper {
1957+
build_compiler,
1958+
target_compiler,
19701959
});
1971-
for name in crate::LLD_FILE_NAMES {
1972-
builder.copy_link(
1973-
&lld_wrapper_exe,
1974-
&self_contained_lld_dir.join(exe(name, target_compiler.host)),
1975-
);
1976-
}
19771960
}
19781961

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

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

+30-9
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use std::path::PathBuf;
22
use std::{env, fs};
33

4-
use crate::core::build_steps::compile;
54
use crate::core::build_steps::toolstate::ToolState;
5+
use crate::core::build_steps::{compile, llvm};
66
use crate::core::builder;
77
use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
88
use crate::core::config::TargetSelection;
@@ -722,29 +722,50 @@ impl Step for Cargo {
722722

723723
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
724724
pub struct LldWrapper {
725-
pub compiler: Compiler,
726-
pub target: TargetSelection,
725+
pub build_compiler: Compiler,
726+
pub target_compiler: Compiler,
727727
}
728728

729729
impl Step for LldWrapper {
730-
type Output = PathBuf;
730+
type Output = ();
731731

732732
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
733733
run.never()
734734
}
735735

736-
fn run(self, builder: &Builder<'_>) -> PathBuf {
737-
builder.ensure(ToolBuild {
738-
compiler: self.compiler,
739-
target: self.target,
736+
fn run(self, builder: &Builder<'_>) {
737+
if builder.config.dry_run() {
738+
return;
739+
}
740+
741+
let target = self.target_compiler.host;
742+
743+
let executable = builder.ensure(ToolBuild {
744+
compiler: self.build_compiler,
745+
target,
740746
tool: "lld-wrapper",
741747
mode: Mode::ToolStd,
742748
path: "src/tools/lld-wrapper",
743749
source_type: SourceType::InTree,
744750
extra_features: Vec::new(),
745751
allow_features: "",
746752
cargo_args: Vec::new(),
747-
})
753+
});
754+
755+
let libdir_bin = builder.sysroot_target_bindir(self.target_compiler, target);
756+
t!(fs::create_dir_all(&libdir_bin));
757+
758+
let lld_install = builder.ensure(llvm::Lld { target });
759+
let src_exe = exe("lld", target);
760+
let dst_exe = exe("rust-lld", target);
761+
762+
builder.copy_link(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
763+
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
764+
t!(fs::create_dir_all(&self_contained_lld_dir));
765+
766+
for name in crate::LLD_FILE_NAMES {
767+
builder.copy_link(&executable, &self_contained_lld_dir.join(exe(name, target)));
768+
}
748769
}
749770
}
750771

0 commit comments

Comments
 (0)