Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Nicer output on nightly #50

Merged
merged 1 commit into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,21 @@ fn main() {
if backend.iter().filter(|&&f| f).count() == 0 {
panic!("A backend needs to be selected");
}

if is_nightly() {
println!("cargo:rustc-cfg=nightly");
}
}

fn is_nightly() -> bool {
let version_output = std::process::Command::new(
std::env::var_os("RUSTC").unwrap_or_else(|| std::ffi::OsString::from("rustc")),
)
.arg("-V")
.output()
.unwrap()
.stdout;
let version_string = String::from_utf8_lossy(&version_output);

version_string.contains("nightly")
}
27 changes: 20 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![allow(rustdoc::bare_urls)]
#![doc = include_str!("../README.md")]
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/46717278")]
#![cfg_attr(nightly, feature(panic_info_message))]

#[cfg(feature = "defmt")]
use defmt as _;
Expand Down Expand Up @@ -57,20 +58,28 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
if let Some(location) = info.location() {
let (file, line, column) = (location.file(), location.line(), location.column());
println!(
"!! A panic occured in '{}', at line {}, column {}",
"!! A panic occured in '{}', at line {}, column {}:",
file, line, column
);
} else {
println!("!! A panic occured at an unknown location");
println!("!! A panic occured at an unknown location:");
}

println!("");
#[cfg(not(nightly))]
{
#[cfg(not(feature = "defmt"))]
println!("{:#?}", info);

#[cfg(not(feature = "defmt"))]
println!("{:#?}", info);
#[cfg(feature = "defmt")]
println!("{:#?}", defmt::Display2Format(info));
}

#[cfg(feature = "defmt")]
println!("{:#?}", defmt::Display2Format(info));
#[cfg(nightly)]
{
if let Some(message) = info.message() {
println!("{}", message);
}
}

println!("");
println!("Backtrace:");
Expand All @@ -83,6 +92,10 @@ fn panic_handler(info: &core::panic::PanicInfo) -> ! {
}
for e in backtrace {
if let Some(addr) = e {
#[cfg(all(feature = "colors", feature = "println"))]
println!("{}0x{:x}", RED, addr - crate::arch::RA_OFFSET);

#[cfg(not(any(feature = "colors", feature = "println")))]
println!("0x{:x}", addr - crate::arch::RA_OFFSET);
}
}
Expand Down
Loading