Create a Hello World project:
cargo new hello_rpi
cd hello_rpi
Create .cargo/config.toml
in the project directory with the following contents:
[build]
target = "arm-unknown-linux-musleabihf"
rustflags = ["-C", "linker=arm-linux-gnueabihf-gcc"]
Here's a Dockerfile
for building:
FROM rust:buster
RUN rustup target add arm-unknown-linux-musleabihf
RUN apt update && apt-get install -y gcc-arm-linux-gnueabihf
WORKDIR /build
COPY . /build
RUN cargo build --release
And here's deploy.sh
script for running the build, extracting the articfact and deploying it to the Raspberry Pi.
It assumes that the Pi is accessible via SSH with pi@raspberrypi.local
.
#/bin/bash -e
docker build -t hello_rpi:latest .
docker run -d -it --rm --name hello_rpi_artifact hello_rpi:latest
docker cp hello_rpi_artifact:/build/target/arm-unknown-linux-musleabihf/release/hello_rpi .
docker stop hello_rpi_artifact
scp ./hello_rpi pi@raspberrypi.local:~/hello_rpi
rm ./hello_rpi