-
Notifications
You must be signed in to change notification settings - Fork 21
/
build.rs
52 lines (46 loc) · 1.73 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
extern crate cmake;
extern crate pkg_config;
use std::env;
fn main() {
let target = env::var("TARGET").unwrap();
if !target.contains("android")
&& pkg_config::Config::new()
.atleast_version("2.1.0")
.find("expat")
.is_ok()
{
return;
}
let mut config = cmake::Config::new("expat");
let cfg = if target.contains("android") {
let ndk_root = env::var("ANDROID_NDK_ROOT").or(env::var("ANDROID_NDK_HOME")).expect("`$ANDROID_NDK_ROOT` or `$ANDROID_NDK_ROOT` is not set.");
let config = config
.define("CMAKE_TOOLCHAIN_FILE", format!("{}/build/cmake/android.toolchain.cmake", ndk_root));
if target.starts_with("aarch64") {
config.define("ANDROID_ABI", "arm64-v8a")
} else if target.starts_with("armv7") {
config.define("ANDROID_ABI", "armeabi-v7a")
} else if target.starts_with("i686") {
config.define("ANDROID_ABI", "x86")
} else if target.starts_with("x86_64") {
config.define("ANDROID_ABI", "x86_64")
} else {
config
}
} else {
&mut config
};
let mut dst = cfg
.define("BUILD_shared", "OFF")
.define("BUILD_tools", "OFF")
.define("BUILD_examples", "OFF")
.define("BUILD_tests", "OFF")
.build();
dst.push("lib");
println!("cargo:rustc-link-search=native={}", dst.display());
println!("cargo:rustc-link-lib=static=expat");
println!("cargo:outdir={}", env::var("OUT_DIR").unwrap());
}