Skip to content

Commit

Permalink
Rollup merge of rust-lang#118708 - davidtwco:target-tier-assembly-tes…
Browse files Browse the repository at this point in the history
…t, r=Mark-Simulacrum

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.

cc rust-lang/compiler-team#655
r? `@wesleywiser`
  • Loading branch information
matthiaskrgr authored Dec 11, 2023
2 parents 69a6867 + 6c993e4 commit 6b4a947
Show file tree
Hide file tree
Showing 5 changed files with 755 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/doc/rustc/src/target-tier-policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ approved by the appropriate team for that shared code before acceptance.
introducing unconditional uses of features that another variation of the
target may not have; use conditional compilation or runtime detection, as
appropriate, to let each target run code supported by that target.
- Tier 3 targets must be able to produce assembly using at least one of
rustc's supported backends from any host target.

If a tier 3 target stops meeting these requirements, or the target maintainers
no longer have interest or time, or the target shows no signs of activity and
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub mod pal;
pub mod rustdoc_css_themes;
pub mod rustdoc_gui_tests;
pub mod style;
pub mod target_policy;
pub mod target_specific_tests;
pub mod tests_placement;
pub mod ui_tests;
Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fn main() {
// Checks that only make sense for the compiler.
check!(error_codes, &root_path, &[&compiler_path, &librustdoc_path], verbose);
check!(fluent_alphabetical, &compiler_path, bless);
check!(target_policy, &root_path);

// Checks that only make sense for the std libs.
check!(pal, &library_path);
Expand Down
45 changes: 45 additions & 0 deletions src/tools/tidy/src/target_policy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//! Tests for target tier policy compliance.
//!
//! As of writing, only checks that sanity-check assembly test for targets doesn't miss any targets.
use crate::walk::{filter_not_rust, walk};
use std::{collections::HashSet, path::Path};

const TARGET_DEFINITIONS_PATH: &str = "compiler/rustc_target/src/spec/targets/";
const ASSEMBLY_TEST_PATH: &str = "tests/assembly/targets.rs";
const REVISION_LINE_START: &str = "// revisions: ";

pub fn check(root_path: &Path, bad: &mut bool) {
let mut targets_to_find = HashSet::new();

let definitions_path = root_path.join(TARGET_DEFINITIONS_PATH);
for defn in ignore::WalkBuilder::new(&definitions_path)
.max_depth(Some(1))
.filter_entry(|e| !filter_not_rust(e.path()))
.build()
{
let defn = defn.unwrap();
// Skip directory itself.
if defn.path() == definitions_path {
continue;
}

let path = defn.path();
let target_name = path.file_stem().unwrap().to_string_lossy().into_owned();
let _ = targets_to_find.insert(target_name);
}

walk(&root_path.join(ASSEMBLY_TEST_PATH), |_, _| false, &mut |_, contents| {
for line in contents.lines() {
let Some(_) = line.find(REVISION_LINE_START) else {
continue;
};
let (_, target_name) = line.split_at(REVISION_LINE_START.len());
targets_to_find.remove(target_name);
}
});

for target in targets_to_find {
tidy_error!(bad, "{ASSEMBLY_TEST_PATH}: missing assembly test for {target}")
}
}
Loading

0 comments on commit 6b4a947

Please sign in to comment.