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 c175766  apps: hello_rust example program
c175766 is described below

commit c1757660a6875e84ed4cc07b69a8126775f5cef5
Author: Piet <p...@mailbox.org>
AuthorDate: Sat Feb 19 14:46:44 2022 +0100

    apps: hello_rust example program
---
 examples/hello_rust/Kconfig            | 29 +++++++++++++++++
 examples/hello_rust/Make.defs          | 23 ++++++++++++++
 examples/hello_rust/Makefile           | 34 ++++++++++++++++++++
 examples/hello_rust/hello_rust_main.rs | 57 ++++++++++++++++++++++++++++++++++
 4 files changed, 143 insertions(+)

diff --git a/examples/hello_rust/Kconfig b/examples/hello_rust/Kconfig
new file mode 100644
index 0000000..92e3b1f
--- /dev/null
+++ b/examples/hello_rust/Kconfig
@@ -0,0 +1,29 @@
+#
+# For a description of the syntax of this configuration file,
+# see the file kconfig-language.txt in the NuttX tools repository.
+#
+
+config EXAMPLES_HELLO_RUST
+       tristate "\"Hello, Rust!\" example"
+       default n
+       ---help---
+               Enable the \"Hello, Rust!\" example
+
+if EXAMPLES_HELLO_RUST
+
+config EXAMPLES_HELLO_RUST_PROGNAME
+       string "Program name"
+       default "hello_rust"
+       ---help---
+               This is the name of the program that will be used when the
+               program is installed.
+
+config EXAMPLES_HELLO_RUST_PRIORITY
+       int "Hello Rust task priority"
+       default 100
+
+config EXAMPLES_HELLO_RUST_STACKSIZE
+       int "Hello Rust stack size"
+       default DEFAULT_TASK_STACKSIZE
+
+endif
diff --git a/examples/hello_rust/Make.defs b/examples/hello_rust/Make.defs
new file mode 100644
index 0000000..245662e
--- /dev/null
+++ b/examples/hello_rust/Make.defs
@@ -0,0 +1,23 @@
+############################################################################
+# apps/examples/hello_rust/Make.defs
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+ifneq ($(CONFIG_EXAMPLES_HELLO_RUST),)
+CONFIGURED_APPS += $(APPDIR)/examples/hello_rust
+endif
diff --git a/examples/hello_rust/Makefile b/examples/hello_rust/Makefile
new file mode 100644
index 0000000..6a0b214
--- /dev/null
+++ b/examples/hello_rust/Makefile
@@ -0,0 +1,34 @@
+############################################################################
+# apps/examples/hello_rust/Make.defs
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.  The
+# ASF licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the
+# License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+# License for the specific language governing permissions and limitations
+# under the License.
+#
+############################################################################
+
+include $(APPDIR)/Make.defs
+
+# Hello, Rust! built-in application info
+
+PROGNAME  = $(CONFIG_EXAMPLES_HELLO_RUST_PROGNAME)
+PRIORITY  = $(CONFIG_EXAMPLES_HELLO_RUST_PRIORITY)
+STACKSIZE = $(CONFIG_EXAMPLES_HELLO_RUST_STACKSIZE)
+MODULE    = $(CONFIG_EXAMPLES_HELLO_RUST)
+
+# Hello, Rust! Example
+
+MAINSRC = hello_rust_main.rs
+
+include $(APPDIR)/Application.mk
diff --git a/examples/hello_rust/hello_rust_main.rs 
b/examples/hello_rust/hello_rust_main.rs
new file mode 100644
index 0000000..6d7aaa5
--- /dev/null
+++ b/examples/hello_rust/hello_rust_main.rs
@@ -0,0 +1,57 @@
+/****************************************************************************
+ * apps/examples/hello_rust/hello_rust_main.rs
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Attributes
+ ****************************************************************************/
+
+#![no_main]
+
+/****************************************************************************
+ * Externs
+ ****************************************************************************/
+
+extern "C"
+{
+    pub fn printf(format: *const u8, ...) -> i32;
+}
+
+/****************************************************************************
+ * Public functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * hello_rust_main
+ ****************************************************************************/
+
+#[no_mangle]
+pub extern "C" fn hello_rust_main(_argc: i32, _argv: *const *const u8) -> i32
+{
+    /* "Hello, Rust!!" using printf() from libc */
+
+    unsafe
+      {
+        printf(b"Hello, Rust!!\n\0" as *const u8);
+      }
+
+    /* exit with status 0 */
+
+    0
+}

Reply via email to