From 5640d8e78ec5a24b81d0bbe88d7c61d1f01d5d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Quentin?= Date: Wed, 7 Feb 2024 14:12:26 +0100 Subject: [PATCH] Fix: println without colors not printing (#53) * Fix conditions * Better CI checks * Speed-up CI --- .github/workflows/ci.yml | 35 +++++++++++++++++++++++++++++++---- src/lib.rs | 12 ++++++++++-- 2 files changed, 41 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63176cd..a3e80fc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,11 +15,14 @@ jobs: check-riscv: name: Check RISC-V runs-on: ubuntu-latest + env: + RUSTFLAGS: -Dwarnings strategy: fail-fast: false matrix: chip: [esp32c2, esp32c3, esp32c6, esp32h2, esp32p4] - printer: ["esp-println/uart"] + colors: ["colors"] + method: ["println"] steps: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@v1 @@ -28,16 +31,19 @@ jobs: toolchain: nightly components: rust-src - uses: Swatinem/rust-cache@v2 - - run: cargo check -Zbuild-std=core --target=riscv32imc-unknown-none-elf --features=${{ matrix.chip }},panic-handler,exception-handler,println,${{ matrix.printer }} + - run: cargo check -Zbuild-std=core --target=riscv32imc-unknown-none-elf --no-default-features --features=esp-println/uart,${{ matrix.chip }},panic-handler,exception-handler,${{ matrix.method }},${{ matrix.colors }} check-xtensa: name: Check Xtensa runs-on: ubuntu-latest + env: + RUSTFLAGS: -Dwarnings strategy: fail-fast: false matrix: chip: [esp32, esp32s2, esp32s3] - printer: ["esp-println/uart"] + colors: ["colors"] + method: ["println"] steps: - uses: actions/checkout@v3 - uses: esp-rs/xtensa-toolchain@v1.5 @@ -45,4 +51,25 @@ jobs: default: true ldproxy: false - uses: Swatinem/rust-cache@v2 - - run: cargo check -Zbuild-std=core --target=xtensa-${{ matrix.chip }}-none-elf --features=${{ matrix.chip }},panic-handler,exception-handler,println,${{ matrix.printer }} + - run: cargo check -Zbuild-std=core --target=xtensa-${{ matrix.chip }}-none-elf --no-default-features --features=esp-println/uart,${{ matrix.chip }},panic-handler,exception-handler,${{ matrix.method }},${{ matrix.colors }} + + check-features: + name: Check unusual feature combinations + runs-on: ubuntu-latest + env: + RUSTFLAGS: -Dwarnings + strategy: + fail-fast: false + matrix: + chip: [esp32c3] + colors: ["colors", ""] + method: ["println","defmt"] + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@v1 + with: + target: riscv32imc-unknown-none-elf + toolchain: nightly + components: rust-src + - uses: Swatinem/rust-cache@v2 + - run: cargo check -Zbuild-std=core --target=riscv32imc-unknown-none-elf --no-default-features --features=esp-println/uart,${{ matrix.chip }},panic-handler,exception-handler,${{ matrix.method }},${{ matrix.colors }} diff --git a/src/lib.rs b/src/lib.rs index e4ffa0e..206895f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,11 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! { #[cfg(nightly)] { if let Some(message) = info.message() { + #[cfg(not(feature = "defmt"))] println!("{}", message); + + #[cfg(feature = "defmt")] + println!("{}", defmt::Display2Format(message)); } } @@ -95,7 +99,7 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! { #[cfg(all(feature = "colors", feature = "println"))] println!("{}0x{:x}", RED, addr - crate::arch::RA_OFFSET); - #[cfg(not(any(feature = "colors", feature = "println")))] + #[cfg(not(all(feature = "colors", feature = "println")))] println!("0x{:x}", addr - crate::arch::RA_OFFSET); } } @@ -192,7 +196,11 @@ fn exception_handler(context: &arch::TrapFrame) -> ! { } for e in backtrace { if let Some(addr) = e { - println!("0x{:x}", addr); + #[cfg(all(feature = "colors", feature = "println"))] + println!("{}0x{:x}", RED, addr - crate::arch::RA_OFFSET); + + #[cfg(not(all(feature = "colors", feature = "println")))] + println!("0x{:x}", addr - crate::arch::RA_OFFSET); } } }