Manually set bindgen sysroot for Android build

This commit is contained in:
Luke Street 2021-09-01 19:06:37 -04:00
parent 34fc7e4286
commit 310093b38a
1 changed files with 9 additions and 0 deletions

View File

@ -24,6 +24,15 @@ fn main() {
{ {
bindings = bindings.layout_tests(false); bindings = bindings.layout_tests(false);
} }
if matches!(env::var("CARGO_CFG_TARGET_OS"), Result::Ok(v) if v == "android") {
if let Result::Ok(cc) = env::var("TARGET_CXX") {
let mut sysroot = PathBuf::from(cc).with_file_name("../sysroot");
sysroot = sysroot.canonicalize().unwrap_or_else(|err| {
panic!("Failed to locate {}: {}", sysroot.to_string_lossy(), err)
});
bindings = bindings.clang_arg(format!("--sysroot={}", sysroot.to_string_lossy()));
}
}
let result = bindings.generate().expect("Unable to generate bindings"); let result = bindings.generate().expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
result.write_to_file(out_path.join("bindings.rs")).expect("Couldn't write bindings!"); result.write_to_file(out_path.join("bindings.rs")).expect("Couldn't write bindings!");