Skip to content

Add ToolTarget to bootstrap #143641

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

Merged
merged 12 commits into from
Jul 19, 2025
4 changes: 2 additions & 2 deletions src/bootstrap/src/core/build_steps/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::core::build_steps::compile::{
};
use crate::core::build_steps::tool;
use crate::core::build_steps::tool::{
COMPILETEST_ALLOW_FEATURES, SourceType, get_tool_target_compiler, prepare_tool_cargo,
COMPILETEST_ALLOW_FEATURES, SourceType, get_compiler_for_target, prepare_tool_cargo,
};
use crate::core::builder::{
self, Alias, Builder, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description,
Expand Down Expand Up @@ -252,7 +252,7 @@ fn prepare_compiler_for_check(

match mode {
Mode::ToolBootstrap => builder.compiler(0, host),
Mode::ToolTarget => get_tool_target_compiler(builder, target),
Mode::ToolTarget => get_compiler_for_target(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
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
30 changes: 17 additions & 13 deletions src/bootstrap/src/core/build_steps/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl Step for ToolBuild {
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 Down Expand Up @@ -196,7 +196,7 @@ impl Step for ToolBuild {
Kind::Build,
self.mode,
self.tool,
self.build_compiler.stage,
self.build_compiler.stage + 1,
&self.build_compiler.host,
&self.target,
);
Expand Down Expand Up @@ -365,15 +365,15 @@ 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 {
todo!("FIX");
if builder.host_target == target {
/// Returns the smallest stage compiler that is able to compile code for the given `target`.
pub(crate) fn get_compiler_for_target(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, target)
}
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
Expand Down Expand Up @@ -648,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 @@ -661,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_compiler_for_target(run.builder, run.target),
target: run.target,
});
}

fn run(self, builder: &Builder<'_>) -> ToolBuildResult {
builder.ensure(ToolBuild {
build_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 @@ -680,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