Created
April 2, 2024 14:18
-
-
Save wyatt-herkamp/84444123a447e15742321219131dca8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const DEFAULT_CLANG_VERSION: &str = "17"; | |
/// Work Around for x86_64 Android not being able to find symbol __extenddftf2 | |
/// [Source](https://github.com/smartvaults/smartvaults/blob/master/bindings/smartvaults-sdk-ffi/build.rs) | |
/// [More Info](https://github.com/tauri-apps/tauri/issues/7413) | |
fn setup_x86_64_android_workaround() -> anyhow::Result<()> { | |
let target_os = | |
env::var("CARGO_CFG_TARGET_OS").with_context(|| "CARGO_CFG_TARGET_OS not set")?; | |
let target_arch = | |
env::var("CARGO_CFG_TARGET_ARCH").with_context(|| "CARGO_CFG_TARGET_ARCH not set")?; | |
if target_arch == "x86_64" && target_os == "android" { | |
let android_ndk_home = env::var("NDK_HOME").with_context(|| "NDK_HOME not set")?; | |
let build_os = match env::consts::OS { | |
"linux" => "linux", | |
"macos" => "darwin", | |
"windows" => "windows", | |
_ => { | |
return Err(anyhow::anyhow!( | |
"Unsupported OS: {}. Must be Linux, Macos, Or Windows", | |
env::consts::OS | |
)); | |
} | |
}; | |
let build_arch = env::consts::ARCH; | |
let clang_version = | |
env::var("NDK_CLANG_VERSION").unwrap_or_else(|_| DEFAULT_CLANG_VERSION.to_owned()); | |
let linux_x86_64_lib_dir = format!( | |
"toolchains/llvm/prebuilt/{build_os}-{build_arch}/lib/clang/{clang_version}/lib/linux/" | |
); | |
let linkpath = format!("{android_ndk_home}/{linux_x86_64_lib_dir}"); | |
if Path::new(&linkpath).exists() { | |
println!("cargo:rustc-link-search={android_ndk_home}/{linux_x86_64_lib_dir}"); | |
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android"); | |
} else { | |
return Err(anyhow::anyhow!("Link Path does not exist: {}", linkpath)); | |
} | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment