Skip to content

Commit 1df946e

Browse files
committed
Port codegen backends to RustcPrivateCompilers
1 parent b7fdf93 commit 1df946e

File tree

6 files changed

+48
-60
lines changed

6 files changed

+48
-60
lines changed

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

Lines changed: 33 additions & 30 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::{
@@ -1133,7 +1133,7 @@ impl Step for Rustc {
11331133
cargo.env("RUSTC_BOLT_LINK_FLAGS", "1");
11341134
}
11351135

1136-
let _guard = builder.msg_sysroot_tool(
1136+
let _guard = builder.msg_rustc_tool(
11371137
Kind::Build,
11381138
build_compiler.stage,
11391139
format_args!("compiler artifacts{}", crate_description(&self.crates)),
@@ -1546,9 +1546,8 @@ impl Step for RustcLink {
15461546

15471547
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
15481548
pub struct CodegenBackend {
1549-
pub target: TargetSelection,
1550-
pub compiler: Compiler,
1551-
pub backend: String,
1549+
compilers: RustcPrivateCompilers,
1550+
backend: String,
15521551
}
15531552

15541553
fn needs_codegen_config(run: &RunConfig<'_>) -> bool {
@@ -1612,8 +1611,11 @@ impl Step for CodegenBackend {
16121611
}
16131612

16141613
run.builder.ensure(CodegenBackend {
1615-
target: run.target,
1616-
compiler: run.builder.compiler(run.builder.top_stage, run.build_triple()),
1614+
compilers: RustcPrivateCompilers::new(
1615+
run.builder,
1616+
run.builder.top_stage,
1617+
run.target,
1618+
),
16171619
backend: backend.clone(),
16181620
});
16191621
}
@@ -1626,21 +1628,17 @@ impl Step for CodegenBackend {
16261628
name = "CodegenBackend::run",
16271629
skip_all,
16281630
fields(
1629-
compiler = ?self.compiler,
1630-
target = ?self.target,
1631-
backend = ?self.target,
1631+
compilers = ?self.compilers,
1632+
backend = ?self.backend,
16321633
),
16331634
),
16341635
)]
16351636
fn run(self, builder: &Builder<'_>) {
1636-
let compiler = self.compiler;
1637-
let target = self.target;
16381637
let backend = self.backend;
1638+
let target = self.compilers.target();
1639+
let build_compiler = self.compilers.build_compiler();
16391640

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

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

16621654
let mut cargo = builder::Cargo::new(
16631655
builder,
1664-
compiler,
1656+
build_compiler,
16651657
Mode::Codegen,
16661658
SourceType::InTree,
16671659
target,
@@ -1682,7 +1674,13 @@ impl Step for CodegenBackend {
16821674

16831675
let tmp_stamp = BuildStamp::new(&out_dir).with_prefix("tmp");
16841676

1685-
let _guard = builder.msg_build(compiler, format_args!("codegen backend {backend}"), target);
1677+
let _guard = builder.msg_rustc_tool(
1678+
Kind::Build,
1679+
build_compiler.stage,
1680+
format_args!("codegen backend {backend}"),
1681+
build_compiler.host,
1682+
target,
1683+
);
16861684
let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false, false);
16871685
if builder.config.dry_run() {
16881686
return;
@@ -1702,15 +1700,18 @@ impl Step for CodegenBackend {
17021700
f.display()
17031701
);
17041702
}
1705-
let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, &backend);
1703+
let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, &backend);
17061704
let codegen_backend = codegen_backend.to_str().unwrap();
17071705
t!(stamp.add_stamp(codegen_backend).write());
17081706
}
17091707

17101708
fn metadata(&self) -> Option<StepMetadata> {
17111709
Some(
1712-
StepMetadata::build(&format!("rustc_codegen_{}", self.backend), self.target)
1713-
.built_by(self.compiler),
1710+
StepMetadata::build(
1711+
&format!("rustc_codegen_{}", self.backend),
1712+
self.compilers.target(),
1713+
)
1714+
.built_by(self.compilers.build_compiler()),
17141715
)
17151716
}
17161717
}
@@ -2199,8 +2200,10 @@ impl Step for Assemble {
21992200
continue;
22002201
}
22012202
builder.ensure(CodegenBackend {
2202-
compiler: build_compiler,
2203-
target: target_compiler.host,
2203+
compilers: RustcPrivateCompilers::from_build_and_link_compiler(
2204+
build_compiler,
2205+
target_compiler,
2206+
),
22042207
backend: backend.clone(),
22052208
});
22062209
}

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
@@ -600,7 +600,7 @@ impl Step for Miri {
600600
cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg());
601601

602602
{
603-
let _guard = builder.msg_sysroot_tool(Kind::Test, stage, "miri", host, target);
603+
let _guard = builder.msg_rustc_tool(Kind::Test, stage, "miri", host, target);
604604
let _time = helpers::timeit(builder);
605605
cargo.run(builder);
606606
}
@@ -616,7 +616,7 @@ impl Step for Miri {
616616
cargo.args(["tests/pass", "tests/panic"]);
617617

618618
{
619-
let _guard = builder.msg_sysroot_tool(
619+
let _guard = builder.msg_rustc_tool(
620620
Kind::Test,
621621
stage,
622622
"miri (mir-opt-level 4)",
@@ -693,7 +693,7 @@ impl Step for CargoMiri {
693693
// Finally, run everything.
694694
let mut cargo = BootstrapCommand::from(cargo);
695695
{
696-
let _guard = builder.msg_sysroot_tool(Kind::Test, stage, "cargo-miri", host, target);
696+
let _guard = builder.msg_rustc_tool(Kind::Test, stage, "cargo-miri", host, target);
697697
let _time = helpers::timeit(builder);
698698
cargo.run(builder);
699699
}
@@ -820,8 +820,7 @@ impl Step for Clippy {
820820
cargo.add_rustc_lib_path(builder);
821821
let cargo = prepare_cargo_test(cargo, &[], &[], host, builder);
822822

823-
let _guard =
824-
builder.msg_sysroot_tool(Kind::Test, build_compiler.stage, "clippy", host, host);
823+
let _guard = builder.msg_rustc_tool(Kind::Test, build_compiler.stage, "clippy", host, host);
825824

826825
// Clippy reports errors if it blessed the outputs
827826
if cargo.allow_failure().run(builder) {
@@ -1088,7 +1087,7 @@ impl Step for RustdocGUI {
10881087
}
10891088

10901089
let _time = helpers::timeit(builder);
1091-
let _guard = builder.msg_sysroot_tool(
1090+
let _guard = builder.msg_rustc_tool(
10921091
Kind::Test,
10931092
self.compiler.stage,
10941093
"rustdoc-gui",
@@ -2563,7 +2562,7 @@ fn run_cargo_test<'a>(
25632562
let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder);
25642563
let _time = helpers::timeit(builder);
25652564
let _group = description.into().and_then(|what| {
2566-
builder.msg_sysroot_tool(Kind::Test, compiler.stage, what, compiler.host, target)
2565+
builder.msg_rustc_tool(Kind::Test, compiler.stage, what, compiler.host, target)
25672566
});
25682567

25692568
#[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
@@ -730,9 +730,6 @@ mod snapshot {
730730
[build] rustc 0 <host> -> rustc 1 <host>
731731
[build] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
732732
[build] rustc 1 <host> -> std 1 <host>
733-
[build] rustc 1 <host> -> std 1 <host>
734-
[build] rustc 1 <host> -> rustc 2 <host>
735-
[build] rustc 1 <host> -> rustc_codegen_cranelift 2 <host>
736733
[build] rustdoc 1 <host>
737734
"
738735
);

src/bootstrap/src/lib.rs

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

1063-
#[must_use = "Groups should not be dropped until the Step finishes running"]
1064-
#[track_caller]
1065-
fn msg_build(
1066-
&self,
1067-
compiler: Compiler,
1068-
what: impl Display,
1069-
target: impl Into<Option<TargetSelection>>,
1070-
) -> Option<gha::Group> {
1071-
self.msg(Kind::Build, compiler.stage, what, compiler.host, target)
1072-
}
1073-
10741063
/// Return a `Group` guard for a [`Step`] that is built for each `--stage`.
10751064
///
10761065
/// [`Step`]: crate::core::builder::Step
@@ -1117,7 +1106,7 @@ impl Build {
11171106

11181107
#[must_use = "Groups should not be dropped until the Step finishes running"]
11191108
#[track_caller]
1120-
fn msg_sysroot_tool(
1109+
fn msg_rustc_tool(
11211110
&self,
11221111
action: impl Into<Kind>,
11231112
build_stage: u32,

0 commit comments

Comments
 (0)