This repository was archived by the owner on Mar 23, 2025. It is now read-only.
File tree 1 file changed +37
-0
lines changed
1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ use std:: env;
2
+ use std:: path:: Path ;
3
+
4
+ const DEFAULT_CLANG_VERSION : & str = "17" ;
5
+
1
6
fn main ( ) {
7
+ setup_x86_64_android_workaround ( ) ;
2
8
tauri_build:: build ( )
3
9
}
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
+ }
You can’t perform that action at this time.
0 commit comments