-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Implement ToolTarget
and port RemoteTestServer
and WasmComponentLd
to it
#143581
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
Changes from all commits
e8be2d8
63f7241
1239b99
46851d3
759366b
51d48f0
4fddfd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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"), | ||
} | ||
|
||
|
@@ -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, | ||
|
@@ -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"), | ||
|
@@ -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, | ||
&self.build_compiler.host, | ||
&self.target, | ||
); | ||
|
||
|
@@ -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 } | ||
} | ||
} | ||
} | ||
|
@@ -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 { | ||
jieyouxu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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( | ||
|
@@ -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 { | ||
|
@@ -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"]; | ||
|
@@ -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, | ||
|
@@ -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 | ||
} | ||
|
@@ -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, | ||
|
@@ -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, | ||
} | ||
|
||
|
@@ -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(), | ||
|
@@ -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)] | ||
|
@@ -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" | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: hm, might this be a problem if There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
There was a problem hiding this comment.
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