Cross compiling Rust for ARM (e.g. Raspberry Pi) using any OS!

Rust + Vagrant 💖

Everybody knows that Rust is the most beloved language for developers since it appeared! Same goes for Raspberry Pi, the small but mighty computer, that costs just £30 but brings a whole awesomeness on board (I wish Broadcom Engineers were a bit more open with their design and less lazy to implement the whole ARM GIC; but let’s keep this for another time).

Preparation 👈🏼

The simple steps for achieving all the above are the following (the first two steps assume Mac OSx; for Windows users you can do something similar but Google on how to install the tools described):

brew cask install virtualbox
brew cask install vagrant
brew cask install vagrant-manager
cd ~/workspace/rustvagrant init debian/stretch64
vagrant up
vagrant ssh
# you can quit the machine with 'vagrant halt'
sudo apt update
sudo apt upgrade
# you may need to 'sudo apt install curl' as well
curl https://sh.rustup.rs -sSf | sh
# Choose 2, Enter, nightly, y. Confirm and press 1 to install.
source $HOME/.cargo/envsudo apt-get install -qq gcc-arm-linux-gnueabihf
rustup target add armv7-unknown-linux-gnueabihf
mkdir -p ~/.cargo# > should not be included when pastingcat >>~/.cargo/config <<EOF
> [target.armv7-unknown-linux-gnueabihf]
> linker = "arm-linux-gnueabihf-gcc"
> EOF
cargo new --bin hello 
cd hello
cargo build --target=armv7-unknown-linux-gnueabihf
file target/armv7-unknown-linux-gnueabihf/debug/hellovagrant@stretch:~/hello$ target/armv7-unknown-linux-gnueabihf/debug/hello: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=39cfb5d9c8cda29ecac841120a2ef9c170f84399, not stripped# you can scp and run the executable on the ARM to finalise your test!

linux 🧙‍| embedded | medical imaging | c | rust | julia | sensors | 🥞 | films 📽️ | swimming 🏊‍| swing dancing🕺🏼

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store