Skip to content

Commit b7fdf93

Browse files
committed
Add step metadata and a simple test for codegen backends
1 parent 1ddc43f commit b7fdf93

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,6 +1706,13 @@ impl Step for CodegenBackend {
17061706
let codegen_backend = codegen_backend.to_str().unwrap();
17071707
t!(stamp.add_stamp(codegen_backend).write());
17081708
}
1709+
1710+
fn metadata(&self) -> Option<StepMetadata> {
1711+
Some(
1712+
StepMetadata::build(&format!("rustc_codegen_{}", self.backend), self.target)
1713+
.built_by(self.compiler),
1714+
)
1715+
}
17091716
}
17101717

17111718
/// Creates the `codegen-backends` folder for a compiler that's about to be

src/bootstrap/src/core/builder/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash {
142142
#[allow(unused)]
143143
#[derive(Debug, PartialEq, Eq)]
144144
pub struct StepMetadata {
145-
name: &'static str,
145+
name: String,
146146
kind: Kind,
147147
target: TargetSelection,
148148
built_by: Option<Compiler>,
@@ -152,28 +152,28 @@ pub struct StepMetadata {
152152
}
153153

154154
impl StepMetadata {
155-
pub fn build(name: &'static str, target: TargetSelection) -> Self {
155+
pub fn build(name: &str, target: TargetSelection) -> Self {
156156
Self::new(name, target, Kind::Build)
157157
}
158158

159-
pub fn check(name: &'static str, target: TargetSelection) -> Self {
159+
pub fn check(name: &str, target: TargetSelection) -> Self {
160160
Self::new(name, target, Kind::Check)
161161
}
162162

163-
pub fn doc(name: &'static str, target: TargetSelection) -> Self {
163+
pub fn doc(name: &str, target: TargetSelection) -> Self {
164164
Self::new(name, target, Kind::Doc)
165165
}
166166

167-
pub fn dist(name: &'static str, target: TargetSelection) -> Self {
167+
pub fn dist(name: &str, target: TargetSelection) -> Self {
168168
Self::new(name, target, Kind::Dist)
169169
}
170170

171-
pub fn test(name: &'static str, target: TargetSelection) -> Self {
171+
pub fn test(name: &str, target: TargetSelection) -> Self {
172172
Self::new(name, target, Kind::Test)
173173
}
174174

175-
fn new(name: &'static str, target: TargetSelection, kind: Kind) -> Self {
176-
Self { name, kind, target, built_by: None, stage: None, metadata: None }
175+
fn new(name: &str, target: TargetSelection, kind: Kind) -> Self {
176+
Self { name: name.to_string(), kind, target, built_by: None, stage: None, metadata: None }
177177
}
178178

179179
pub fn built_by(mut self, compiler: Compiler) -> Self {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,26 @@ mod snapshot {
718718
");
719719
}
720720

721+
#[test]
722+
fn build_compiler_codegen_backend() {
723+
let ctx = TestCtx::new();
724+
insta::assert_snapshot!(
725+
ctx
726+
.config("build")
727+
.args(&["--set", "rust.codegen-backends=['llvm', 'cranelift']"])
728+
.render_steps(), @r"
729+
[build] llvm <host>
730+
[build] rustc 0 <host> -> rustc 1 <host>
731+
[build] rustc 0 <host> -> rustc_codegen_cranelift 1 <host>
732+
[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>
736+
[build] rustdoc 1 <host>
737+
"
738+
);
739+
}
740+
721741
#[test]
722742
fn build_compiler_tools() {
723743
let ctx = TestCtx::new();

0 commit comments

Comments
 (0)