How to Cross-Compile Rust for Raspberry Pi on Apple Silicon (The Fast Way)
If you are developing Rust applications on a Mac with Apple Silicon and want to deploy to a Raspberry Pi (or any other ARM64 Linux device)…
How to Cross-Compile Rust for Raspberry Pi on Apple Silicon (The Fast Way)
If you are developing Rust applications on a Mac with Apple Silicon and want to deploy to a Raspberry Pi (or any other ARM64 Linux device), you might have hit the dreaded “Docker QEMU penalty.”

While tools like cross are fantastic, they often rely on Docker. When the architecture or kernel ABI doesn’t align perfectly, Docker falls back to QEMU emulation. On macOS, this can result in build times that are 10x-50x slower than native compilation, with the linker often timing out entirely. Here is a significantly faster, cleaner solution using Zig as a linker.
The Secret Sauce: cargo-zigbuild
Zig is an impressive language toolchain that happens to include a C/C++ compiler and linker capable of cross-compiling for almost any target out of the box. cargo-zigbuild wraps this capability to let cargo use Zig as its linker. This approach offers two massive benefits:
- Speed: It runs natively on your Mac. No Docker containers, no virtualization overhead.
- Portability: By targeting musl instead of gnu, we get a fully static binary. You can drop this single file onto your Raspberry Pi (Alpine, Raspbian, Ubuntu, etc.), and it will just work — no missing “glibc” errors.
Step-by-Step Guide
Install the Rust Target First
Tell Rust that we want to build for 64-bit ARM Linux using the MUSL standard library.
rustup target add aarch64-unknown-linux-musl
Install cargo-zigbuild
Install the Cargo subcommand:
cargo install cargo-zigbuild
Install Zig
You need the Zig compiler itself. You can install it via Homebrew (brew install zig), or if you need a specific version or want to keep your system clean
Build!
Now, replace your standard cargo build command with cargo zigbuild.
cargo zigbuild — target aarch64-unknown-linux-musl — release
That’s it. You will find your binary in target/aarch64-unknown-linux-musl/release/
Verification
You can verify the output file is indeed an ARM64 executable:
file target/aarch64-unknown-linux-musl/release/your_app_name
Output should look like:
ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, stripped
Copy this file to your Pi, “chmod +x” it, and enjoy your new blazing fast deployment pipeline!
메타데이터
- post_id
- bf864fb007e8
- slug
- how-to-cross-compile-rust-for-raspberry-pi-on-apple-silicon-the-fast-way-bf864fb007e8
- url
- https://medium.com/@loafoe/how-to-cross-compile-rust-for-raspberry-pi-on-apple-silicon-the-fast-way-bf864fb007e8
- canonical_url
- https://medium.com/@loafoe/how-to-cross-compile-rust-for-raspberry-pi-on-apple-silicon-the-fast-way-bf864fb007e8
- author_url
- https://medium.com/@loafoe
- status
- ok
- fetched_at
- 2026-07-13 09:40:43