Last active
July 21, 2022 05:21
-
-
Save ekzhang/e9c8265468c0e71bc475f9e1bf669c49 to your computer and use it in GitHub Desktop.
Rust cross-compilation cheatsheet (M1 Mac)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cross-compilation commands for Rust on M1 (arm64) macOS. | |
brew tap messense/macos-cross-toolchains | |
# -> macOS arm64 | |
cargo build --release | |
# -> macOS x86-64 | |
SDKROOT=$(xcrun -sdk macosx12.3 --show-sdk-path) \ | |
MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx12.3 --show-sdk-platform-version) \ | |
cargo build --release --target=x86_64-apple-darwin | |
# usage: (only for linux targets) | |
# | |
# rcr-tap | |
# rcr-add x86_64-unknown-linux-gnu | |
# rcr-build x86_64-unknown-linux-gnu | |
function rcr-tap { | |
brew tap messense/macos-cross-toolchains | |
} | |
function rcr-add { | |
brew install "$1" | |
rustup target add "$1" | |
} | |
function rcr-build { | |
capital_target=$(tr '-' '_' <<< ${1:u}) | |
eval " | |
TARGET_CC=$1-cc \ | |
CARGO_TARGET_${capital_target}_LINKER=$1-gcc \ | |
cargo build --release --target $1 | |
" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment