From f2b419f8d07940018680f73db8aa14a322a90909 Mon Sep 17 00:00:00 2001 From: linuswck Date: Fri, 15 Dec 2023 13:11:05 +0800 Subject: [PATCH] Fix nix build to compilation error at Check Phase - "panic_handler" should not be declared during test - "main" and "std" are needed during test --- src/main.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7ffde0b..a628e7d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ -#![no_main] -#![no_std] +#![cfg_attr(not(test), no_main)] +#![cfg_attr(not(test), no_std)] use cortex_m_rt::entry; use log::info; @@ -10,21 +10,22 @@ mod laser_diode; use device::{boot::bootup, log_setup, sys_timer}; // If RTT is used, print panic info through RTT -#[cfg(feature = "RTT")] +#[cfg(all(feature = "RTT", not(test)))] use { core::panic::PanicInfo, rtt_target::rprintln, }; -#[cfg(feature = "RTT")] +#[cfg(all(feature = "RTT", not(test)))] #[panic_handler] fn panic(info: &PanicInfo) -> ! { rprintln!("{}", info); loop {} } // Otherwise use panic halt -#[cfg(not(feature = "RTT"))] +#[cfg(all(not(feature = "RTT"), not(test)))] use panic_halt as _; +#[cfg(not(test))] #[entry] fn main() -> ! { -- 2.44.2