What steps are needed to cross-compile a program that runs on my raspberry pi zero 2 w?
How to cross-compile the code of Raspberry Pi on windows
Has anyone programmed a Raspberry Pi with Rust?
(I'm assuming crosscompiling then running on Linux, not bare-metal (but that also should be possible)) Not a big project, but I've run simple HTTP server on one. To be honest, with Rust it mostly just:
rustup target add arm-unknown-linux-musleabihf cargo build --target arm-unknown-linux-musleabihf
You might need to adjust target, depending on which Raspberry Pi version you're using.
In my case, because I've fairly old one (RPi 1 B+), I had to additionally download gcc toolchain (for linking) from arm's website, as the one from distro didn't support armv6.
More on reddit.comHow can I compile Rust code to run on a Raspberry Pi 2? - Stack Overflow
Videos
Hi, I already succeeded partially in this as I compiled a rust program for my raspberry pi zero w (the first version). Let's call that one rp0w1 and the new version rp0w2 for clarity.
On my rp0w1 I run rasberry pi os, because that's the only OS supported. I oriented myself on this blog post: link
On the rp0w2 I am running arch linux (arm) though, because I prefer it. And the toolchain isn't correct (the one also mentioned in the blog post).
I would like to know what steps would be needed in order to get a binary that I can run on my rp0w2. I am also not entirely sure what toolchain means in this context. I already have a toolchain installed through rustup don't I? Why do I need additional files?
Can I simply download some files from ARM or what do I do?
If you’ve worked on any projects using Rust and a Raspberry Pi I would be interested to hear your story.
Cross-compiling to Raspberry PI is easy, and works great. Compiling on a Raspberry PI is rather painful due to long compile times.
(I'm assuming crosscompiling then running on Linux, not bare-metal (but that also should be possible)) Not a big project, but I've run simple HTTP server on one. To be honest, with Rust it mostly just:
rustup target add arm-unknown-linux-musleabihf
cargo build --target arm-unknown-linux-musleabihf
You might need to adjust target, depending on which Raspberry Pi version you're using.
In my case, because I've fairly old one (RPi 1 B+), I had to additionally download gcc toolchain (for linking) from arm's website, as the one from distro didn't support armv6.
We have rustup now.
$ rustup target add arm-unknown-linux-gnueabihf
$ sudo apt-get install gcc-arm-linux-gnueabihf
$ echo '[target.arm-unknown-linux-gnueabihf]' >> ~/.cargo/config
$ echo 'linker = "arm-linux-gnueabihf-gcc"' >> ~/.cargo/config
$ cd <project dir>
$ cargo build --target=arm-unknown-linux-gnueabihf
The Rust compiler is not distributed as a cross-compiler for the Raspberry Pi, so it needs to be compiled as a cross compiler with rpi dev tools.
Get rpi dev tools -
git clone https://github.com/raspberrypi/tools.git ~/pi-toolsget rust compiler from mozilla git repo and add rpi tools to the path
export PATH=~/pi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin:$PATHLook for rusty-pi dir on your home
./configure --target=arm-unknown-linux-gnueabihf --prefix=$HOME/rusty-pi && make && make installConsidering helloworld.rs ->
% ~/pi-rust/bin/rustc --target=arm-unknown-linux-gnueabihf -C linker=arm-linux-gnueabihf-g++ helloworld.rs
It will produce an executable.