Skip to content

Latest commit

 

History

History
40 lines (35 loc) · 957 Bytes

README.md

File metadata and controls

40 lines (35 loc) · 957 Bytes

A helper library for build.rs to work with NDK to build native libraries targeting android.

Usage

Cargo.toml

[build-dependencies]
ndk-rs = { git = "https://github.com/jarod/ndk-rs.git" }

Autotools configure script:

extern crate ndk;

use ndk::Toolchain;

fn main() {
    let target = env::var("TARGET").unwrap();
    let mut configure = Command::new("sh");
    configure.args(&[
        "configure",
        "--host",
        &target,
    ]);
    // set CC and sysroot for android targets
    if target.contains("android") {
        let toolchain = Toolchain::new(14, &target).unwrap();
        configure
            .env("CC", toolchian.cc())
            .arg("--with-sysroot")
            .arg(&toolchian.sysroot());
    }
    configure.status().expect("configure");
}

Set ANDROID_NDK then build

export ANDROID_NDK=<path to ndk directory>
cargo build