Skip to content

Commit

Permalink
chore: Fix no_std ci test
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmah309 committed Sep 11, 2024
1 parent 60c4442 commit b582981
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ jobs:
- name: Run std tests
run: cargo test --verbose --tests
- name: Run no_std tests
run: cargo run --manifest-path tests/no_std/Cargo.toml
run: rustup target add x86_64-unknown-none && cd tests/no_std/ && cargo run
- name: Run feature flags tests
run: cargo test --tests --features coerce_macro && cargo test --tests --features tracing && cargo test --tests --features log
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ tracing-test = { version = "0.2", features = ["no-env-filter"] }
lazy_static = "1"

[workspace]
members = ["impl", "tests/no_std"]
members = ["impl"]
exclude = ["tests/no_std"]

[features]
default = []
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![no_std]
#![cfg_attr(not(test), no_std)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("../README.md")]

Expand Down
2 changes: 2 additions & 0 deletions tests/no_std/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
target = ["x86_64-unknown-none"]
3 changes: 2 additions & 1 deletion tests/no_std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ error_set = { path = "../.." }
name = "no_std"
path = "main.rs"


[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"
panic = "abort"
24 changes: 22 additions & 2 deletions tests/no_std/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,29 @@
#![no_std]
#![no_main]

use error_set::{error_set, CoerceResult};

fn main() {
#[no_mangle]
pub extern "C" fn _start() -> ! {
readme_example();
exit(0);
}

fn exit(code: i32) -> ! {
unsafe {
core::arch::asm!(
"mov rax, 60", // Syscall number for exit
"mov rdi, {0}", // Exit code
"syscall", // Trigger the syscall
in(reg) code,
options(noreturn)
);
}
}

#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
exit(1);
}

//************************************************************************//
Expand Down Expand Up @@ -40,7 +60,7 @@ error_set! {
};
}

struct TestError(u32);
pub struct TestError(u32);

impl TestError {
pub fn new(code: u32) -> Self {
Expand Down

0 comments on commit b582981

Please sign in to comment.