-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# RIOT rust support makefile | ||
|
||
# make RIOT's linker hook path known to rustc | ||
export RUST_TARGET_PATH ?= $(RIOTBASE)/dist/rust/targets | ||
|
||
# (unfortunately with this set, Cargo somehow fails. Thus we need to keep | ||
# Cargo's build directory in ./target) | ||
#export CARGO_TARGET_DIR ?= $(BINDIR)/_cargo | ||
|
||
# the rust riot crate depends on fmt | ||
USEMODULE += fmt | ||
|
||
ifeq ($(CPU_ARCH), cortex-m0plus) | ||
RUST_TARGET=$(CPU_ARCH) | ||
else ifeq ($(CPU_ARCH),native) | ||
$(error Makefile.rust: RIOT rust on native is currently broken.) | ||
RUST_TARGET=i586-unknown-linux-gnu | ||
endif | ||
|
||
ifeq (, $(RUST_TARGET)) | ||
$(error Makefile.rust: cannot determine rust target triple!) | ||
endif | ||
|
||
all: xargo | ||
|
||
xargo: | ||
@mkdir -p $(BINDIR)/_extra_libs | ||
@PATH=$${PATH}:$(RIOTBASE)/dist/rust xargo build -v --target $(RUST_TARGET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/sh | ||
|
||
[ -z "$BINDIR" ] && { | ||
echo "$0: BINDIR not defined!" 1&>2 | ||
exit 1 | ||
} | ||
|
||
_EXTRA_LIBS=${BINDIR}/_extra_libs | ||
mkdir -p ${_EXTRA_LIBS} | ||
|
||
while true; do | ||
[ -z "$1" ] && exit 0 | ||
[ -f "$1" ] && { | ||
if [[ "$1" == *.o ]]; then | ||
${AR} r ${_EXTRA_LIBS}/_objects.a $1 | ||
elif [[ "$1" == *.rlib ]]; then | ||
cp $1 ${_EXTRA_LIBS}/$(basename $1).a | ||
fi | ||
} | ||
shift | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"arch": "arm", | ||
"cpu": "cortex-m0plus", | ||
"data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", | ||
"executables": true, | ||
"linker": "riot-rust-linker-hook", | ||
"llvm-target": "thumbv6m-none-eabi", | ||
"no-compiler-rt": true, | ||
"os": "none", | ||
"pre-link-args": [ ], | ||
"relocation-model": "static", | ||
"target-endian": "little", | ||
"target-pointer-width": "32" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "app" | ||
version = "0.1.0" | ||
authors = ["Kaspar Schleiser <[email protected]>"] | ||
|
||
[dependencies] | ||
riot = "0.1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# name of your application | ||
APPLICATION = rust | ||
|
||
# This has to be the absolute path to the RIOT base directory: | ||
RIOTBASE ?= $(CURDIR)/../.. | ||
|
||
# Change this to 0 show compiler invocation lines by default: | ||
QUIET ?= 1 | ||
|
||
# tested only on samr21-xpro | ||
BOARD_WHITELIST := samr21-xpro | ||
|
||
# If no BOARD is found in the environment, use this default: | ||
BOARD ?= samr21-xpro | ||
|
||
# use this to enable rust support. | ||
# the current directory will be built using xargo. | ||
CARGO_BUILD=1 | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Introduction | ||
|
||
"Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety." | ||
|
||
This example shows how to write a RIOT application using Rust. | ||
|
||
# Status | ||
|
||
As Rust's libstd is too fat for our little MCUs, it is currently only possible | ||
to write Rust applications using ```#![no_std]```. | ||
There's a crate on crate.io trying to map RIOT's API to rust, but that is in | ||
very early stages. | ||
|
||
# Prerequisites | ||
|
||
You'll need a Rust nightly toolchain and xargo. | ||
|
||
This should get you started: | ||
|
||
# curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain=nightly | ||
# . ~/.cargo/env | ||
# cargo install xargo | ||
|
||
# Trying the example | ||
|
||
As always, | ||
|
||
# BOARD=samr21-xpro make clean all flash term | ||
|
||
is all you need. | ||
|
||
# Internals | ||
|
||
RIOT's make system intercepts cargo's linking step and just copies the objects | ||
and archives cargo tries to link into RIOT's build dir, then just links | ||
everything together. | ||
|
||
# Known issues | ||
|
||
- currently this works only for Atmel Sam R21 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#![feature(lang_items)] | ||
#![no_main] | ||
#![no_std] | ||
|
||
mod lang_items { | ||
#[lang = "panic_fmt"] | ||
extern fn panic_fmt() {} | ||
|
||
#[lang = "eh_personality"] | ||
fn eh_personality() {} | ||
} | ||
|
||
// user code starts here | ||
|
||
extern crate riot; | ||
|
||
#[no_mangle] | ||
pub fn main() { | ||
riot::fmt::print("Hello from RUST!\n"); | ||
} |