Skip to content

Commit

Permalink
Merge pull request #177 from xch-dev/x64-fix
Browse files Browse the repository at this point in the history
Fix Android x64
  • Loading branch information
Rigidity authored Dec 22, 2024
2 parents 2aa0500 + 0a4d306 commit bcbfd38
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ once_cell = "1.19.0"
num-traits = "0.2.19"
paste = "1.0.15"
chrono = "0.4.38"
glob = "0.3.1"

# Tracing
tracing = "0.1.40"
Expand Down
1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ aws-lc-rs = { version = "1", features = ["bindgen"] }

[build-dependencies]
tauri-build = { workspace = true, features = [] }
glob = { workspace = true }

[package.metadata.cargo-machete]
ignored = ["serde_json", "aws-lc-rs"]
33 changes: 33 additions & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
use glob::glob;
use std::env;

/// Adds a temporary workaround for an issue with the Rust compiler and Android
/// in `x86_64` devices: <https://github.com/rust-lang/rust/issues/109717>.
/// The workaround comes from: <https://github.com/smartvaults/smartvaults/blob/827805a989561b78c0ea5b41f2c1c9e9e59545e0/bindings/smartvaults-sdk-ffi/build.rs>
fn setup_x86_64_android_workaround() {
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("CARGO_CFG_TARGET_OS not set");
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").expect("CARGO_CFG_TARGET_ARCH not set");
if target_arch == "x86_64" && target_os == "android" {
let android_ndk_home = env::var("ANDROID_NDK_HOME").expect("ANDROID_NDK_HOME not set");
let build_os = match env::consts::OS {
"linux" => "linux",
"macos" => "darwin",
"windows" => "windows",
_ => panic!(
"Unsupported OS. You must use either Linux, MacOS or Windows to build the crate."
),
};
let linux_x86_64_lib_pattern = format!(
"{android_ndk_home}/toolchains/llvm/prebuilt/{build_os}-x86_64/lib*/clang/**/lib/linux/"
);
match glob(&linux_x86_64_lib_pattern).expect("glob failed").last() {
Some(Ok(path)) => {
println!("cargo:rustc-link-search={}", path.to_string_lossy());
println!("cargo:rustc-link-lib=static=clang_rt.builtins-x86_64-android");
},
_ => panic!("Path not found: {linux_x86_64_lib_pattern}. Try setting a different ANDROID_NDK_HOME."),
}
}
}

fn main() {
setup_x86_64_android_workaround();
tauri_build::build();
}

0 comments on commit bcbfd38

Please sign in to comment.