From a4d824819db3c6305057476b59963774338af7c9 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sat, 29 Jul 2023 17:02:30 +0900 Subject: [PATCH] ci: Run no-std test also on stable --- .github/workflows/ci.yml | 10 ++++++++++ tests/no-std-qemu/Cargo.toml | 15 ++++++++++++++- tests/no-std-qemu/build.rs | 33 +++++++++++++++++++++++++++++++++ tests/no-std-qemu/src/main.rs | 19 ++++++++----------- tools/build.sh | 3 ++- 5 files changed, 67 insertions(+), 13 deletions(-) create mode 100644 tests/no-std-qemu/build.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2ad066a..5bf7e82e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -370,6 +370,12 @@ jobs: no-std: needs: tidy + strategy: + fail-fast: false + matrix: + rust: + - stable + - nightly runs-on: ubuntu-latest timeout-minutes: 60 steps: @@ -384,6 +390,7 @@ jobs: tool: espup env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: startsWith(matrix.rust, 'nightly') - run: | set -euxo pipefail sudo apt-get -o Acquire::Retries=10 -qq update && sudo apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends \ @@ -402,9 +409,12 @@ jobs: - run: espup install env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + if: startsWith(matrix.rust, 'nightly') - run: tools/no-std.sh - run: tools/build.sh +esp xtensa-esp32-none-elf + if: startsWith(matrix.rust, 'nightly') - run: tools/no-std.sh +esp xtensa-esp32-none-elf + if: startsWith(matrix.rust, 'nightly') miri: needs: tidy diff --git a/tests/no-std-qemu/Cargo.toml b/tests/no-std-qemu/Cargo.toml index 8e8f522f..6106d5da 100644 --- a/tests/no-std-qemu/Cargo.toml +++ b/tests/no-std-qemu/Cargo.toml @@ -14,7 +14,20 @@ test-helper = { path = "../helper" } paste = "1" semihosting = { version = "0.1", features = ["stdio", "panic-handler"] } -[target.'cfg(all(target_arch = "arm", target_feature = "mclass"))'.dependencies] +# cfg(target_feature = "mclass") is not available on stable/beta. +[target.thumbv6m-none-eabi.dependencies] +cortex-m-rt = "0.7" +[target.thumbv7m-none-eabi.dependencies] +cortex-m-rt = "0.7" +[target.thumbv7em-none-eabi.dependencies] +cortex-m-rt = "0.7" +[target.thumbv7em-none-eabihf.dependencies] +cortex-m-rt = "0.7" +[target.'thumbv8m.base-none-eabi'.dependencies] +cortex-m-rt = "0.7" +[target.'thumbv8m.main-none-eabi'.dependencies] +cortex-m-rt = "0.7" +[target.'thumbv8m.main-none-eabihf'.dependencies] cortex-m-rt = "0.7" [profile.dev] diff --git a/tests/no-std-qemu/build.rs b/tests/no-std-qemu/build.rs new file mode 100644 index 00000000..df63111a --- /dev/null +++ b/tests/no-std-qemu/build.rs @@ -0,0 +1,33 @@ +use std::env; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + + let target = &*env::var("TARGET").expect("TARGET not set"); + let target_arch = &*env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set"); + + if target_arch == "arm" { + let mut subarch = + target.strip_prefix("arm").or_else(|| target.strip_prefix("thumb")).unwrap(); + subarch = subarch.strip_prefix("eb").unwrap_or(subarch); // ignore endianness + subarch = subarch.split('-').next().unwrap(); // ignore vender/os/env + subarch = subarch.split('.').next().unwrap(); // ignore .base/.main suffix + match subarch { + "v6m" | "v7em" | "v7m" | "v8m" => println!("cargo:rustc-cfg=mclass"), + "v5te" => println!("cargo:rustc-cfg=armv5te"), + _ => {} + } + } + if target_arch.starts_with("riscv") { + let mut subarch = target.strip_prefix(target_arch).unwrap(); + subarch = subarch.split('-').next().unwrap(); + if subarch.contains('f') || subarch.contains('d') || subarch.contains('g') { + println!("cargo:rustc-cfg=f") + } + if subarch.contains('d') || subarch.contains('g') { + println!("cargo:rustc-cfg=d") + } + } + + println!("cargo:rustc-check-cfg=names(mclass,armv5te,f,d)"); +} diff --git a/tests/no-std-qemu/src/main.rs b/tests/no-std-qemu/src/main.rs index 359945e3..c072d985 100644 --- a/tests/no-std-qemu/src/main.rs +++ b/tests/no-std-qemu/src/main.rs @@ -11,20 +11,20 @@ use core::sync::atomic::Ordering; use portable_atomic::*; use semihosting::{print, println}; -#[cfg(all(target_arch = "arm", target_feature = "mclass"))] +#[cfg(mclass)] #[cortex_m_rt::entry] fn main() -> ! { run(); semihosting::process::exit(0) } -#[cfg(not(all(target_arch = "arm", target_feature = "mclass")))] +#[cfg(not(mclass))] #[no_mangle] unsafe fn _start(_: usize, _: usize) -> ! { #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] unsafe { core::arch::asm!("la sp, _stack"); } - #[cfg(all(target_arch = "arm", not(target_feature = "v6"), target_feature = "v5te"))] + #[cfg(armv5te)] unsafe { #[instruction_set(arm::a32)] #[inline] @@ -52,10 +52,7 @@ fn run() { } }; } - #[cfg_attr( - any(target_arch = "riscv32", target_arch = "riscv64"), - cfg(any(target_feature = "f", target_feature = "d")) - )] + #[cfg_attr(any(target_arch = "riscv32", target_arch = "riscv64"), cfg(f))] macro_rules! test_atomic_float { ($float_type:ident) => { paste::paste! { @@ -90,7 +87,7 @@ fn run() { } // TODO: undefined reference to `__sync_synchronize' - #[cfg(not(all(target_arch = "arm", not(target_feature = "v6"))))] + #[cfg(not(armv5te))] for &order in &test_helper::FENCE_ORDERINGS { fence(order); compiler_fence(order); @@ -110,9 +107,9 @@ fn run() { test_atomic_int!(u64); test_atomic_int!(i128); test_atomic_int!(u128); - // TODO - #[cfg_attr(any(target_arch = "riscv32", target_arch = "riscv64"), cfg(target_feature = "f"))] + // TODO: undefined reference to f{max,min}{,f} + #[cfg_attr(any(target_arch = "riscv32", target_arch = "riscv64"), cfg(f))] test_atomic_float!(f32); - #[cfg_attr(any(target_arch = "riscv32", target_arch = "riscv64"), cfg(target_feature = "d"))] + #[cfg_attr(any(target_arch = "riscv32", target_arch = "riscv64"), cfg(d))] test_atomic_float!(f64); } diff --git a/tools/build.sh b/tools/build.sh index 1bc7eb4e..a76addee 100755 --- a/tools/build.sh +++ b/tools/build.sh @@ -259,7 +259,7 @@ export CARGO_TARGET_DIR="${target_dir}" has_asm='' # asm! requires 1.59 # concat! in asm! requires 1.46.0-nightly (nightly-2020-06-21). -if [[ "${rustc_minor_version}" -ge 59 ]] || [[ "${rustc_minor_version}" -ge 46 ]] && [[ -n "${nightly}" ]]; then +if [[ "${rustc_minor_version}" -ge 59 ]] || { [[ "${rustc_minor_version}" -ge 46 ]] && [[ -n "${nightly}" ]]; }; then has_asm='1' fi has_offline='' @@ -509,6 +509,7 @@ build() { fi fi fi + offline=() RUSTFLAGS="${target_rustflags}" \ x_cargo "${args[@]}" "$@" offline=(--offline)