From aa2c9e7c334f7fbdd7c52b6dbd7eeb7947af3901 Mon Sep 17 00:00:00 2001 From: Piet Date: Sun, 20 Feb 2022 23:13:57 +0100 Subject: [PATCH] hello_rust: changes for target support --- examples/hello_rust/Makefile | 2 ++ examples/hello_rust/hello_rust_main.rs | 31 ++++++++++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) 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 */