mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
examples: Add Rust example
This commit is contained in:
parent
72e4c1803f
commit
49403c7781
BIN
examples/rust-hello-world/Cargo.lock
generated
Normal file
BIN
examples/rust-hello-world/Cargo.lock
generated
Normal file
Binary file not shown.
12
examples/rust-hello-world/Cargo.toml
Normal file
12
examples/rust-hello-world/Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "rust-hello-world"
|
||||
version = "0.1.0"
|
||||
authors = ["Christian Amsüss <chrysn@fsfe.org>"]
|
||||
edition = "2018"
|
||||
resolver = "2"
|
||||
|
||||
[lib]
|
||||
crate-type = ["staticlib"]
|
||||
|
||||
[dependencies]
|
||||
riot-wrappers = "0.7"
|
24
examples/rust-hello-world/Makefile
Normal file
24
examples/rust-hello-world/Makefile
Normal file
@ -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
|
24
examples/rust-hello-world/README.md
Normal file
24
examples/rust-hello-world/README.md
Normal file
@ -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.
|
15
examples/rust-hello-world/src/lib.rs
Normal file
15
examples/rust-hello-world/src/lib.rs
Normal file
@ -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!");
|
||||
}
|
Loading…
Reference in New Issue
Block a user