diff --git a/Cargo.lock b/Cargo.lock index d2fbe3f9..d633533a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5290,6 +5290,7 @@ dependencies = [ "flume", "futures-util", "getrandom", + "glob", "hex", "ifstructs", "jni", diff --git a/veilid-core/Cargo.toml b/veilid-core/Cargo.toml index 783d4ead..0a82ca4e 100644 --- a/veilid-core/Cargo.toml +++ b/veilid-core/Cargo.toml @@ -279,6 +279,7 @@ wasm-logger = "0.2.0" [build-dependencies] capnpc = "0.18.0" +glob = "0.3.1" [package.metadata.wasm-pack.profile.release] wasm-opt = ["-O", "--enable-mutable-globals"] diff --git a/veilid-core/build.rs b/veilid-core/build.rs index 745f3e52..5f38c28e 100644 --- a/veilid-core/build.rs +++ b/veilid-core/build.rs @@ -1,4 +1,8 @@ -use std::process::{Command, Stdio}; +use glob::glob; +use std::{ + env, + process::{Command, Stdio}, +}; const CAPNP_VERSION: &str = "1.0.1"; // Keep in sync with scripts/install_capnp.sh const PROTOC_VERSION: &str = "24.3"; // Keep in sync with scripts/install_protoc.sh @@ -111,4 +115,25 @@ fn main() { .run() .expect("compiling schema"); } + + // Fix for missing __extenddftf2 on Android x86_64 Emulator + let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap(); + // if target_os == "android" || target_os == "linux" { + // println!("cargo:rustc-link-lib=stdc++"); + // } else { + // println!("cargo:rustc-link-lib=c++"); + // } + let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); + if target_arch == "x86_64" && target_os == "android" { + let missing_library = "clang_rt.builtins-x86_64-android"; + let android_ndk_home = env::var("ANDROID_NDK_HOME").expect("ANDROID_NDK_HOME not set"); + let lib_path = glob(&format!("{android_ndk_home}/**/lib{missing_library}.a")) + .expect("failed to glob") + .next() + .expect("Need libclang_rt.builtins-x86_64-android.a") + .unwrap(); + let lib_dir = lib_path.parent().unwrap(); + println!("cargo:rustc-link-search={}", lib_dir.display()); + println!("cargo:rustc-link-lib=static={missing_library}"); + } }