To run our project on the Brick, we need to cross-compile our code to the ISA (instruction set architecture) of the target processor. Cross-compiling rust projects requires the rust toolchain and a suitable cross-compiler for our target.
The Modbrick is powerered by a Raspberry Pi Zero 2W, its BCM2710 SoC includes four Cortex-A53 ARMv8-CPUs, which support the aarch64 ISA.
As Raspberry Pi OS is based on Linux and uses the GNU C Library (glibc), the final cross-compilation target is aarch64-unknown-linux-gnu.
This guide uses a native toolchain of the widely used GNU Compiler Collection (GCC) as a C/C++ cross-compiler.
Please test your installation after going through the installation steps!
Please install the corresponding Arm GNU Toolchain from the ARM Developer Website:
Windows (mingw-w64-x86_64) hosted cross toolchainsAArch64 GNU/Linux target (aarch64-none-linux-gnu).msi for automatic extractionmingw-w64-x86_64-aarch64-none-linux-gnu.msiAfter the installation, add the following toolchain location to your PATH Environment Variable (> FAQ):
C:\Program Files\Arm\GNU Toolchain mingw-w64-x86_64-aarch64-none-linux-gnu\bin
Cross Compiler Toolchains for macOS can be installed using brew from github.com/messense/homebrew-macos-cross-toolchains:
brew tap messense/macos-cross-toolchains
brew install aarch64-unknown-linux-gnu
Alternatively, install the corresponding Arm GNU Toolchain from the ARM Developer Website:
macOS (Apple silicon / x86_64) hosted cross toolchainsAArch64 GNU/Linux target (aarch64-none-linux-gnu)darwin-arm64/x86_64-aarch64-none-elf.pkgLatest supported release for x86_64 macOS (Intel) is 14.2.Rel1
Install gcc the cross-compile toolchain with your package manager:
sudo apt install gcc-aarch64-linux-gnu # Debian, Ubuntu, Linux Mint
sudo pacman -S aarch64-linux-gnu-gcc # Arch
sudo dnf install gcc-aarch64-linux-gnu # Fedora
Create ~/.cargo/config.toml with the following content to specify the correct executable name:
# notepad.exe .cargo\config.toml
[target.aarch64-unknown-linux-musl]
linker = "aarch64-none-linux-gnu-gcc"
# nano ~/.cargo/config.toml
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-gnu-gcc"
rustup target add aarch64-unknown-linux-musl
cargo new hello
cd hello
cargo build --target aarch64-unknown-linux-musl