Skip to content

Commit 826842b

Browse files
committed
Auto merge of #143641 - Kobzol:tool-target, r=jieyouxu
Add `ToolTarget` to bootstrap Oh, you thought I'm done with refactoring bootstrap tools? Na-ah, think again! After the failure of #143581, `ToolTarget` is back with a vengeance. This time, I implemented the test changes and tool cleanups without forcing these tools to be built with the stage0 compiler. There are still some small wins though, `LlvmBitcodeLinker` now starts at stage 1, and not stage 2. Cargo should also be ported to this new mode, but I'm leaving that for a follow-up PR. Hopefully X-th time's the charm 🤞 r? `@jieyouxu`
2 parents ebd8557 + 4f1b3e3 commit 826842b

File tree

11 files changed

+393
-168
lines changed

11 files changed

+393
-168
lines changed

src/bootstrap/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ build/
105105
debuginfo/
106106
...
107107

108-
# Bootstrap host tools (which are always compiled with the stage0 compiler)
108+
# Host tools (which are always compiled with the stage0 compiler)
109109
# are stored here.
110110
bootstrap-tools/
111111

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use crate::core::build_steps::compile::{
44
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
55
};
66
use crate::core::build_steps::tool;
7-
use crate::core::build_steps::tool::{COMPILETEST_ALLOW_FEATURES, SourceType, prepare_tool_cargo};
7+
use crate::core::build_steps::tool::{
8+
COMPILETEST_ALLOW_FEATURES, SourceType, ToolTargetBuildMode, get_tool_target_compiler,
9+
prepare_tool_cargo,
10+
};
811
use crate::core::builder::{
912
self, Alias, Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
1013
};
@@ -252,8 +255,10 @@ fn prepare_compiler_for_check(
252255
mode: Mode,
253256
) -> Compiler {
254257
let host = builder.host_target;
258+
255259
match mode {
256260
Mode::ToolBootstrap => builder.compiler(0, host),
261+
Mode::ToolTarget => get_tool_target_compiler(builder, ToolTargetBuildMode::Build(target)),
257262
Mode::ToolStd => {
258263
if builder.config.compile_time_deps {
259264
// When --compile-time-deps is passed, we can't use any rustc

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

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use serde_derive::Deserialize;
1919
use tracing::{instrument, span};
2020

2121
use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
22-
use crate::core::build_steps::tool::SourceType;
22+
use crate::core::build_steps::tool::{SourceType, copy_lld_artifacts};
2323
use crate::core::build_steps::{dist, llvm};
2424
use crate::core::builder;
2525
use crate::core::builder::{
@@ -2050,19 +2050,20 @@ impl Step for Assemble {
20502050
}
20512051
}
20522052

2053-
let maybe_install_llvm_bitcode_linker = |compiler| {
2053+
let maybe_install_llvm_bitcode_linker = || {
20542054
if builder.config.llvm_bitcode_linker_enabled {
20552055
trace!("llvm-bitcode-linker enabled, installing");
2056-
let llvm_bitcode_linker =
2057-
builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker {
2058-
build_compiler: compiler,
2059-
target: target_compiler.host,
2060-
});
2056+
let llvm_bitcode_linker = builder.ensure(
2057+
crate::core::build_steps::tool::LlvmBitcodeLinker::for_use_by_compiler(
2058+
builder,
2059+
target_compiler,
2060+
),
2061+
);
20612062

20622063
// Copy the llvm-bitcode-linker to the self-contained binary directory
20632064
let bindir_self_contained = builder
2064-
.sysroot(compiler)
2065-
.join(format!("lib/rustlib/{}/bin/self-contained", compiler.host));
2065+
.sysroot(target_compiler)
2066+
.join(format!("lib/rustlib/{}/bin/self-contained", target_compiler.host));
20662067
let tool_exe = exe("llvm-bitcode-linker", target_compiler.host);
20672068

20682069
t!(fs::create_dir_all(&bindir_self_contained));
@@ -2089,9 +2090,9 @@ impl Step for Assemble {
20892090
builder.info(&format!("Creating a sysroot for stage{stage} compiler (use `rustup toolchain link 'name' build/host/stage{stage}`)", stage = target_compiler.stage));
20902091
}
20912092

2092-
let mut precompiled_compiler = target_compiler;
2093-
precompiled_compiler.forced_compiler(true);
2094-
maybe_install_llvm_bitcode_linker(precompiled_compiler);
2093+
// FIXME: this is incomplete, we do not copy a bunch of other stuff to the downloaded
2094+
// sysroot...
2095+
maybe_install_llvm_bitcode_linker();
20952096

20962097
return target_compiler;
20972098
}
@@ -2256,10 +2257,12 @@ impl Step for Assemble {
22562257
copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler);
22572258

22582259
if builder.config.lld_enabled {
2259-
builder.ensure(crate::core::build_steps::tool::LldWrapper {
2260-
build_compiler,
2261-
target_compiler,
2262-
});
2260+
let lld_wrapper =
2261+
builder.ensure(crate::core::build_steps::tool::LldWrapper::for_use_by_compiler(
2262+
builder,
2263+
target_compiler,
2264+
));
2265+
copy_lld_artifacts(builder, lld_wrapper, target_compiler);
22632266
}
22642267

22652268
if builder.config.llvm_enabled(target_compiler.host) && builder.config.llvm_tools_enabled {
@@ -2284,23 +2287,22 @@ impl Step for Assemble {
22842287
}
22852288

22862289
// In addition to `rust-lld` also install `wasm-component-ld` when
2287-
// LLD is enabled. This is a relatively small binary that primarily
2288-
// delegates to the `rust-lld` binary for linking and then runs
2289-
// logic to create the final binary. This is used by the
2290-
// `wasm32-wasip2` target of Rust.
2290+
// is enabled. This is used by the `wasm32-wasip2` target of Rust.
22912291
if builder.tool_enabled("wasm-component-ld") {
2292-
let wasm_component = builder.ensure(crate::core::build_steps::tool::WasmComponentLd {
2293-
compiler: build_compiler,
2294-
target: target_compiler.host,
2295-
});
2292+
let wasm_component = builder.ensure(
2293+
crate::core::build_steps::tool::WasmComponentLd::for_use_by_compiler(
2294+
builder,
2295+
target_compiler,
2296+
),
2297+
);
22962298
builder.copy_link(
22972299
&wasm_component.tool_path,
22982300
&libdir_bin.join(wasm_component.tool_path.file_name().unwrap()),
22992301
FileType::Executable,
23002302
);
23012303
}
23022304

2303-
maybe_install_llvm_bitcode_linker(target_compiler);
2305+
maybe_install_llvm_bitcode_linker();
23042306

23052307
// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
23062308
// so that it can be found when the newly built `rustc` is run.

src/bootstrap/src/core/build_steps/dist.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,10 @@ impl Step for Extended {
15751575
compiler: builder.compiler(stage, target),
15761576
backend: "cranelift".to_string(),
15771577
});
1578-
add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker {compiler, target});
1578+
add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker {
1579+
target_compiler: compiler,
1580+
target
1581+
});
15791582

15801583
let etc = builder.src.join("src/etc/installer");
15811584

@@ -2343,7 +2346,7 @@ impl Step for LlvmTools {
23432346

23442347
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
23452348
pub struct LlvmBitcodeLinker {
2346-
pub compiler: Compiler,
2349+
pub target_compiler: Compiler,
23472350
pub target: TargetSelection,
23482351
}
23492352

@@ -2359,23 +2362,16 @@ impl Step for LlvmBitcodeLinker {
23592362

23602363
fn make_run(run: RunConfig<'_>) {
23612364
run.builder.ensure(LlvmBitcodeLinker {
2362-
compiler: run.builder.compiler_for(
2363-
run.builder.top_stage,
2364-
run.builder.config.host_target,
2365-
run.target,
2366-
),
2365+
target_compiler: run.builder.compiler(run.builder.top_stage, run.target),
23672366
target: run.target,
23682367
});
23692368
}
23702369

23712370
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
2372-
let compiler = self.compiler;
23732371
let target = self.target;
23742372

2375-
builder.ensure(compile::Rustc::new(compiler, target));
2376-
2377-
let llbc_linker =
2378-
builder.ensure(tool::LlvmBitcodeLinker { build_compiler: compiler, target });
2373+
let llbc_linker = builder
2374+
.ensure(tool::LlvmBitcodeLinker::for_use_by_compiler(builder, self.target_compiler));
23792375

23802376
let self_contained_bin_dir = format!("lib/rustlib/{}/bin/self-contained", target.triple);
23812377

src/bootstrap/src/core/build_steps/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ install!((self, builder, _config),
287287
}
288288
};
289289
LlvmBitcodeLinker, alias = "llvm-bitcode-linker", Self::should_build(_config), only_hosts: true, {
290-
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { compiler: self.compiler, target: self.target }) {
290+
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { target_compiler: self.compiler, target: self.target }) {
291291
install_sh(builder, "llvm-bitcode-linker", self.compiler.stage, Some(self.target), &tarball);
292292
} else {
293293
builder.info(

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2945,7 +2945,8 @@ impl Step for RemoteCopyLibs {
29452945

29462946
builder.info(&format!("REMOTE copy libs to emulator ({target})"));
29472947

2948-
let remote_test_server = builder.ensure(tool::RemoteTestServer { compiler, target });
2948+
let remote_test_server =
2949+
builder.ensure(tool::RemoteTestServer { build_compiler: compiler, target });
29492950

29502951
// Spawn the emulator and wait for it to come online
29512952
let tool = builder.tool_exe(Tool::RemoteTestClient);

0 commit comments

Comments
 (0)