Skip to content

Commit

Permalink
CI: test no_std on stable rust
Browse files Browse the repository at this point in the history
As of rust 1.80, we no longer need any unstable features to test
`no_std` compatibility.
  • Loading branch information
robamler committed Oct 20, 2024
1 parent f8dfa14 commit 3045761
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
13 changes: 7 additions & 6 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,19 @@ jobs:
env:
RUSTFLAGS: "-D warnings"
run: cargo test

- name: Test in release mode
env:
RUSTFLAGS: "-D warnings"
run: cargo test --release

- name: Test `no_std` compatibility
shell: bash
working-directory: ensure_no_std
run: cargo build

miri-test:
name: no_std and miri
name: miri
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand Down Expand Up @@ -94,11 +100,6 @@ jobs:
toolchain: ${{ steps.rust-version.outputs.rustc }}
components: miri, rust-src

- name: Test `no_std` compatibility
shell: bash
working-directory: ensure_no_std
run: cargo +${{ steps.rust-version.outputs.rustc }} build

- name: Run tests in miri
env:
RUSTFLAGS: "-Zrandomize-layout"
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,13 @@ jobs:
RUSTFLAGS: "-D warnings"
run: cargo test --release

- name: Test `no_std` compatibility
shell: bash
working-directory: ensure_no_std
run: cargo build

miri-test:
name: no_std and miri
name: miri
runs-on: ${{ matrix.os }}
needs: rust-test
strategy:
Expand Down Expand Up @@ -120,11 +125,6 @@ jobs:
toolchain: ${{ steps.rust-version.outputs.rustc }}
components: miri, rust-src

- name: Test `no_std` compatibility
shell: bash
working-directory: ensure_no_std
run: cargo +${{ steps.rust-version.outputs.rustc }} build

- name: Run tests in miri
env:
RUSTFLAGS: "-Zrandomize-layout"
Expand Down
3 changes: 2 additions & 1 deletion ensure_no_std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
edition = "2021"
name = "ensure_no_std"
version = "0.1.0"
rust-version = "1.80.1"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
constriction = {path = "..", default-features = false}
spin = "0.9.8"
talc = "4.2.0"
emma = "0.0.1"

[profile.dev]
panic = "abort"
Expand Down
23 changes: 4 additions & 19 deletions ensure_no_std/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,20 @@
#![no_std]
#![no_main]
#![feature(alloc_error_handler)]
#![feature(const_mut_refs)]

use constriction::stream::{Decode, Encode};
use core::panic::PanicInfo;

use talc::*;

static mut ARENA: [u8; 10000] = [0; 10000];

#[global_allocator]
static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> =
Talc::new(unsafe { ClaimOnOom::new(Span::from_const_array(core::ptr::addr_of!(ARENA))) })
.lock();

#[allow(unused_imports)]
use constriction;
static EMMA: emma::DefaultEmma = emma::DefaultEmma::new();

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
#[allow(clippy::empty_loop)]
loop {}
}

#[alloc_error_handler]
fn alloc_error_handler(layout: core::alloc::Layout) -> ! {
panic!("Can't handle allocation: layout = {:?}", layout);
}

#[no_mangle]
pub extern "C" fn _start() -> ! {
use constriction::stream::{Decode, Encode};

let model = constriction::stream::model::DefaultUniformModel::new(10);

let mut encoder = constriction::stream::stack::DefaultAnsCoder::new();
Expand All @@ -43,5 +27,6 @@ pub extern "C" fn _start() -> ! {
assert_eq!(decoder.decode_symbol(model), Ok(5));
assert_eq!(decoder.decode_symbol(model), Ok(3));

#[allow(clippy::empty_loop)]
loop {}
}

0 comments on commit 3045761

Please sign in to comment.