Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
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
6 changes: 5 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,9 @@ 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, 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 +249,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, target),
Mode::ToolStd => {
// These tools require the local standard library to be checked
let build_compiler = builder.compiler(builder.top_stage, host);
Expand Down
14 changes: 6 additions & 8 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2282,15 +2282,13 @@ 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_target(
builder,
target_compiler.host,
));
builder.copy_link(
&wasm_component.tool_path,
&libdir_bin.join(wasm_component.tool_path.file_name().unwrap()),
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 @@ -2929,7 +2929,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
143 changes: 108 additions & 35 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ pub enum ToolArtifactKind {

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
struct ToolBuild {
compiler: Compiler,
/// Compiler that will build this tool.
build_compiler: Compiler,
target: TargetSelection,
tool: &'static str,
path: &'static str,
Expand Down Expand Up @@ -111,28 +112,28 @@ impl Step for ToolBuild {
let mut tool = self.tool;
let path = self.path;

let target_compiler = self.compiler;
self.compiler = if self.mode == Mode::ToolRustc {
get_tool_rustc_compiler(builder, self.compiler)
let target_compiler = self.build_compiler;
self.build_compiler = if self.mode == Mode::ToolRustc {
get_tool_rustc_compiler(builder, self.build_compiler)
} else {
self.compiler
self.build_compiler
};

match self.mode {
Mode::ToolRustc => {
// If compiler was forced, its artifacts should have been prepared earlier.
if !self.compiler.is_forced_compiler() {
builder.std(self.compiler, self.compiler.host);
builder.ensure(compile::Rustc::new(self.compiler, target));
if !self.build_compiler.is_forced_compiler() {
builder.std(self.build_compiler, self.build_compiler.host);
builder.ensure(compile::Rustc::new(self.build_compiler, target));
}
}
Mode::ToolStd => {
// If compiler was forced, its artifacts should have been prepared earlier.
if !self.compiler.is_forced_compiler() {
builder.std(self.compiler, target)
if !self.build_compiler.is_forced_compiler() {
builder.std(self.build_compiler, target);
}
}
Mode::ToolBootstrap => {} // uses downloaded stage0 compiler libs
Mode::ToolBootstrap | Mode::ToolTarget => {} // uses downloaded stage0 compiler libs
_ => panic!("unexpected Mode for tool build"),
}

Expand All @@ -151,7 +152,7 @@ impl Step for ToolBuild {

let mut cargo = prepare_tool_cargo(
builder,
self.compiler,
self.build_compiler,
self.mode,
target,
Kind::Build,
Expand All @@ -173,7 +174,7 @@ impl Step for ToolBuild {

// Rustc tools (miri, clippy, cargo, rustfmt, rust-analyzer)
// could use the additional optimizations.
if self.mode == Mode::ToolRustc && is_lto_stage(&self.compiler) {
if self.mode == Mode::ToolRustc && is_lto_stage(&self.build_compiler) {
let lto = match builder.config.rust_lto {
RustcLto::Off => Some("off"),
RustcLto::Thin => Some("thin"),
Expand All @@ -195,8 +196,8 @@ impl Step for ToolBuild {
Kind::Build,
self.mode,
self.tool,
self.compiler.stage,
&self.compiler.host,
self.build_compiler.stage + 1,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remark: this is because it's a product of the stage 0 rustc that is not the stage 0 library

&self.build_compiler.host,
&self.target,
);

Expand All @@ -219,14 +220,14 @@ impl Step for ToolBuild {
}
let tool_path = match self.artifact_kind {
ToolArtifactKind::Binary => {
copy_link_tool_bin(builder, self.compiler, self.target, self.mode, tool)
copy_link_tool_bin(builder, self.build_compiler, self.target, self.mode, tool)
}
ToolArtifactKind::Library => builder
.cargo_out(self.compiler, self.mode, self.target)
.cargo_out(self.build_compiler, self.mode, self.target)
.join(format!("lib{tool}.rlib")),
};

ToolBuildResult { tool_path, build_compiler: self.compiler, target_compiler }
ToolBuildResult { tool_path, build_compiler: self.build_compiler, target_compiler }
}
}
}
Expand Down Expand Up @@ -364,6 +365,18 @@ pub(crate) fn get_tool_rustc_compiler(
builder.compiler(target_compiler.stage.saturating_sub(1), builder.config.host_target)
}

/// Returns a compiler that is able to compile a `ToolTarget` tool for the given `target`.
pub(crate) fn get_tool_target_compiler(builder: &Builder<'_>, target: TargetSelection) -> Compiler {
let compiler = if builder.host_target == target {
builder.compiler(0, builder.host_target)
} else {
// FIXME: should this be builder.top_stage to avoid rebuilds?
builder.compiler(1, builder.host_target)
};
builder.std(compiler, target);
compiler
}

/// Links a built tool binary with the given `name` from the build directory to the
/// tools directory.
fn copy_link_tool_bin(
Expand Down Expand Up @@ -450,7 +463,7 @@ macro_rules! bootstrap_tool {
let compiletest_wants_stage0 = $tool_name == "compiletest" && builder.config.compiletest_use_stage0_libtest;

builder.ensure(ToolBuild {
compiler: self.compiler,
build_compiler: self.compiler,
target: self.target,
tool: $tool_name,
mode: if is_unstable && !compiletest_wants_stage0 {
Expand Down Expand Up @@ -521,7 +534,6 @@ bootstrap_tool!(
// rustdoc-gui-test has a crate dependency on compiletest, so it needs the same unstable features.
RustdocGUITest, "src/tools/rustdoc-gui-test", "rustdoc-gui-test", is_unstable_tool = true, allow_features = COMPILETEST_ALLOW_FEATURES;
CoverageDump, "src/tools/coverage-dump", "coverage-dump";
WasmComponentLd, "src/tools/wasm-component-ld", "wasm-component-ld", is_unstable_tool = true, allow_features = "min_specialization";
UnicodeTableGenerator, "src/tools/unicode-table-generator", "unicode-table-generator";
FeaturesStatusDump, "src/tools/features-status-dump", "features-status-dump";
OptimizedDist, "src/tools/opt-dist", "opt-dist", submodules = &["src/tools/rustc-perf"];
Expand Down Expand Up @@ -560,7 +572,7 @@ impl Step for RustcPerf {
builder.require_submodule("src/tools/rustc-perf", None);

let tool = ToolBuild {
compiler: self.compiler,
build_compiler: self.compiler,
target: self.target,
tool: "collector",
mode: Mode::ToolBootstrap,
Expand All @@ -576,7 +588,7 @@ impl Step for RustcPerf {
let res = builder.ensure(tool.clone());
// We also need to symlink the `rustc-fake` binary to the corresponding directory,
// because `collector` expects it in the same directory.
copy_link_tool_bin(builder, tool.compiler, tool.target, tool.mode, "rustc-fake");
copy_link_tool_bin(builder, tool.build_compiler, tool.target, tool.mode, "rustc-fake");

res
}
Expand Down Expand Up @@ -620,7 +632,7 @@ impl Step for ErrorIndex {

fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
builder.ensure(ToolBuild {
compiler: self.compiler,
build_compiler: self.compiler,
target: self.compiler.host,
tool: "error_index_generator",
mode: Mode::ToolRustc,
Expand All @@ -636,7 +648,7 @@ impl Step for ErrorIndex {

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

Expand All @@ -649,17 +661,17 @@ impl Step for RemoteTestServer {

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

fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
builder.ensure(ToolBuild {
compiler: self.compiler,
build_compiler: self.build_compiler,
target: self.target,
tool: "remote-test-server",
mode: Mode::ToolStd,
mode: Mode::ToolTarget,
path: "src/tools/remote-test-server",
source_type: SourceType::InTree,
extra_features: Vec::new(),
Expand All @@ -668,6 +680,10 @@ impl Step for RemoteTestServer {
artifact_kind: ToolArtifactKind::Binary,
})
}

fn metadata(&self) -> Option<StepMetadata> {
Some(StepMetadata::build("remote-test-server", self.target).built_by(self.build_compiler))
}
}

#[derive(Debug, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
Expand Down Expand Up @@ -757,7 +773,7 @@ impl Step for Rustdoc {

let ToolBuildResult { tool_path, build_compiler, target_compiler } =
builder.ensure(ToolBuild {
compiler: target_compiler,
build_compiler: target_compiler,
target,
// Cargo adds a number of paths to the dylib search path on windows, which results in
// the wrong rustdoc being executed. To avoid the conflicting rustdocs, we name the "tool"
Expand Down Expand Up @@ -825,7 +841,7 @@ impl Step for Cargo {
builder.build.require_submodule("src/tools/cargo", None);

builder.ensure(ToolBuild {
compiler: self.compiler,
build_compiler: self.compiler,
target: self.target,
tool: "cargo",
mode: Mode::ToolRustc,
Expand Down Expand Up @@ -873,7 +889,7 @@ impl Step for LldWrapper {
let target = self.target_compiler.host;

let tool_result = builder.ensure(ToolBuild {
compiler: self.build_compiler,
build_compiler: self.build_compiler,
target,
tool: "lld-wrapper",
mode: Mode::ToolStd,
Expand Down Expand Up @@ -912,6 +928,63 @@ impl Step for LldWrapper {
}
}

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

impl WasmComponentLd {
pub fn for_target(builder: &Builder<'_>, target: TargetSelection) -> Self {
Self { build_compiler: get_tool_target_compiler(builder, target), target }
}
}

impl Step for WasmComponentLd {
type Output = ToolBuildResult;

const ONLY_HOSTS: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.path("src/tools/wasm-component-ld")
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(WasmComponentLd {
build_compiler: get_tool_target_compiler(run.builder, run.target),
target: run.target,
});
}

#[cfg_attr(
feature = "tracing",
instrument(
level = "debug",
name = "WasmComponentLd::run",
skip_all,
fields(build_compiler = ?self.build_compiler),
),
)]
fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
builder.ensure(ToolBuild {
build_compiler: self.build_compiler,
target: self.target,
tool: "wasm-component-ld",
mode: Mode::ToolTarget,
path: "src/tools/wasm-component-ld",
source_type: SourceType::InTree,
extra_features: vec![],
allow_features: "min-specialization",
Comment on lines +976 to +977
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: hm, might this be a problem if min_specialization ever gets renamed, removed or stabilized? Or rather, the tool now has to be support being built by both stage 0 compiler and stage 1 compiler right? In that situation, the tool would have to cfg(bootstrap) anyway I think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the feature flag is even needed, the tool compiles with the stable compiler... Unless it does some weird detection in build scripts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep it for now, to leave the previous functionality intact. If it becomes an issue, we can always try to remove it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that sounds reasonable.

cargo_args: vec![],
artifact_kind: ToolArtifactKind::Binary,
})
}

fn metadata(&self) -> Option<StepMetadata> {
Some(StepMetadata::build("WasmComponentLd", self.target).built_by(self.build_compiler))
}
}

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct RustAnalyzer {
pub compiler: Compiler,
Expand Down Expand Up @@ -941,7 +1014,7 @@ impl Step for RustAnalyzer {

fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
builder.ensure(ToolBuild {
compiler: self.compiler,
build_compiler: self.compiler,
target: self.target,
tool: "rust-analyzer",
mode: Mode::ToolRustc,
Expand Down Expand Up @@ -986,7 +1059,7 @@ impl Step for RustAnalyzerProcMacroSrv {

fn run(self, builder: &Builder<'_>) -> Option<ToolBuildResult> {
let tool_result = builder.ensure(ToolBuild {
compiler: self.compiler,
build_compiler: self.compiler,
target: self.target,
tool: "rust-analyzer-proc-macro-srv",
mode: Mode::ToolRustc,
Expand Down Expand Up @@ -1044,7 +1117,7 @@ impl Step for LlvmBitcodeLinker {
)]
fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
let tool_result = builder.ensure(ToolBuild {
compiler: self.compiler,
build_compiler: self.compiler,
target: self.target,
tool: "llvm-bitcode-linker",
mode: Mode::ToolRustc,
Expand Down Expand Up @@ -1241,7 +1314,7 @@ fn run_tool_build_step(

let ToolBuildResult { tool_path, build_compiler, target_compiler } =
builder.ensure(ToolBuild {
compiler,
build_compiler: compiler,
target,
tool: tool_name,
mode: Mode::ToolRustc,
Expand Down Expand Up @@ -1338,7 +1411,7 @@ impl Step for TestFloatParse {
let compiler = builder.compiler(builder.top_stage, bootstrap_host);

builder.ensure(ToolBuild {
compiler,
build_compiler: compiler,
target: bootstrap_host,
tool: "test-float-parse",
mode: Mode::ToolStd,
Expand Down
Loading
Loading