diff --git a/crates/.cargo/config.toml b/crates/.cargo/config.toml index c4844541..c1e03de9 100644 --- a/crates/.cargo/config.toml +++ b/crates/.cargo/config.toml @@ -1,6 +1,10 @@ +# Equivalent to [target.thumbv7em-none-eabihf] but also disabing the runner for Miri. +# Until target_abi is stable, this also permits thumbv7em-none-eabi. +[target.'cfg(all(target_arch = "arm", target_feature = "thumb2", target_feature = "v7", target_feature = "dsp", target_os = "none", not(miri)))'] +runner = "python3 ../cargo-runner.py" + [target.thumbv7em-none-eabihf] linker = "./fap-lld.py" -runner = "python3 ../cargo-runner.py" rustflags = [ # CPU is Cortex-M4 (STM32WB55) "-C", "target-cpu=cortex-m4", diff --git a/crates/flipperzero/src/lib.rs b/crates/flipperzero/src/lib.rs index 26d642e0..92d6ef59 100644 --- a/crates/flipperzero/src/lib.rs +++ b/crates/flipperzero/src/lib.rs @@ -5,7 +5,8 @@ //! #![no_std] -#![cfg_attr(test, no_main)] +#![cfg_attr(all(test, not(miri)), no_main)] +#![cfg_attr(all(test, miri), feature(start))] #![cfg_attr(docsrs, feature(doc_cfg))] #![deny(rustdoc::broken_intra_doc_links)] diff --git a/crates/rt/src/lib.rs b/crates/rt/src/lib.rs index d8c95ed7..d479dd15 100644 --- a/crates/rt/src/lib.rs +++ b/crates/rt/src/lib.rs @@ -32,6 +32,7 @@ macro_rules! entry { ($path:path) => { // Force the section to `.text` instead of `.text.main`. // lld seems not to automatically rename `.rel.text.main` properly. + #[cfg(not(miri))] #[export_name = "main"] pub unsafe fn __main(args: *mut u8) -> i32 { // type check the entry function diff --git a/crates/sys/src/lib.rs b/crates/sys/src/lib.rs index d61e607d..f77c9902 100644 --- a/crates/sys/src/lib.rs +++ b/crates/sys/src/lib.rs @@ -5,13 +5,16 @@ // Features that identify thumbv7em-none-eabihf. // Until target_abi is stable, this also permits thumbv7em-none-eabi. -#[cfg(not(all( - target_arch = "arm", - target_feature = "thumb2", - target_feature = "v7", - target_feature = "dsp", - target_os = "none", - //target_abi = "eabihf", +#[cfg(not(any( + all( + target_arch = "arm", + target_feature = "thumb2", + target_feature = "v7", + target_feature = "dsp", + target_os = "none", + //target_abi = "eabihf", + ), + miri )))] core::compile_error!("This crate requires `--target thumbv7em-none-eabihf`"); diff --git a/crates/test/macros/src/lib.rs b/crates/test/macros/src/lib.rs index d1c790c2..68d98f85 100644 --- a/crates/test/macros/src/lib.rs +++ b/crates/test/macros/src/lib.rs @@ -131,7 +131,7 @@ fn tests_runner_impl(args: TokenStream) -> parse::Result { } // Test runner entry point - fn main(args: *mut u8) -> i32 { + pub(super) fn main(args: *mut u8) -> i32 { // SAFETY: Flipper Zero passes arguments to FAPs as a C string. let args = unsafe { ::flipperzero_test::__macro_support::Args::parse(args) }; match ::flipperzero_test::__macro_support::run_tests(test_count(), test_list(), args) { @@ -140,6 +140,17 @@ fn tests_runner_impl(args: TokenStream) -> parse::Result { } } } + + #[cfg(all(test, miri))] + #[start] + fn main(argc: isize, argv: *const *const u8) -> isize { + let ret = __test_runner::main(::core::ptr::null_mut()); + + // Clean up app state. + ::flipperzero_rt::__macro_support::__wait_for_thread_completion(); + + ret.try_into().unwrap_or(isize::MAX) + } ) .into()) }