Cross-compiling Rust programs (for Linux and Windows) on Mac OS
Published: Post views:This post records the essential steps for cross-compiling Rust programs (for Linux and Windows) on Mac OS.
Install prerequisites
rustup target add x86_64-unknown-linux-musl
brew install filosottile/musl-cross/musl-cross
ln -s /usr/local/bin/x86_64-linux-musl-gcc /usr/local/bin/musl-gcc
rustup target add x86_64-pc-windows-gnu
brew install mingw-w64
Add config
add to ~/.cargo/config
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
[target.x86_64-pc-windows-gnu]
linker = "x86_64-w64-mingw32-gcc"
ar = "x86_64-w64-mingw32-gcc-ar"
Compiling
# Linux
CROSS_COMPILE=x86_64-linux-musl- cargo build --release --target x86_64-unknown-linux-musl
# Windows
cargo build --release --target x86_64-pc-windows-gnu
Tags: Rust
Categories: Programming
Comments