Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce compiler Assemble complexity #134437

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1892,12 +1892,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 @@ -1958,22 +1952,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
Loading