How to cross compile M2 Macbook pro to Raspberry Pi 4
Cross-compiling from MacOS to the Raspberry Pi
Cross-compiling from macOS to ARM
Cross-compiling Rust for the Raspberry Pi on macOS
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.