Getting Started

If you want to automate this process with Docker, take a look at cross!

This guide covers how to set up your linux computer to compile , upload , and run a Rust binary on your Raspberry Pi. In order to do this, you'll need to:

Download the standard library that's compatible with your Pi.

Download the Linker for the Cortex-A Family.

Upload & run the binary on your Pi.

Before moving on, make sure you have a Pi that's connected to WiFi and has SSH enabled.

Install the Standard Library for your Pi

Assuming that Rust is already installed, download the compatible standard library on your computer.

rustup target add arm-unknown-linux-gnueabihf rustup target add armv7-unknown-linux-gnueabihf

Download the GNU Toolchain

We're installing this from source to stay distro agnostic.

Next we need to get a compatible Arm linker for Rust to compile against. Download any Linux Toolchain version for the desired target.

You may have to search through previous releases to find what you want.

GNU Toolchain Downloads Pi 0/1 : AArch32 target with hard float (arm-linux-gnueabihf) Pi 2/3/4 : AArch32 target with hard float (arm-none-linux-gnueabihf)



Unzip it, and add the binaries to your $PATH .

export PATH= " $HOME /PATH_TO_YOUR_DOWNLOAD/PATH_TO_TOOLCHAIN_FOLDER/bin: $PATH "

Create a Cargo Project

It's almost ready! All that's left is to create and configure a cargo project.

cargo new pi_project mkdir pi_project/.cargo cd ./pi_project/.cargo touch config.toml

Add the following to pi_project/.cargo/config.toml .

[build] [target.arm-unknown-linux-gnueabihf] linker = "arm-linux-gnueabihf-gcc" [target.armv7-unknown-linux-gnueabihf] linker = "arm-none-linux-gnueabihf-gcc"

Run your Binary on the Pi

Below is a quick example workflow you can use to quickly deploy your project on a Pi.

PI_IP=192.168.2.159 TARGET=armv7-unknown-linux-gnueabihf cargo build --target $TARGET sshpass -p 'raspberry' scp -r ./target/ $TARGET /debug/pi_project pi@ $PI_IP :/home/pi sshpass -p 'raspberry' ssh pi@ $PI_IP './pi_project'

The output should look like this.