Skip to content

Commit 51aa2e7

Browse files
committed
tests: add sanity-check assembly test for every target
Adds a basic assembly test checking that each target can produce assembly and update the target tier policy to require this. Signed-off-by: David Wood <david@davidtw.co>
1 parent f90f898 commit 51aa2e7

File tree

5 files changed

+749
-0
lines changed

5 files changed

+749
-0
lines changed

Diff for: src/doc/rustc/src/target-tier-policy.md

+2
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ approved by the appropriate team for that shared code before acceptance.
246246
introducing unconditional uses of features that another variation of the
247247
target may not have; use conditional compilation or runtime detection, as
248248
appropriate, to let each target run code supported by that target.
249+
- Tier 3 targets must be able to produce assembly using at least one of
250+
rustc's supported backends from any host target.
249251

250252
If a tier 3 target stops meeting these requirements, or the target maintainers
251253
no longer have interest or time, or the target shows no signs of activity and

Diff for: src/tools/tidy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ pub mod pal;
7070
pub mod rustdoc_css_themes;
7171
pub mod rustdoc_gui_tests;
7272
pub mod style;
73+
pub mod target_policy;
7374
pub mod target_specific_tests;
7475
pub mod tests_placement;
7576
pub mod ui_tests;

Diff for: src/tools/tidy/src/main.rs

+1
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ fn main() {
109109
// Checks that only make sense for the compiler.
110110
check!(error_codes, &root_path, &[&compiler_path, &librustdoc_path], verbose);
111111
check!(fluent_alphabetical, &compiler_path, bless);
112+
check!(target_policy, &root_path);
112113

113114
// Checks that only make sense for the std libs.
114115
check!(pal, &library_path);

Diff for: src/tools/tidy/src/target_policy.rs

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//! Tests for target tier policy compliance.
2+
//!
3+
//! As of writing, only checks that sanity-check assembly test for targets doesn't miss any targets.
4+
5+
use crate::walk::{filter_not_rust, walk};
6+
use std::{collections::HashSet, path::Path};
7+
8+
const TARGET_DEFINITIONS_PATH: &str = "compiler/rustc_target/src/spec/targets/";
9+
const ASSEMBLY_TEST_PATH: &str = "tests/assembly/targets.rs";
10+
const REVISION_LINE_START: &str = "// revisions: ";
11+
12+
pub fn check(root_path: &Path, bad: &mut bool) {
13+
let mut targets_to_find = HashSet::new();
14+
15+
let definitions_path = root_path.join(TARGET_DEFINITIONS_PATH);
16+
for defn in ignore::WalkBuilder::new(&definitions_path)
17+
.max_depth(Some(1))
18+
.filter_entry(|e| !filter_not_rust(e.path()))
19+
.build()
20+
{
21+
let defn = defn.unwrap();
22+
// Skip directory itself.
23+
if defn.path() == definitions_path {
24+
continue;
25+
}
26+
27+
let path = defn.path();
28+
let target_name = path.file_stem().unwrap().to_string_lossy().into_owned();
29+
let _ = targets_to_find.insert(target_name);
30+
}
31+
32+
walk(&root_path.join(ASSEMBLY_TEST_PATH), |_, _| false, &mut |_, contents| {
33+
for line in contents.lines() {
34+
let Some(_) = line.find(REVISION_LINE_START) else {
35+
continue;
36+
};
37+
let (_, target_name) = line.split_at(REVISION_LINE_START.len());
38+
targets_to_find.remove(target_name);
39+
}
40+
});
41+
42+
for target in targets_to_find {
43+
tidy_error!(bad, "{ASSEMBLY_TEST_PATH}: missing assembly test for {target}")
44+
}
45+
}

0 commit comments

Comments
 (0)