Skip to content

Commit

Permalink
Auto merge of rust-lang#122558 - kjetilkjeka:llvm_bitcode_linker_no_t…
Browse files Browse the repository at this point in the history
…rigger_rebuild, r=onur-ozkan

LLVM bitcode linker: use --cfg=parallel_compiler to avoid invalidating the build cache of rustdoc

fixes rust-lang#122491

`@rustbot` ready
  • Loading branch information
bors committed Mar 18, 2024
2 parents a42873e + 7bdd63d commit 13abc0a
Showing 1 changed file with 73 additions and 1 deletion.
74 changes: 73 additions & 1 deletion src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,79 @@ impl Step for RustAnalyzerProcMacroSrv {
}
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct LlvmBitcodeLinker {
pub compiler: Compiler,
pub target: TargetSelection,
pub extra_features: Vec<String>,
}

impl Step for LlvmBitcodeLinker {
type Output = PathBuf;
const DEFAULT: bool = true;
const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let builder = run.builder;
run.path("src/tools/llvm-bitcode-linker").default_condition(
builder.config.extended
&& builder
.config
.tools
.as_ref()
.map_or(builder.build.unstable_features(), |tools| {
tools.iter().any(|tool| tool == "llvm-bitcode-linker")
}),
)
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(LlvmBitcodeLinker {
compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.build),
extra_features: Vec::new(),
target: run.target,
});
}

fn run(self, builder: &Builder<'_>) -> PathBuf {
let bin_name = "llvm-bitcode-linker";

builder.ensure(compile::Std::new(self.compiler, self.compiler.host));
builder.ensure(compile::Rustc::new(self.compiler, self.target));

let mut cargo = prepare_tool_cargo(
builder,
self.compiler,
Mode::ToolRustc,
self.target,
"build",
"src/tools/llvm-bitcode-linker",
SourceType::InTree,
&self.extra_features,
);

if builder.config.rustc_parallel {
cargo.rustflag("--cfg=parallel_compiler");
}

builder.run(&mut cargo.into());

let tool_out = builder
.cargo_out(self.compiler, Mode::ToolRustc, self.target)
.join(exe(bin_name, self.compiler.host));

if self.compiler.stage > 0 {
let bindir = builder.sysroot(self.compiler).join("bin");
t!(fs::create_dir_all(&bindir));
let bin_destination = bindir.join(exe(bin_name, self.compiler.host));
builder.copy_link(&tool_out, &bin_destination);
bin_destination
} else {
tool_out
}
}
}

macro_rules! tool_extended {
(($sel:ident, $builder:ident),
$($name:ident,
Expand Down Expand Up @@ -795,7 +868,6 @@ tool_extended!((self, builder),
Rls, "src/tools/rls", "rls", stable=true, tool_std=true;
RustDemangler, "src/tools/rust-demangler", "rust-demangler", stable=false, tool_std=true;
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
LlvmBitcodeLinker, "src/tools/llvm-bitcode-linker", "llvm-bitcode-linker", stable=false, add_bins_to_sysroot = ["llvm-bitcode-linker"];
);

impl<'a> Builder<'a> {
Expand Down

0 comments on commit 13abc0a

Please sign in to comment.