Skip to content

Commit

Permalink
fix android x86_64 build
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedberg committed Oct 16, 2023
1 parent c27b06e commit 3385f2d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 34 deletions.
49 changes: 21 additions & 28 deletions rgb-lib-ffi/Cargo.lock

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

6 changes: 0 additions & 6 deletions rgb-lib-ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
37 changes: 37 additions & 0 deletions rgb-lib-ffi/build.rs
Original file line number Diff line number Diff line change
@@ -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");
}

0 comments on commit 3385f2d

Please sign in to comment.