You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1.3 KiB
1.3 KiB
Cross Compile
To do cross compile, you should set the toolchains correctly, espicially the target linker, please read the Cargo target reference first.
Here are some examples for cross compile.
Build on macOS and target Linux
- Install the rustc toolchain for Linux
rustup target add x86_64-unknown-linux-gnu
- Install a prebuilt cross compiler for Linux
brew tap SergioBenitez/osxct
brew install x86_64-unknown-linux-gnu
- Do cross compile:
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER=x86_64-unknown-linux-gnu-gcc \
cargo build --target=x86_64-unknown-linux-gnu
The CARGO_TARGET_<triple>_LINKER
environment is used to specify the linker for cross compiling.
Build on macOS and target Android
- Install the rustc toolchain for Android
rustup target add arm-linux-androideabi aarch64-linux-android
- Install ndk for Android, you can download it in here
- Set the linker for cross compile:
CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=$NDK/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android30-clang
the $NDK
is the ndk installation directory.
- Do cross compile:
cargo build --target aarch64-linux-android