Skip to content
This repository was archived by the owner on Mar 23, 2025. It is now read-only.

Commit 609d813

Browse files
committed
android x86_64模拟器
breez/c-breez#553 (comment)
1 parent f40fdf8 commit 609d813

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src-tauri/build.rs

+37
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,40 @@
1+
use std::env;
2+
use std::path::Path;
3+
4+
const DEFAULT_CLANG_VERSION: &str = "17";
5+
16
fn main() {
7+
setup_x86_64_android_workaround();
28
tauri_build::build()
39
}
10+
11+
/// Adds a temporary workaround for an issue with the Rust compiler and Android
12+
/// in x86_64 devices: https://github.com/rust-lang/rust/issues/109717.
13+
/// The workaround comes from: https://github.com/mozilla/application-services/pull/5442
14+
fn setup_x86_64_android_workaround() {
15+
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
16+
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
17+
if target_arch == "x86_64" && target_os == "android" {
18+
let android_ndk_home = env::var("NDK_HOME").expect("ANDROID_NDK_HOME not set");
19+
let build_os = match env::consts::OS {
20+
"linux" => "linux",
21+
"macos" => "darwin",
22+
"windows" => "windows",
23+
_ => panic!(
24+
"Unsupported OS. You must use either Linux, MacOS or Windows to build the crate."
25+
),
26+
};
27+
let clang_version =
28+
env::var("NDK_CLANG_VERSION").unwrap_or_else(|_| DEFAULT_CLANG_VERSION.to_owned());
29+
let linux_x86_64_lib_dir = format!(
30+
"toolchains/llvm/prebuilt/{build_os}-x86_64/lib/clang/{clang_version}/lib/linux/"
31+
);
32+
let linkpath = format!("{android_ndk_home}/{linux_x86_64_lib_dir}");
33+
if Path::new(&linkpath).exists() {
34+
println!("cargo:rustc-link-search={android_ndk_home}/{linux_x86_64_lib_dir}");
35+
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
36+
} else {
37+
panic!("Path {linkpath} not exists");
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)