Skip to content

Commit

Permalink
Unrolled build for rust-lang#134437
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rust-timer authored Dec 19, 2024
2 parents a4079b2 + bb1a90f commit 3b8c1dd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
25 changes: 4 additions & 21 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,12 +1897,6 @@ impl Step for Assemble {
});
}

let lld_install = if builder.config.lld_enabled {
Some(builder.ensure(llvm::Lld { target: target_compiler.host }))
} else {
None
};

let stage = target_compiler.stage;
let host = target_compiler.host;
let (host_info, dir_name) = if build_compiler.host == host {
Expand Down Expand Up @@ -1963,22 +1957,11 @@ impl Step for Assemble {

copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler);

if let Some(lld_install) = lld_install {
let src_exe = exe("lld", target_compiler.host);
let dst_exe = exe("rust-lld", target_compiler.host);
builder.copy_link(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
t!(fs::create_dir_all(&self_contained_lld_dir));
let lld_wrapper_exe = builder.ensure(crate::core::build_steps::tool::LldWrapper {
compiler: build_compiler,
target: target_compiler.host,
if builder.config.lld_enabled {
builder.ensure(crate::core::build_steps::tool::LldWrapper {
build_compiler,
target_compiler,
});
for name in crate::LLD_FILE_NAMES {
builder.copy_link(
&lld_wrapper_exe,
&self_contained_lld_dir.join(exe(name, target_compiler.host)),
);
}
}

if builder.config.llvm_enabled(target_compiler.host) && builder.config.llvm_tools_enabled {
Expand Down
39 changes: 30 additions & 9 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::PathBuf;
use std::{env, fs};

use crate::core::build_steps::compile;
use crate::core::build_steps::toolstate::ToolState;
use crate::core::build_steps::{compile, llvm};
use crate::core::builder;
use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
use crate::core::config::TargetSelection;
Expand Down Expand Up @@ -722,29 +722,50 @@ impl Step for Cargo {

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct LldWrapper {
pub compiler: Compiler,
pub target: TargetSelection,
pub build_compiler: Compiler,
pub target_compiler: Compiler,
}

impl Step for LldWrapper {
type Output = PathBuf;
type Output = ();

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

fn run(self, builder: &Builder<'_>) -> PathBuf {
builder.ensure(ToolBuild {
compiler: self.compiler,
target: self.target,
fn run(self, builder: &Builder<'_>) {
if builder.config.dry_run() {
return;
}

let target = self.target_compiler.host;

let executable = builder.ensure(ToolBuild {
compiler: self.build_compiler,
target,
tool: "lld-wrapper",
mode: Mode::ToolStd,
path: "src/tools/lld-wrapper",
source_type: SourceType::InTree,
extra_features: Vec::new(),
allow_features: "",
cargo_args: Vec::new(),
})
});

let libdir_bin = builder.sysroot_target_bindir(self.target_compiler, target);
t!(fs::create_dir_all(&libdir_bin));

let lld_install = builder.ensure(llvm::Lld { target });
let src_exe = exe("lld", target);
let dst_exe = exe("rust-lld", target);

builder.copy_link(&lld_install.join("bin").join(src_exe), &libdir_bin.join(dst_exe));
let self_contained_lld_dir = libdir_bin.join("gcc-ld");
t!(fs::create_dir_all(&self_contained_lld_dir));

for name in crate::LLD_FILE_NAMES {
builder.copy_link(&executable, &self_contained_lld_dir.join(exe(name, target)));
}
}
}

Expand Down

0 comments on commit 3b8c1dd

Please sign in to comment.