apps: hello_rust example program

This commit is contained in:
Piet 2022-02-19 14:46:44 +01:00 committed by Xiang Xiao
parent 7df20da96c
commit c1757660a6
4 changed files with 143 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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
}