Skip to content

Instantly share code, notes, and snippets.

@ralfstx
Created May 10, 2020 10:48
Show Gist options
  • Save ralfstx/20d403bfbdc693634f150109628171bc to your computer and use it in GitHub Desktop.
Save ralfstx/20d403bfbdc693634f150109628171bc to your computer and use it in GitHub Desktop.
Cross-compiling for ARM with musl

Cross-compiling for ARM with musl

I'm using the target arm-linux-musleabihf for ARM v6 (Raspberry Zero is v6) with musl and hard float.

Build a cross compiler

Following instructions from Rust (and C) Cross Compilation for the Raspberry Pi.

Create an output directory:

mkdir /data/cross
chown $USER /data/cross

Use musl-cross-make:

git clone [email protected]:richfelker/musl-cross-make.git
cd musl-cross-make

Create a config.mak:

TARGET = arm-linux-musleabihf
OUTPUT = /data/cross/armv6
COMMON_CONFIG += CFLAGS="-g0 -Os" CXXFLAGS="-g0 -Os" LDFLAGS="-s"
GCC_CONFIG += --with-arch=armv6 --with-mode=arm --with-fpu=vfp

Build:

make install

Add binaries to path: add to .profile:

export PATH=/data/cross/armv6/bin/:$PATH

Prepare Rust for cross compiling

Continue with instructions from rust-cross.

Configure cargo for cross compilation: add this section to ~/.cargo/config:

[target.arm-unknown-linux-musleabihf]
linker = "arm-linux-musleabihf-gcc"

Install the cross compiled standard crates

rustup target add arm-unknown-linux-musleabihf

Cross-compile

cargo build --target=arm-unknown-linux-musleabihf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment