//

MacOSX Rust Cross-Compile to Linux Steps and Common Issues

Install musl-cross

brew install FiloSottile/musl-cross/musl-cross
sudo ln -s /usr/local/bin/x86_64-linux-musl-gcc /usr/local/bin/musl-gcc

Encountered Issue:

==> make install
Error: gettext: unknown or unsupported macOS version: :dunno

Solution:

brew update-reset

Add Content to .cargo/config

[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"

If this file does not exist, just create it.

Add Target: x86_64-unknown-linux-musl

rustup target add x86_64-unknown-linux-musl

Start Compiling Happily

cargo build --release --target x86_64-unknown-linux-musl

Encountered Issue:

error: failed to run custom build command for `openssl-sys v0.9.95`

Solution:

brew install openssl
export OPENSSL_DIR=/opt/homebrew/opt/openssl@3

Encountered Another Issue:

reqwest.38a55170626eab39-cgu.02:(.text._ZN4core3ptr44drop_in_place$LT$reqwest..connect..Inner$GT$17h0198ea10d7817d8cE+0x38): undefined reference to `SSL_CTX_free'

Solution: need to add openssl dependency in Cargo.toml.

openssl = { version = "0.10", features = ["vendored"] }

Done