diff --git a/examples/rust-hello-world/Cargo.lock b/examples/rust-hello-world/Cargo.lock new file mode 100644 index 0000000000..353d9fbe43 Binary files /dev/null and b/examples/rust-hello-world/Cargo.lock differ diff --git a/examples/rust-hello-world/Cargo.toml b/examples/rust-hello-world/Cargo.toml new file mode 100644 index 0000000000..443cf57cf2 --- /dev/null +++ b/examples/rust-hello-world/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "rust-hello-world" +version = "0.1.0" +authors = ["Christian Amsüss "] +edition = "2018" +resolver = "2" + +[lib] +crate-type = ["staticlib"] + +[dependencies] +riot-wrappers = "0.7" diff --git a/examples/rust-hello-world/Makefile b/examples/rust-hello-world/Makefile new file mode 100644 index 0000000000..c411d26d26 --- /dev/null +++ b/examples/rust-hello-world/Makefile @@ -0,0 +1,24 @@ +# name of your application +APPLICATION = hello-world + +# If no BOARD is found in the environment, use this default: +BOARD ?= native + +# This has to be the absolute path to the RIOT base directory: +RIOTBASE ?= $(CURDIR)/../.. + +# Comment this out to disable code in RIOT that does safety checking +# which is not needed in a production environment but helps in the +# development process: +DEVELHELP ?= 1 + +# Change this to 0 show compiler invocation lines by default: +QUIET ?= 1 + +# The name of crate (as per Cargo.toml package name, but with '-' replaced with '_') +APPLICATION_RUST_MODULE = rust_hello_world +BASELIBS += $(APPLICATION_RUST_MODULE).module + +FEATURES_REQUIRED += rust_target + +include $(RIOTBASE)/Makefile.include diff --git a/examples/rust-hello-world/README.md b/examples/rust-hello-world/README.md new file mode 100644 index 0000000000..d76953389a --- /dev/null +++ b/examples/rust-hello-world/README.md @@ -0,0 +1,24 @@ +Hello World! +============ + +This is a basic example how to use Rust to write your RIOT application. +It prints out the famous text `Hello World!`. + +This example should foremost give you an overview how an application built +completely in Rust is structured: + +* The Makefile resembles the regular application Makefile, see ../hello-world/ + for more introduction to that. + +* The Cargo.toml file describes the Rust code, and declares its dependencies. + + Prominently, it contains a `[lib]` / `crate-type = ["staticlib"]` section, + which is necessary for how RIOT later links together the C and Rust portions. + +* The file src/lib.rs (and any modules referenced by it) contain Rust code to + be run. + + It uses the `riot_main!` macro provided by the riot-wrappers crate to declare + the entry point of the program. + +The code itself looks like the usual Rust hello-world example. diff --git a/examples/rust-hello-world/src/lib.rs b/examples/rust-hello-world/src/lib.rs new file mode 100644 index 0000000000..f4ad7a8fc4 --- /dev/null +++ b/examples/rust-hello-world/src/lib.rs @@ -0,0 +1,15 @@ +// Copyright (C) 2020 Christian Amsüss +// +// This file is subject to the terms and conditions of the GNU Lesser +// General Public License v2.1. See the file LICENSE in the top level +// directory for more details. +#![no_std] + +use riot_wrappers::riot_main; +use riot_wrappers::println; + +riot_main!(main); + +fn main() { + println!("Hello Rust!"); +}