From 49403c778183916a5408b080fb6a25354d855d30 Mon Sep 17 00:00:00 2001 From: chrysn Date: Fri, 2 Apr 2021 19:07:39 +0200 Subject: [PATCH] examples: Add Rust example --- examples/rust-hello-world/Cargo.lock | Bin 0 -> 19452 bytes examples/rust-hello-world/Cargo.toml | 12 ++++++++++++ examples/rust-hello-world/Makefile | 24 ++++++++++++++++++++++++ examples/rust-hello-world/README.md | 24 ++++++++++++++++++++++++ examples/rust-hello-world/src/lib.rs | 15 +++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 examples/rust-hello-world/Cargo.lock create mode 100644 examples/rust-hello-world/Cargo.toml create mode 100644 examples/rust-hello-world/Makefile create mode 100644 examples/rust-hello-world/README.md create mode 100644 examples/rust-hello-world/src/lib.rs diff --git a/examples/rust-hello-world/Cargo.lock b/examples/rust-hello-world/Cargo.lock new file mode 100644 index 0000000000000000000000000000000000000000..353d9fbe439664f5514a0a027d5eb3325b925f8c GIT binary patch literal 19452 zcmchfOLH5^a)tN$6%5{`O-{WZj&Ot{yz<_=i3vtMNmwL71E4hWulH9CiUOc+&MaDY zF(ZP&XgaI1GEbg!3jetJ?}yF)s&5|K6@RAJ!}cj1HYGhie!KdQ`}W*+>Coy`{&w}B zX?MT9{q&Ek|2mA1K5zNs`Ouy#Z};u)>M1?HrpK#RH;2vh{q3hOZMWZSpRfM?N`LzF z`|mHQd`|c6k3T*=r>DkmuhYZ!rfhd%%l7HF-Ru5v^O&CRe=Flz_qUtv&4#D?^ZHYHXyx<%^=bUy zWYfO%YMXb~r<#oI-l*zYj3rqgf(;_uVpXighn~8Wtu)6Ap`3O7`crK$BiiS(X?y<0 z-#=YlKeeawu)F@(Pk$_g_`KiT9op{cB0i~Z<;w9@t5VF_w<1b6!4zv{&?5QLl+RU( z>U>MZ8Q)}XJzJMWZl*OIleJaN#`kseoL)8`#7DYp%FWC6@f#`hcp2rbT{+0+f~(#H zt3%RCE1OlQ&PZ8nNKwbe&RVHLvsDPCOEJA_>vhe>I$`F6E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rI+yX z4N4MQ-_qJ2zry5Ak30_|uFgI1T@9szxw&kG!@Vesh6Qo42+$dB1cGAbV5HUTRmp;D zw?o2Gz;nDnd|)YvVfH?K_R);i?nM+{)zGXhD@)ViQWbni!wt#h;RfK&&Q-+H-UL1i zu8`r9WQI?CHHjZ0^HQ`7r!cSVrlbxScuQ+yLY=bsjFfU0@jl&n55qv6=VHdUhH#dg|(Zg`4TP zUl`r_?u~H^mC?3gg~bTd;8jGznXZ{8JYHtUZcf+~p_qvtuO>#C+3kEo2^+qQ=H{hv zfA6_&zwU4DpO2H@+uMHzcjwH{A6V$OAN-}~i?qH?m41YFjtz)!`FPHos&H#9;k@K^i>n)<8{-4#KG3c%>Ir4oFgG9#Nlo5?! zWiij-_ACK$kx_)Ji5ysNj|}35TL^tzw$KK>5rTtnl0fR3q1TQ9ECaz0H~Lp^8kWh% xwIKZ4b=;`N+zrZyzktx?>kU8~sL2T#)9_tZcs6i`;z2IVm>9wNVkijR{|CvwwS@ox literal 0 HcmV?d00001 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!"); +}