Skip to content

Commit

Permalink
rust: Gate panic messages behind a feature
Browse files Browse the repository at this point in the history
The ability to get the panic message in a custom handler has only been
stabilized in Rust 1.81.  Gate this behind a feature so that CI, which
is using an older version of Rust will still be able to compile.

Users wishing to have panic messages can enable this feature in their
app's Cargo.toml.  This will require them to have a newer Rust
toolchain.

Signed-off-by: David Brown <[email protected]>
  • Loading branch information
d3zd3z committed Sep 10, 2024
1 parent 266eace commit 3506a68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/rust/zephyr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ version = "0.3.7"
# used by the core Zephyr tree, but are needed by zephyr applications.
[build-dependencies]
zephyr-build = { version = "0.1.0", path = "../zephyr-build" }

[features]
default = []

# The panic message is only stabilizesd in Rust 1.81. Gate this behind a feature, as the CI is
# using an older version of Rustc. Users can use this functionality by setting this feature in
# their Cargo.toml.
panic-message = []
3 changes: 2 additions & 1 deletion lib/rust/zephyr/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ use core::panic::PanicInfo;
/// Override rust's panic. This simplistic initial version just hangs in a loop.
#[panic_handler]
fn panic(info :&PanicInfo) -> ! {
#[cfg(CONFIG_PRINTK)]
#[cfg(all(CONFIG_PRINTK, feature = "panic-message"))]
{
printkln!("panic: {}", info.message());
}
let _ = info;
loop {
}
}
Expand Down

0 comments on commit 3506a68

Please sign in to comment.