Skip to content
2 changes: 1 addition & 1 deletion src/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ build/
debuginfo/
...

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

Expand Down
7 changes: 6 additions & 1 deletion src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use crate::core::build_steps::compile::{
add_to_sysroot, run_cargo, rustc_cargo, rustc_cargo_env, std_cargo, std_crates_for_run_make,
};
use crate::core::build_steps::tool;
use crate::core::build_steps::tool::{COMPILETEST_ALLOW_FEATURES, SourceType, prepare_tool_cargo};
use crate::core::build_steps::tool::{
COMPILETEST_ALLOW_FEATURES, SourceType, ToolTargetBuildMode, get_tool_target_compiler,
prepare_tool_cargo,
};
use crate::core::builder::{
self, Alias, Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
};
Expand Down Expand Up @@ -247,8 +250,10 @@ fn prepare_compiler_for_check(
mode: Mode,
) -> Compiler {
let host = builder.host_target;

match mode {
Mode::ToolBootstrap => builder.compiler(0, host),
Mode::ToolTarget => get_tool_target_compiler(builder, ToolTargetBuildMode::Build(target)),
Mode::ToolStd => {
// These tools require the local standard library to be checked
let build_compiler = builder.compiler(builder.top_stage, host);
Expand Down
52 changes: 27 additions & 25 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use serde_derive::Deserialize;
use tracing::{instrument, span};

use crate::core::build_steps::gcc::{Gcc, add_cg_gcc_cargo_flags};
use crate::core::build_steps::tool::SourceType;
use crate::core::build_steps::tool::{SourceType, copy_lld_artifacts};
use crate::core::build_steps::{dist, llvm};
use crate::core::builder;
use crate::core::builder::{
Expand Down Expand Up @@ -2052,19 +2052,20 @@ impl Step for Assemble {
}
}

let maybe_install_llvm_bitcode_linker = |compiler| {
let maybe_install_llvm_bitcode_linker = || {
if builder.config.llvm_bitcode_linker_enabled {
trace!("llvm-bitcode-linker enabled, installing");
let llvm_bitcode_linker =
builder.ensure(crate::core::build_steps::tool::LlvmBitcodeLinker {
build_compiler: compiler,
target: target_compiler.host,
});
let llvm_bitcode_linker = builder.ensure(
crate::core::build_steps::tool::LlvmBitcodeLinker::from_target_compiler(
builder,
target_compiler,
),
);

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

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

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

return target_compiler;
}
Expand Down Expand Up @@ -2258,10 +2259,12 @@ impl Step for Assemble {
copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler);

if builder.config.lld_enabled {
builder.ensure(crate::core::build_steps::tool::LldWrapper {
build_compiler,
target_compiler,
});
let lld_wrapper =
builder.ensure(crate::core::build_steps::tool::LldWrapper::for_use_by_compiler(
builder,
target_compiler,
));
copy_lld_artifacts(builder, lld_wrapper, target_compiler);
}

if builder.config.llvm_enabled(target_compiler.host) && builder.config.llvm_tools_enabled {
Expand All @@ -2286,23 +2289,22 @@ impl Step for Assemble {
}

// In addition to `rust-lld` also install `wasm-component-ld` when
// LLD is enabled. This is a relatively small binary that primarily
// delegates to the `rust-lld` binary for linking and then runs
// logic to create the final binary. This is used by the
// `wasm32-wasip2` target of Rust.
// is enabled. This is used by the `wasm32-wasip2` target of Rust.
if builder.tool_enabled("wasm-component-ld") {
let wasm_component = builder.ensure(crate::core::build_steps::tool::WasmComponentLd {
compiler: build_compiler,
target: target_compiler.host,
});
let wasm_component = builder.ensure(
crate::core::build_steps::tool::WasmComponentLd::for_use_by_compiler(
builder,
target_compiler,
),
);
builder.copy_link(
&wasm_component.tool_path,
&libdir_bin.join(wasm_component.tool_path.file_name().unwrap()),
FileType::Executable,
);
}

maybe_install_llvm_bitcode_linker(target_compiler);
maybe_install_llvm_bitcode_linker();

// Ensure that `libLLVM.so` ends up in the newly build compiler directory,
// so that it can be found when the newly built `rustc` is run.
Expand Down
23 changes: 13 additions & 10 deletions src/bootstrap/src/core/build_steps/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,7 +1575,10 @@ impl Step for Extended {
compiler: builder.compiler(stage, target),
backend: "cranelift".to_string(),
});
add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker {compiler, target});
add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker {
build_compiler: compiler,
target
});

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

Expand Down Expand Up @@ -2341,9 +2344,13 @@ impl Step for LlvmTools {
}
}

/// Distributes the `llvm-bitcode-linker` tool so that it can be used by a compiler whose host
/// is `target`.
#[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)]
pub struct LlvmBitcodeLinker {
pub compiler: Compiler,
/// The linker will be compiled by this compiler.
pub build_compiler: Compiler,
/// The linker will by usable by rustc on this host.
pub target: TargetSelection,
}

Expand All @@ -2359,23 +2366,19 @@ impl Step for LlvmBitcodeLinker {

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(LlvmBitcodeLinker {
compiler: run.builder.compiler_for(
run.builder.top_stage,
run.builder.config.host_target,
build_compiler: tool::LlvmBitcodeLinker::get_build_compiler_for_target(
run.builder,
run.target,
),
target: run.target,
});
}

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

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

let llbc_linker =
builder.ensure(tool::LlvmBitcodeLinker { build_compiler: compiler, target });
let llbc_linker = builder
.ensure(tool::LlvmBitcodeLinker::from_build_compiler(self.build_compiler, target));

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

Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/src/core/build_steps/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ install!((self, builder, _config),
}
};
LlvmBitcodeLinker, alias = "llvm-bitcode-linker", Self::should_build(_config), only_hosts: true, {
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { compiler: self.compiler, target: self.target }) {
if let Some(tarball) = builder.ensure(dist::LlvmBitcodeLinker { build_compiler: self.compiler, target: self.target }) {
install_sh(builder, "llvm-bitcode-linker", self.compiler.stage, Some(self.target), &tarball);
} else {
builder.info(
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/src/core/build_steps/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2941,7 +2941,8 @@ impl Step for RemoteCopyLibs {

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

let remote_test_server = builder.ensure(tool::RemoteTestServer { compiler, target });
let remote_test_server =
builder.ensure(tool::RemoteTestServer { build_compiler: compiler, target });

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