diff --git a/cli/Cargo.lock b/cli/Cargo.lock index ba0b938..a8f4779 100644 --- a/cli/Cargo.lock +++ b/cli/Cargo.lock @@ -179,6 +179,9 @@ name = "anyhow" version = "1.0.83" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25bdb32cbbdce2b519a9cd7df3a678443100e265d5e25ca763b7572a5104f5f3" +dependencies = [ + "backtrace", +] [[package]] name = "atomic" @@ -397,6 +400,7 @@ dependencies = [ "boltz-client", "elements", "flutter_rust_bridge", + "glob", "log", "lwk_common", "lwk_signer", @@ -989,6 +993,12 @@ version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253" +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + [[package]] name = "h2" version = "0.3.26" diff --git a/lib/Cargo.lock b/lib/Cargo.lock index c338572..bf0f54b 100644 --- a/lib/Cargo.lock +++ b/lib/Cargo.lock @@ -504,6 +504,7 @@ dependencies = [ "boltz-client", "elements", "flutter_rust_bridge", + "glob", "log", "lwk_common", "lwk_signer", diff --git a/lib/bindings/bindings-flutter/scripts/build-android.sh b/lib/bindings/bindings-flutter/scripts/build-android.sh index f961bfe..fdf17b9 100755 --- a/lib/bindings/bindings-flutter/scripts/build-android.sh +++ b/lib/bindings/bindings-flutter/scripts/build-android.sh @@ -19,11 +19,11 @@ rustup target add \ # Build the android libraries in the jniLibs directory cargo ndk -o $JNI_DIR \ - --manifest-path ../../../Cargo.toml \ - -t armeabi-v7a \ - -t arm64-v8a \ - -t x86 \ - -t x86_64 \ + --manifest-path ../../../core/Cargo.toml \ + -t aarch64-linux-android \ + -t armv7-linux-androideabi \ + -t i686-linux-android \ + -t x86_64-linux-android \ build "$@" # Archive the dynamic libs diff --git a/lib/core/Cargo.toml b/lib/core/Cargo.toml index 2916c2e..bad706a 100644 --- a/lib/core/Cargo.toml +++ b/lib/core/Cargo.toml @@ -7,6 +7,10 @@ version.workspace = true name = "breez_liquid_sdk" crate-type = ["lib", "cdylib", "staticlib"] +[features] +default = ["frb"] +frb = ["dep:flutter_rust_bridge"] + [dependencies] anyhow = { workspace = true } bip39 = { version = "2.0.0", features = ["serde"] } @@ -31,6 +35,6 @@ elements = "0.24.1" tempdir = "0.3.7" uuid = { version = "1.8.0", features = ["v4"] } -[features] -default = ["frb"] -frb = ["dep:flutter_rust_bridge"] +[build-dependencies] +anyhow = { version = "1.0.79", features = ["backtrace"] } +glob = "0.3.1" diff --git a/lib/core/build.rs b/lib/core/build.rs new file mode 100644 index 0000000..a5be789 --- /dev/null +++ b/lib/core/build.rs @@ -0,0 +1,38 @@ +use anyhow::*; +use glob::glob; +use std::env; +use std::result::Result::Ok; + +/// 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).unwrap().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() -> Result<()> { + setup_x86_64_android_workaround(); + Ok(()) +}