Skip to content

Commit cc3053a

Browse files
authored
Rollup merge of rust-lang#134437 - onur-ozkan:improve-compiler-build, r=jieyouxu
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.
2 parents bd6ed18 + bb1a90f commit cc3053a

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
@@ -1897,12 +1897,6 @@ impl Step for Assemble {
18971897
});
18981898
}
18991899

1900-
let lld_install = if builder.config.lld_enabled {
1901-
Some(builder.ensure(llvm::Lld { target: target_compiler.host }))
1902-
} else {
1903-
None
1904-
};
1905-
19061900
let stage = target_compiler.stage;
19071901
let host = target_compiler.host;
19081902
let (host_info, dir_name) = if build_compiler.host == host {
@@ -1963,22 +1957,11 @@ impl Step for Assemble {
19631957

19641958
copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler);
19651959

1966-
if let Some(lld_install) = lld_install {
1967-
let src_exe = exe("lld", target_compiler.host);
1968-
let dst_exe = exe("rust-lld", target_compiler.host);
1969-
builder.copy_link(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
1970-
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
1971-
t!(fs::create_dir_all(&self_contained_lld_dir));
1972-
let lld_wrapper_exe = builder.ensure(crate::core::build_steps::tool::LldWrapper {
1973-
compiler: build_compiler,
1974-
target: target_compiler.host,
1960+
if builder.config.lld_enabled {
1961+
builder.ensure(crate::core::build_steps::tool::LldWrapper {
1962+
build_compiler,
1963+
target_compiler,
19751964
});
1976-
for name in crate::LLD_FILE_NAMES {
1977-
builder.copy_link(
1978-
&lld_wrapper_exe,
1979-
&self_contained_lld_dir.join(exe(name, target_compiler.host)),
1980-
);
1981-
}
19821965
}
19831966

19841967
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)