On this page
macOS
Tell Rustup to download the standard library for Linux.
rustup target add x86_64-unknown-linux-muslmacOS doesn’t come with a linker that understands Linux binaries. Use musl-cross:
brew install messense/macos-cross-toolchains/x86_64-unknown-linux-muslYou need to tell Cargo to use that specific linker when building for Linux.
Verify the binary name: Run ls /opt/homebrew/bin | grep musl to see the exact filename.
It is usually x86_64-unknown-linux-musl-gcc.
Create or edit .cargo/config.toml in your project folder:
[target.x86_64-unknown-linux-musl]linker = "x86_64-unknown-linux-musl-gcc"cargo build --target x86_64-unknown-linux-musl --releaseIf your project uses OpenSSL, cross-compiling gets messy because OpenSSL tries to find local C headers. To fix this, add the vendored feature to your Cargo.toml: Ini, TOML
openssl = { version = "0.10", features = ["vendored"] }This forces Rust to compile its own version of OpenSSL instead of looking for a Linux version on your Mac.