Skip to content

Commit 06855be

Browse files
committed
Port codegen backends to RustcPrivateCompilers
1 parent 7a2c4d3 commit 06855be

File tree

6 files changed

+45
-61
lines changed

6 files changed

+45
-61
lines changed

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

Lines changed: 30 additions & 31 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, copy_lld_artifacts};
22+
use crate::core::build_steps::tool::{RustcPrivateCompilers, SourceType, copy_lld_artifacts};
2323
use crate::core::build_steps::{dist, llvm};
2424
use crate::core::builder;
2525
use crate::core::builder::{
@@ -1131,7 +1131,7 @@ impl Step for Rustc {
11311131
cargo.env("RUSTC_BOLT_LINK_FLAGS", "1");
11321132
}
11331133

1134-
let _guard = builder.msg_sysroot_tool(
1134+
let _guard = builder.msg_rustc_tool(
11351135
Kind::Build,
11361136
build_compiler.stage,
11371137
format_args!("compiler artifacts{}", crate_description(&self.crates)),
@@ -1544,9 +1544,8 @@ impl Step for RustcLink {
15441544

15451545
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
15461546
pub struct CodegenBackend {
1547-
pub target: TargetSelection,
1548-
pub compiler: Compiler,
1549-
pub backend: CodegenBackendKind,
1547+
compilers: RustcPrivateCompilers,
1548+
backend: CodegenBackendKind,
15501549
}
15511550

15521551
fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
@@ -1610,8 +1609,11 @@ impl Step for CodegenBackend {
16101609
}
16111610

16121611
run.builder.ensure(CodegenBackend {
1613-
target: run.target,
1614-
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
1612+
compilers: RustcPrivateCompilers::new(
1613+
run.builder,
1614+
run.builder.top_stage,
1615+
run.target,
1616+
),
16151617
backend: backend.clone(),
16161618
});
16171619
}
@@ -1624,21 +1626,17 @@ impl Step for CodegenBackend {
16241626
name = "CodegenBackend::run",
16251627
skip_all,
16261628
fields(
1627-
compiler = ?self.compiler,
1628-
target = ?self.target,
1629-
backend = ?self.target,
1629+
compilers = ?self.compilers,
1630+
backend = ?self.backend,
16301631
),
16311632
),
16321633
)]
16331634
fn run(self, builder: &Builder<'_>) {
1634-
let compiler = self.compiler;
1635-
let target = self.target;
16361635
let backend = self.backend;
1636+
let target = self.compilers.target();
1637+
let build_compiler = self.compilers.build_compiler();
16371638

1638-
// FIXME: migrate to RustcPrivateCompilers
1639-
builder.ensure(Rustc::new(compiler, target));
1640-
1641-
if builder.config.keep_stage.contains(&compiler.stage) {
1639+
if builder.config.keep_stage.contains(&build_compiler.stage) {
16421640
trace!("`keep-stage` requested");
16431641
builder.info(
16441642
"WARNING: Using a potentially old codegen backend. \
@@ -1649,17 +1647,11 @@ impl Step for CodegenBackend {
16491647
return;
16501648
}
16511649

1652-
let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target);
1653-
if compiler_to_use != compiler {
1654-
builder.ensure(CodegenBackend { compiler: compiler_to_use, target, backend });
1655-
return;
1656-
}
1657-
1658-
let out_dir = builder.cargo_out(compiler, Mode::Codegen, target);
1650+
let out_dir = builder.cargo_out(build_compiler, Mode::Codegen, target);
16591651

16601652
let mut cargo = builder::Cargo::new(
16611653
builder,
1662-
compiler,
1654+
build_compiler,
16631655
Mode::Codegen,
16641656
SourceType::InTree,
16651657
target,
@@ -1680,8 +1672,13 @@ impl Step for CodegenBackend {
16801672

16811673
let tmp_stamp = BuildStamp::new(&out_dir).with_prefix("tmp");
16821674

1683-
let _guard =
1684-
builder.msg_build(compiler, format_args!("codegen backend {}", backend.name()), target);
1675+
let _guard = builder.msg_rustc_tool(
1676+
Kind::Build,
1677+
build_compiler.stage,
1678+
format_args!("codegen backend {}", backend.name()),
1679+
build_compiler.host,
1680+
target,
1681+
);
16851682
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false, false);
16861683
if builder.config.dry_run() {
16871684
return;
@@ -1701,15 +1698,15 @@ impl Step for CodegenBackend {
17011698
f.display()
17021699
);
17031700
}
1704-
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, &backend);
1701+
let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, &backend);
17051702
let codegen_backend = codegen_backend.to_str().unwrap();
17061703
t!(stamp.add_stamp(codegen_backend).write());
17071704
}
17081705

17091706
fn metadata(&self) -> Option<StepMetadata> {
17101707
Some(
1711-
StepMetadata::build(&format!("rustc_codegen_{}", self.backend), self.target)
1712-
.built_by(self.compiler),
1708+
StepMetadata::build(&self.backend.crate_name(), self.compilers.target())
1709+
.built_by(self.compilers.build_compiler()),
17131710
)
17141711
}
17151712
}
@@ -2198,8 +2195,10 @@ impl Step for Assemble {
21982195
continue;
21992196
}
22002197
builder.ensure(CodegenBackend {
2201-
compiler: build_compiler,
2202-
target: target_compiler.host,
2198+
compilers: RustcPrivateCompilers::from_build_and_link_compiler(
2199+
build_compiler,
2200+
target_compiler,
2201+
),
22032202
backend: backend.clone(),
22042203
});
22052204
}

src/bootstrap/src/core/build_steps/doc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ impl Step for Rustc {
811811
let compiler = builder.compiler(stage, builder.config.host_target);
812812
builder.std(compiler, builder.config.host_target);
813813

814-
let _guard = builder.msg_sysroot_tool(
814+
let _guard = builder.msg_rustc_tool(
815815
Kind::Doc,
816816
stage,
817817
format!("compiler{}", crate_description(&self.crates)),

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ impl Step for Miri {
603603
cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
604604

605605
{
606-
let _guard = builder.msg_sysroot_tool(Kind::Test, stage, "miri", host, target);
606+
let _guard = builder.msg_rustc_tool(Kind::Test, stage, "miri", host, target);
607607
let _time = helpers::timeit(builder);
608608
cargo.run(builder);
609609
}
@@ -619,7 +619,7 @@ impl Step for Miri {
619619
cargo.args(["tests/pass", "tests/panic"]);
620620

621621
{
622-
let _guard = builder.msg_sysroot_tool(
622+
let _guard = builder.msg_rustc_tool(
623623
Kind::Test,
624624
stage,
625625
"miri (mir-opt-level 4)",
@@ -696,7 +696,7 @@ impl Step for CargoMiri {
696696
// Finally, run everything.
697697
let mut cargo = BootstrapCommand::from(cargo);
698698
{
699-
let _guard = builder.msg_sysroot_tool(Kind::Test, stage, "cargo-miri", host, target);
699+
let _guard = builder.msg_rustc_tool(Kind::Test, stage, "cargo-miri", host, target);
700700
let _time = helpers::timeit(builder);
701701
cargo.run(builder);
702702
}
@@ -837,8 +837,7 @@ impl Step for Clippy {
837837
cargo.add_rustc_lib_path(builder);
838838
let cargo = prepare_cargo_test(cargo, &[], &[], host, builder);
839839

840-
let _guard =
841-
builder.msg_sysroot_tool(Kind::Test, build_compiler.stage, "clippy", host, host);
840+
let _guard = builder.msg_rustc_tool(Kind::Test, build_compiler.stage, "clippy", host, host);
842841

843842
// Clippy reports errors if it blessed the outputs
844843
if cargo.allow_failure().run(builder) {
@@ -1105,7 +1104,7 @@ impl Step for RustdocGUI {
11051104
}
11061105

11071106
let _time = helpers::timeit(builder);
1108-
let _guard = builder.msg_sysroot_tool(
1107+
let _guard = builder.msg_rustc_tool(
11091108
Kind::Test,
11101109
self.compiler.stage,
11111110
"rustdoc-gui",
@@ -2597,7 +2596,7 @@ fn run_cargo_test<'a>(
25972596
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder);
25982597
let _time = helpers::timeit(builder);
25992598
let _group = description.into().and_then(|what| {
2600-
builder.msg_sysroot_tool(Kind::Test, compiler.stage, what, compiler.host, target)
2599+
builder.msg_rustc_tool(Kind::Test, compiler.stage, what, compiler.host, target)
26012600
});
26022601

26032602
#[cfg(feature = "build-metrics")]

src/bootstrap/src/core/build_steps/tool.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,9 @@ impl Builder<'_> {
7171
) -> Option<gha::Group> {
7272
match mode {
7373
// depends on compiler stage, different to host compiler
74-
Mode::ToolRustc => self.msg_sysroot_tool(
75-
kind,
76-
build_stage,
77-
format_args!("tool {tool}"),
78-
*host,
79-
*target,
80-
),
74+
Mode::ToolRustc => {
75+
self.msg_rustc_tool(kind, build_stage, format_args!("tool {tool}"), *host, *target)
76+
}
8177
// doesn't depend on compiler, same as host compiler
8278
_ => self.msg(kind, build_stage, format_args!("tool {tool}"), *host, *target),
8379
}
@@ -1327,6 +1323,10 @@ impl RustcPrivateCompilers {
13271323
Self { build_compiler, link_compiler }
13281324
}
13291325

1326+
pub fn from_build_and_link_compiler(build_compiler: Compiler, link_compiler: Compiler) -> Self {
1327+
Self { build_compiler, link_compiler }
1328+
}
1329+
13301330
/// Create rustc tool compilers from the build compiler.
13311331
pub fn from_build_compiler(
13321332
builder: &Builder<'_>,

src/bootstrap/src/core/builder/tests.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -731,9 +731,6 @@ mod snapshot {
731731
[build] rustc 0 <host> -> rustc 1 <host>
732732
[build] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
733733
[build] rustc 1 <host> -> std 1 <host>
734-
[build] rustc 1 <host> -> std 1 <host>
735-
[build] rustc 1 <host> -> rustc 2 <host>
736-
[build] rustc 1 <host> -> rustc_codegen_cranelift 2 <host>
737734
[build] rustdoc 1 <host>
738735
"
739736
);

src/bootstrap/src/lib.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,17 +1100,6 @@ impl Build {
11001100
self.msg(Kind::Doc, compiler.stage, what, compiler.host, target.into())
11011101
}
11021102

1103-
#[must_use = "Groups should not be dropped until the Step finishes running"]
1104-
#[track_caller]
1105-
fn msg_build(
1106-
&self,
1107-
compiler: Compiler,
1108-
what: impl Display,
1109-
target: impl Into<Option<TargetSelection>>,
1110-
) -> Option<gha::Group> {
1111-
self.msg(Kind::Build, compiler.stage, what, compiler.host, target)
1112-
}
1113-
11141103
/// Return a `Group` guard for a [`Step`] that is built for each `--stage`.
11151104
///
11161105
/// [`Step`]: crate::core::builder::Step
@@ -1157,7 +1146,7 @@ impl Build {
11571146

11581147
#[must_use = "Groups should not be dropped until the Step finishes running"]
11591148
#[track_caller]
1160-
fn msg_sysroot_tool(
1149+
fn msg_rustc_tool(
11611150
&self,
11621151
action: impl Into<Kind>,
11631152
build_stage: u32,

0 commit comments

Comments
 (0)