hello_rust: changes for target support

This commit is contained in:
Piet 2022-02-20 23:13:57 +01:00 committed by Xiang Xiao
parent 0baf524def
commit aa2c9e7c33
2 changed files with 26 additions and 7 deletions

View File

@ -31,4 +31,6 @@ MODULE = $(CONFIG_EXAMPLES_HELLO_RUST)
MAINSRC = hello_rust_main.rs
RUSTFLAGS += -C panic=abort
include $(APPDIR)/Application.mk

View File

@ -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,12 +61,10 @@ 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);
}