You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/02/25 15:22:32 UTC

[incubator-nuttx-apps] branch master updated: hello_rust: changes for target support

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new aa2c9e7  hello_rust: changes for target support
aa2c9e7 is described below

commit aa2c9e7c334f7fbdd7c52b6dbd7eeb7947af3901
Author: Piet <pt...@mailbox.org>
AuthorDate: Sun Feb 20 23:13:57 2022 +0100

    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 6a0b214..f96db90 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 6d7aaa5..3a276e9 100644
--- a/examples/hello_rust/hello_rust_main.rs
+++ b/examples/hello_rust/hello_rust_main.rs
@@ -23,17 +23,36 @@
  ****************************************************************************/
 
 #![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 */