diff --git a/rgb-lib-ffi/Cargo.lock b/rgb-lib-ffi/Cargo.lock index 662efcb..b3116a1 100644 --- a/rgb-lib-ffi/Cargo.lock +++ b/rgb-lib-ffi/Cargo.lock @@ -168,30 +168,29 @@ dependencies = [ [[package]] name = "anstream" -version = "0.3.2" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +checksum = "2ab91ebe16eb252986481c5b62f6098f3b698a45e34b5b98200cf20dd2484a44" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", - "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.1" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" +checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87" [[package]] name = "anstyle-parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +checksum = "317b9a89c1868f5ea6ff1d9539a69f45dffc21ce321ac1fd1160dfa48c8e2140" dependencies = [ "utf8parse", ] @@ -207,9 +206,9 @@ dependencies = [ [[package]] name = "anstyle-wincon" -version = "1.0.2" +version = "3.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +checksum = "f0699d10d2f4d628a98ee7b57b289abbc98ff3bad977cb3152709d4bf2330628" dependencies = [ "anstyle", "windows-sys", @@ -957,33 +956,31 @@ dependencies = [ [[package]] name = "clap" -version = "4.3.24" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb690e81c7840c0d7aade59f242ea3b41b9bc27bcd5997890e7702ae4b32e487" +checksum = "d04704f56c2cde07f43e8e2c154b43f216dc5c92fc98ada720177362f953b956" dependencies = [ "clap_builder", "clap_derive", - "once_cell", ] [[package]] name = "clap_builder" -version = "4.3.24" +version = "4.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ed2e96bc16d8d740f6f48d663eddf4b8a0983e79210fd55479b7bcd0a69860e" +checksum = "0e231faeaca65ebd1ea3c737966bf858971cd38c3849107aa3ea7de90a804e45" dependencies = [ "anstream", "anstyle", "clap_lex", - "once_cell", "strsim", ] [[package]] name = "clap_derive" -version = "4.3.12" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +checksum = "0862016ff20d69b84ef8247369fabf5c008a7417002411897d40ee1f4532b873" dependencies = [ "heck", "proc-macro2", @@ -993,9 +990,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" +checksum = "cd7cc57abe963c6d3b9d8be5b06ba7c8957a930305ca90304f24ef040aa6f961" [[package]] name = "cloudabi" @@ -2751,13 +2748,13 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.1" +version = "1.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaac441002f822bc9705a681810a4dd2963094b9ca0ddc41cb963a4c189189ea" +checksum = "380b951a9c5e80ddfd6136919eef32310721aa4aacd4889a8d39124b026ab343" dependencies = [ "aho-corasick", "memchr 2.6.4", - "regex-automata 0.4.2", + "regex-automata 0.4.3", "regex-syntax 0.8.2", ] @@ -2772,9 +2769,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5011c7e263a695dc8ca064cddb722af1be54e517a280b12a5356f98366899e5d" +checksum = "5f804c7828047e88b2d32e2d7fe5a105da8ee3264f01902f796c8e067dc2483f" dependencies = [ "aho-corasick", "memchr 2.6.4", @@ -2929,10 +2926,6 @@ dependencies = [ name = "rgb-lib-ffi" version = "0.1.0" dependencies = [ - "anstyle", - "anstyle-parse", - "clap_derive", - "clap_lex", "openssl", "rgb-lib", "uniffi", diff --git a/rgb-lib-ffi/Cargo.toml b/rgb-lib-ffi/Cargo.toml index 9be1d7d..382669d 100644 --- a/rgb-lib-ffi/Cargo.toml +++ b/rgb-lib-ffi/Cargo.toml @@ -20,12 +20,6 @@ default = ["uniffi/cli"] rgb-lib = { version = "0.2.0-alpha.5", path = "../" } uniffi = "0.24.3" -# fixed-version dependencies to support building with rust 1.67 -anstyle = "=1.0.1" -anstyle-parse = "=0.2.1" -clap_lex = "=0.5.0" -clap_derive = "=4.3.12" - [build-dependencies] uniffi = { version = "0.24.3", features = ["build"] } diff --git a/rgb-lib-ffi/build.rs b/rgb-lib-ffi/build.rs index 367ef7b..29ea2d3 100644 --- a/rgb-lib-ffi/build.rs +++ b/rgb-lib-ffi/build.rs @@ -1,3 +1,40 @@ +use std::env; +use std::path::Path; + +const DEFAULT_CLANG_VERSION: &str = "14.0.7"; + +/// 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/mozilla/application-services/pull/5442 +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_ROOT").expect("ANDROID_NDK_ROOT 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 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}-x86_64/lib64/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 { + panic!("Path {linkpath} not exists"); + } + } +} + fn main() { + setup_x86_64_android_workaround(); uniffi::generate_scaffolding("src/rgb-lib.udl").expect("UDL should be valid"); }