Skip to content

Commit 12aa509

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 <work@onurozkan.dev>
1 parent 7caf35b commit 12aa509

File tree

6 files changed

+33
-28
lines changed

6 files changed

+33
-28
lines changed

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

+2-19
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 {
1955+
if builder.config.lld_enabled {
1956+
builder.ensure(crate::core::build_steps::tool::LldWrapper {
19681957
compiler: build_compiler,
19691958
target: target_compiler.host,
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

+27-5
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;
@@ -727,14 +727,18 @@ pub struct LldWrapper {
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 {
736+
fn run(self, builder: &Builder<'_>) {
737+
if builder.config.dry_run() {
738+
return;
739+
}
740+
741+
let executable = builder.ensure(ToolBuild {
738742
compiler: self.compiler,
739743
target: self.target,
740744
tool: "lld-wrapper",
@@ -744,7 +748,25 @@ impl Step for LldWrapper {
744748
extra_features: Vec::new(),
745749
allow_features: "",
746750
cargo_args: Vec::new(),
747-
})
751+
});
752+
753+
let libdir_bin = builder.sysroot_target_bindir(
754+
Compiler { stage: self.compiler.stage + 1, host: self.target },
755+
self.target,
756+
);
757+
t!(fs::create_dir_all(&libdir_bin));
758+
759+
let lld_install = builder.ensure(llvm::Lld { target: self.target });
760+
let src_exe = exe("lld", self.target);
761+
let dst_exe = exe("rust-lld", self.target);
762+
763+
builder.copy_link(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
764+
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
765+
t!(fs::create_dir_all(&self_contained_lld_dir));
766+
767+
for name in crate::LLD_FILE_NAMES {
768+
builder.copy_link(&executable, &self_contained_lld_dir.join(exe(name, self.target)));
769+
}
748770
}
749771
}
750772

src/doc/book

Submodule book updated 203 files

src/tools/cargo

Submodule cargo updated 178 files

0 commit comments

Comments
 (0)