- Download and install the latest Android NDK
- Setup a standalone toolchain for your specific Android API Level
- Clone the Rust Repository
- Configure rustc to be built with NDK toolchain
The examples in this document were tested with the following software versions:
OS X: 10.10.2 (14C1510)
Android API: 14 (Ice Cream Sandwich)
Android NDK: r10d
rustc: 1.0.0-dev (46f649c47 2015-03-18) (built 2015-03-18)
cargo: 0.0.1-pre-nightly (07cd618 2015-03-12) (built 2015-03-13)
The same commands will also work for Linux. Additional dependencies may be needed for working with the Android build chain on 64-bit Linux distros. This posting covers most major distribution dependencies.
Use NDK version r9b or later. Jemalloc may not be able to build with previous NDK versions.
The following command builds an NDK toolchain for Android API 14, arm architecture in the ~/bin/ndk-standalone-14-arm directory.
~/android-ndk-r10d/build/tools/make-standalone-toolchain.sh --platform=android-14 --arch=arm --install-dir=~/bin/ndk-standalone-14-arm
git clone https://github.com/rust-lang/rust
cd rust
mkdir build
cd build
../configure --target=arm-linux-androideabi --android-cross-path=~/bin/ndk-standalone-14-arm/
make
sudo make install
rustc --target=arm-linux-androideabi -C linker=~/bin/ndk-standalone-14-arm/bin/arm-linux-androideabi-gcc main.rs
Cargo needs the linker information when passing --target=arm-linux-androideabi
Create a .cargo/config
file in the project root directory
cargo new some-project --bin
cd some-project
mkdir .cargo
touch .cargo/config
Place the linker path in the config
file
[target.arm-linux-androideabi]
linker = "~/bin/ndk-standalone-14-arm/bin/arm-linux-androideabi-gcc"
Build
cargo build --target=arm-linux-androideabi