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 07d20ee9..14f4a232 100644 --- a/crates/rt/src/lib.rs +++ b/crates/rt/src/lib.rs @@ -34,6 +34,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 85b0555a..7637f18e 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 30365497..394faf3a 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: Option<&::core::ffi::CStr>) -> i32 { + pub(super) fn main(args: Option<&::core::ffi::CStr>) -> i32 { let args = ::flipperzero_test::__macro_support::Args::parse(args); match ::flipperzero_test::__macro_support::run_tests(test_count(), test_list(), args) { Ok(()) => 0, @@ -139,6 +139,19 @@ fn tests_runner_impl(args: TokenStream) -> parse::Result { } } } + + #[cfg(all(test, miri))] + #[start] + fn main(argc: isize, argv: *const *const u8) -> isize { + // TODO: Is there any benefit to Miri in hooking up the binary arguments to + // the test runner? + let ret = __test_runner::main(None); + + // Clean up app state. + ::flipperzero_rt::__macro_support::__wait_for_thread_completion(); + + ret.try_into().unwrap_or(isize::MAX) + } ) .into()) }