From b582981eeb0e129de5a7b778d2691f573313f00f Mon Sep 17 00:00:00 2001 From: mcmah309 Date: Wed, 11 Sep 2024 23:22:11 +0000 Subject: [PATCH] chore: Fix no_std ci test --- .github/workflows/ci.yml | 2 +- Cargo.toml | 3 ++- src/lib.rs | 2 +- tests/no_std/.cargo/config.toml | 2 ++ tests/no_std/Cargo.toml | 3 ++- tests/no_std/main.rs | 24 ++++++++++++++++++++++-- 6 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 tests/no_std/.cargo/config.toml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1de7e66..0a9275b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/Cargo.toml b/Cargo.toml index cf19b78..acb3b25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 = [] diff --git a/src/lib.rs b/src/lib.rs index 6bec993..a3cab29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,4 @@ -#![no_std] +#![cfg_attr(not(test), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] #![doc = include_str!("../README.md")] diff --git a/tests/no_std/.cargo/config.toml b/tests/no_std/.cargo/config.toml new file mode 100644 index 0000000..e417ccb --- /dev/null +++ b/tests/no_std/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = ["x86_64-unknown-none"] \ No newline at end of file diff --git a/tests/no_std/Cargo.toml b/tests/no_std/Cargo.toml index 3560151..7b8861e 100644 --- a/tests/no_std/Cargo.toml +++ b/tests/no_std/Cargo.toml @@ -10,8 +10,9 @@ error_set = { path = "../.." } name = "no_std" path = "main.rs" + [profile.dev] panic = "abort" [profile.release] -panic = "abort" +panic = "abort" \ No newline at end of file diff --git a/tests/no_std/main.rs b/tests/no_std/main.rs index 740b998..2bdc529 100644 --- a/tests/no_std/main.rs +++ b/tests/no_std/main.rs @@ -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); } //************************************************************************// @@ -40,7 +60,7 @@ error_set! { }; } -struct TestError(u32); +pub struct TestError(u32); impl TestError { pub fn new(code: u32) -> Self {