A step-by-step walkthrough for cross-compiling static Rust binaries targeting Raspberry Pi (ARMv7 and ARMv6) inside Docker using musl for static linking. Covers setting up Rust targets with rustup, configuring the linker in .cargo/config, optimizing binary size via Cargo.toml release profile settings (opt-level z, LTO, single codegen unit), and building multi-architecture Docker images using Docker buildx with BUILDPLATFORM and TARGETPLATFORM arguments to dynamically select the correct Rust compilation target per architecture.

6m read timeFrom jakewharton.com
Post cover image
Table of contents
Cross-compiling and static linkingBuilding inside Docker