-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
4b3a894
commit eb2229d
Showing
9 changed files
with
88 additions
and
114 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
*~ | ||
target | ||
Cargo.lock | ||
avr-unknown-gnu-atmega32u4.json | ||
options.mk |
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 |
---|---|---|
@@ -1,13 +1,8 @@ | ||
[package] | ||
name = 'hello' | ||
version = '1.0.0' | ||
authors = ['Itoh Shimon <[email protected]>'] | ||
version = '2.0.0' | ||
authors = ['Itoh Shimon <[email protected]>'] | ||
|
||
[lib] | ||
crate-type = ['staticlib'] | ||
path = 'hello.rs' | ||
|
||
[profile.release] | ||
lto = true | ||
panic = 'abort' | ||
opt-level = 'z' |
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,29 @@ | ||
FROM ubuntu:focal | ||
|
||
RUN set -eux; \ | ||
groupadd -g 1005 builder; \ | ||
useradd -g builder -u 1005 -m -s /bin/bash builder | ||
|
||
RUN set -eux; \ | ||
apt-get update; \ | ||
apt-get install -y --no-install-recommends \ | ||
# for Docker | ||
gosu curl ca-certificates \ | ||
# for makefile | ||
jq make \ | ||
# for rust's libcore | ||
gcc libc6-dev | ||
|
||
RUN set -eux; \ | ||
gosu builder mkdir /home/builder/arduboy-hello-rs; \ | ||
gosu builder mkdir /home/builder/bin | ||
|
||
RUN set -eux; \ | ||
gosu builder bash -c "curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y"; \ | ||
gosu builder bash -c "curl -fsSL https://raw.githubusercontent.com/arduino/arduino-cli/master/install.sh | BINDIR=/home/builder/bin sh" | ||
|
||
COPY --chown=builder:builder Cargo.toml Makefile arduboy-hello-rs.ino hello.rs /home/builder/arduboy-hello-rs/ | ||
|
||
RUN set -eux; \ | ||
cd /home/builder/arduboy-hello-rs; \ | ||
gosu builder bash -c 'export PATH="/home/builder/bin:/home/builder/.cargo/bin:$PATH" && make PORT=fake setup && make' |
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 |
---|---|---|
@@ -1,41 +1,42 @@ | ||
#IDE_PATH := ${HOME}/opt/arduino-1.8.5 | ||
#PORT := /dev/ttyACM0 | ||
.PHONY: all setup cargo build upload verify | ||
|
||
ifndef IDE_PATH | ||
$(error IDE_PATH is not defined) | ||
endif | ||
-include options.mk | ||
|
||
ifndef PORT | ||
$(error PORT is not defined) | ||
$(error PORT is not defined) | ||
else | ||
$(shell printf 'PORT = %s\n' $(PORT) > options.mk) | ||
endif | ||
|
||
SYSROOT := $(shell rustc +avr-toolchain --print sysroot) | ||
BOARD = arduino:avr:leonardo | ||
TARGET = avr-unknown-gnu-atmega32u4 | ||
RECIPE = "$$(arduino-cli compile -b $(BOARD) --show-properties \ | ||
| grep -E '^recipe\.c\.combine\.pattern=.*$$' \ | ||
| sed -r 's@(.*)@\1 target/$(TARGET)/release/libhello.a@')" | ||
|
||
all: build | ||
|
||
setup: | ||
# workaround https://github.com/rust-lang/compiler-builtins/issues/400 | ||
rustup toolchain install nightly-2021-01-07 | ||
rustup override set nightly-2021-01-07 | ||
rustup component add rust-src --toolchain nightly-2021-01-07 | ||
rustc --print target-spec-json -Z unstable-options \ | ||
--target avr-unknown-gnu-atmega328 \ | ||
| sed 's/atmega328/atmega32u4/g' \ | ||
| jq '."is-builtin" = false' \ | ||
> $(TARGET).json | ||
arduino-cli core install arduino:avr | ||
arduino-cli lib install Arduboy | ||
|
||
# TODO Better implementation | ||
# see https://github.com/arduino/Arduino/pull/5338 | ||
IDE_PREF := $(shell grep -E '^recipe\.c\.combine\.pattern=.*$$' \ | ||
'$(IDE_PATH)/hardware/arduino/avr/platform.txt' \ | ||
| sed -r 's@(.*)@\1 target/arduboy/release/libhello.a@') | ||
cargo: | ||
cargo build -Z build-std=core --target $(TARGET).json --release | ||
|
||
build: cargo | ||
arduino-cli compile --fqbn $(BOARD) --build-property $(RECIPE) | ||
|
||
verify: | ||
$(call do_build,--verify) | ||
upload: | ||
$(call do_build,--upload) | ||
|
||
define do_build | ||
: IDE_PATH := $(IDE_PATH) | ||
: PORT := $(PORT) | ||
: SYSROOT := $(SYSROOT) | ||
: IDE_PREF := $(IDE_PREF) | ||
: ----------build-rust-program---------- | ||
RUST_BACKTRACE=1 \ | ||
XARGO_RUST_SRC='$(SYSROOT)/lib/rustlib/src/' \ | ||
RUSTC='$(SYSROOT)/bin/rustc' \ | ||
RUSTDOC='$(SYSROOT)/bin/rustdoc' \ | ||
xargo build -vvv --release --target=arduboy | ||
: ----------build-arduboy-game---------- | ||
'$(IDE_PATH)/arduino' $1 -v --board arduboy:avr:arduboy \ | ||
--port '$(PORT)' --pref '$(IDE_PREF)' ffi.ino | ||
endef | ||
|
||
.PHONY: verify upload | ||
arduino-cli upload --fqbn $(BOARD) --port $(PORT) | ||
|
||
verify: cargo | ||
arduino-cli compile --verify --fqbn $(BOARD) --build-property $(RECIPE) |
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 |
---|---|---|
@@ -1,48 +1,17 @@ | ||
# arduboy-hello-rs | ||
|
||
![hello, arduboy and rust](demo.gif) | ||
## Install | ||
### Install Rust with rustup | ||
<https://www.rust-lang.org/en-US/install.html> | ||
### Install Arduino IDE | ||
<https://www.arduino.cc/en/Main/Software> | ||
### Setup Arduboy | ||
<https://community.arduboy.com/t/quick-start-guide> | ||
Requirement: 「Arduboy」library | ||
### Setup AVR-Rust | ||
~~~~~~~~~~~~~~~~~~~~ | ||
mkdir -p ~/ws/avr-rust-build/build/ | ||
cd ~/ws/avr-rust-build/ | ||
git clone https://github.com/avr-rust/rust.git | ||
(cd rust && git checkout b5a0d3b7b87eafed7499d69bd543648cfb139b0c) | ||
cd build | ||
../rust/configure \ | ||
--enable-debug \ | ||
--disable-docs \ | ||
--enable-llvm-assertions \ | ||
--enable-debug-assertions \ | ||
--enable-optimize | ||
make # Wait for about an hour | ||
rustup toolchain link avr-toolchain "$(realpath "$(find . -name stage2)")" | ||
# ↓for xargo | ||
RUST_SRC="$(rustc +avr-toolchain --print sysroot)/lib/rustlib/src/" | ||
mkdir -p "${RUST_SRC}" | ||
ln -s "$(realpath ../rust/)" "${RUST_SRC}" | ||
~~~~~~~~~~~~~~~~~~~~ | ||
### Setup Xargo | ||
~~~~~~~~~~~~~~~~~~~~ | ||
cargo install xargo | ||
~~~~~~~~~~~~~~~~~~~~ | ||
### Build | ||
~~~~~~~~~~~~~~~~~~~~ | ||
cd ~/ws | ||
git clone https://github.com/simon-i1-h/arduboy-hello-rs.git | ||
cd ~/ws/arduboy-hello-rs | ||
rustup override set avr-toolchain | ||
editor Makefile # edit `IDE_PATH' and `PORT' | ||
make verify # check | ||
make upload | ||
~~~~~~~~~~~~~~~~~~~~ | ||
## Tips | ||
<https://help.ubuntu.com/community/SerialConsoleHowto> | ||
## License | ||
MIT License | ||
|
||
## Build | ||
|
||
Main requirements: | ||
|
||
- `rustup` | ||
- `arduino-cli` | ||
|
||
See also `Dockerfile` for details. | ||
|
||
``` | ||
PORT=/dev/ttyACM0 # e.g. | ||
make PORT=$PORT setup && make && make upload | ||
``` |
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
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