Skip to content

Commit

Permalink
Auto merge of rust-lang#118708 - davidtwco:target-tier-assembly-test,…
Browse files Browse the repository at this point in the history
… 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
bors committed Jan 12, 2024
2 parents bfd799f + 298f9ec commit 1c06737
Show file tree
Hide file tree
Showing 8 changed files with 803 additions and 7 deletions.

This file was deleted.

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
52 changes: 52 additions & 0 deletions src/tools/tidy/src/target_policy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//! 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/";
const REVISION_LINE_START: &str = "// revisions: ";
const EXCEPTIONS: &[&str] = &[
// FIXME: disabled since it fails on CI saying the csky component is missing
"csky_unknown_linux_gnuabiv2",
"csky_unknown_linux_gnuabiv2hf",
];

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 {
if !EXCEPTIONS.contains(&target.as_str()) {
tidy_error!(bad, "{ASSEMBLY_TEST_PATH}: missing assembly test for {target}")
}
}
}
633 changes: 633 additions & 0 deletions tests/assembly/targets/targets-elf.rs

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions tests/assembly/targets/targets-nvptx.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// assembly-output: emit-asm
// ignore-tidy-linelength
// revisions: nvptx64_nvidia_cuda
// [nvptx64_nvidia_cuda] compile-flags: --target nvptx64-nvidia-cuda
// [nvptx64_nvidia_cuda] needs-llvm-components: nvptx

// Sanity-check that each target can produce assembly code.

#![feature(no_core, lang_items)]
#![no_std]
#![no_core]
#![crate_type = "lib"]

#[lang = "sized"]
trait Sized {}

pub fn test() -> u8 {
42
}

// CHECK: .version
93 changes: 93 additions & 0 deletions tests/assembly/targets/targets-pe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// assembly-output: emit-asm
// ignore-tidy-linelength
// revisions: aarch64_pc_windows_msvc
// [aarch64_pc_windows_msvc] compile-flags: --target aarch64-pc-windows-msvc
// [aarch64_pc_windows_msvc] needs-llvm-components: aarch64
// revisions: aarch64_pc_windows_gnullvm
// [aarch64_pc_windows_gnullvm] compile-flags: --target aarch64-pc-windows-gnullvm
// [aarch64_pc_windows_gnullvm] needs-llvm-components: aarch64
// revisions: aarch64_unknown_uefi
// [aarch64_unknown_uefi] compile-flags: --target aarch64-unknown-uefi
// [aarch64_unknown_uefi] needs-llvm-components: aarch64
// revisions: aarch64_uwp_windows_msvc
// [aarch64_uwp_windows_msvc] compile-flags: --target aarch64-uwp-windows-msvc
// [aarch64_uwp_windows_msvc] needs-llvm-components: aarch64
// revisions: avr_unknown_gnu_atmega328
// [avr_unknown_gnu_atmega328] compile-flags: --target avr-unknown-gnu-atmega328
// [avr_unknown_gnu_atmega328] needs-llvm-components: avr
// revisions: bpfeb_unknown_none
// [bpfeb_unknown_none] compile-flags: --target bpfeb-unknown-none
// [bpfeb_unknown_none] needs-llvm-components: bpf
// revisions: bpfel_unknown_none
// [bpfel_unknown_none] compile-flags: --target bpfel-unknown-none
// [bpfel_unknown_none] needs-llvm-components: bpf
// revisions: i586_pc_windows_msvc
// [i586_pc_windows_msvc] compile-flags: --target i586-pc-windows-msvc
// [i586_pc_windows_msvc] needs-llvm-components: x86
// revisions: i686_pc_windows_gnu
// [i686_pc_windows_gnu] compile-flags: --target i686-pc-windows-gnu
// [i686_pc_windows_gnu] needs-llvm-components: x86
// revisions: i686_pc_windows_msvc
// [i686_pc_windows_msvc] compile-flags: --target i686-pc-windows-msvc
// [i686_pc_windows_msvc] needs-llvm-components: x86
// revisions: i686_pc_windows_gnullvm
// [i686_pc_windows_gnullvm] compile-flags: --target i686-pc-windows-gnullvm
// [i686_pc_windows_gnullvm] needs-llvm-components: x86
// revisions: i686_uwp_windows_gnu
// [i686_uwp_windows_gnu] compile-flags: --target i686-uwp-windows-gnu
// [i686_uwp_windows_gnu] needs-llvm-components: x86
// revisions: i686_unknown_uefi
// [i686_unknown_uefi] compile-flags: --target i686-unknown-uefi
// [i686_unknown_uefi] needs-llvm-components: x86
// revisions: i686_uwp_windows_msvc
// [i686_uwp_windows_msvc] compile-flags: --target i686-uwp-windows-msvc
// [i686_uwp_windows_msvc] needs-llvm-components: x86
// revisions: i686_win7_windows_msvc
// [i686_win7_windows_msvc] compile-flags: --target i686-win7-windows-msvc
// [i686_win7_windows_msvc] needs-llvm-components: x86
// revisions: powerpc64_ibm_aix
// [powerpc64_ibm_aix] compile-flags: --target powerpc64-ibm-aix
// [powerpc64_ibm_aix] needs-llvm-components: powerpc
// revisions: thumbv7a_uwp_windows_msvc
// [thumbv7a_uwp_windows_msvc] compile-flags: --target thumbv7a-uwp-windows-msvc
// [thumbv7a_uwp_windows_msvc] needs-llvm-components: arm
// revisions: thumbv7a_pc_windows_msvc
// [thumbv7a_pc_windows_msvc] compile-flags: --target thumbv7a-pc-windows-msvc
// [thumbv7a_pc_windows_msvc] needs-llvm-components: arm
// revisions: x86_64_pc_windows_gnu
// [x86_64_pc_windows_gnu] compile-flags: --target x86_64-pc-windows-gnu
// [x86_64_pc_windows_gnu] needs-llvm-components: x86
// revisions: x86_64_pc_windows_gnullvm
// [x86_64_pc_windows_gnullvm] compile-flags: --target x86_64-pc-windows-gnullvm
// [x86_64_pc_windows_gnullvm] needs-llvm-components: x86
// revisions: x86_64_pc_windows_msvc
// [x86_64_pc_windows_msvc] compile-flags: --target x86_64-pc-windows-msvc
// [x86_64_pc_windows_msvc] needs-llvm-components: x86
// revisions: x86_64_unknown_uefi
// [x86_64_unknown_uefi] compile-flags: --target x86_64-unknown-uefi
// [x86_64_unknown_uefi] needs-llvm-components: x86
// revisions: x86_64_uwp_windows_gnu
// [x86_64_uwp_windows_gnu] compile-flags: --target x86_64-uwp-windows-gnu
// [x86_64_uwp_windows_gnu] needs-llvm-components: x86
// revisions: x86_64_uwp_windows_msvc
// [x86_64_uwp_windows_msvc] compile-flags: --target x86_64-uwp-windows-msvc
// [x86_64_uwp_windows_msvc] needs-llvm-components: x86
// revisions: x86_64_win7_windows_msvc
// [x86_64_win7_windows_msvc] compile-flags: --target x86_64-win7-windows-msvc
// [x86_64_win7_windows_msvc] needs-llvm-components: x86

// Sanity-check that each target can produce assembly code.

#![feature(no_core, lang_items)]
#![no_std]
#![no_core]
#![crate_type = "lib"]

#[lang = "sized"]
trait Sized {}

pub fn test() -> u8 {
42
}

// CHECK: .file

0 comments on commit 1c06737

Please sign in to comment.