diff --git a/examples/hello_rust/Makefile b/examples/hello_rust/Makefile index 6a0b214fd..f96db90e5 100644 --- a/examples/hello_rust/Makefile +++ b/examples/hello_rust/Makefile @@ -31,4 +31,6 @@ MODULE = $(CONFIG_EXAMPLES_HELLO_RUST) MAINSRC = hello_rust_main.rs +RUSTFLAGS += -C panic=abort + include $(APPDIR)/Application.mk diff --git a/examples/hello_rust/hello_rust_main.rs b/examples/hello_rust/hello_rust_main.rs index 6d7aaa59e..3a276e94d 100644 --- a/examples/hello_rust/hello_rust_main.rs +++ b/examples/hello_rust/hello_rust_main.rs @@ -23,16 +23,35 @@ ****************************************************************************/ #![no_main] +#![no_std] + +/**************************************************************************** + * Uses + ****************************************************************************/ + +use core::panic::PanicInfo; /**************************************************************************** * Externs ****************************************************************************/ -extern "C" -{ +extern "C" { pub fn printf(format: *const u8, ...) -> i32; } +/**************************************************************************** + * Private functions + ****************************************************************************/ + +/**************************************************************************** + * Panic handler (needed for [no_std] compilation) + ****************************************************************************/ + +#[panic_handler] +fn panic(_panic: &PanicInfo<'_>) -> ! { + loop {} +} + /**************************************************************************** * Public functions ****************************************************************************/ @@ -42,14 +61,12 @@ extern "C" ****************************************************************************/ #[no_mangle] -pub extern "C" fn hello_rust_main(_argc: i32, _argv: *const *const u8) -> i32 -{ +pub extern "C" fn hello_rust_main(_argc: i32, _argv: *const *const u8) -> i32 { /* "Hello, Rust!!" using printf() from libc */ - unsafe - { + unsafe { printf(b"Hello, Rust!!\n\0" as *const u8); - } + } /* exit with status 0 */