Skip to content

Commit

Permalink
two way for building for android
Browse files Browse the repository at this point in the history
  • Loading branch information
shiroedev2024 committed Apr 23, 2024
1 parent fe3b7c8 commit 3935609
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions leaf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@ fn generate_mobile_bindings() {
let inc_path =
Path::new(String::from_utf8_lossy(&output.stdout).trim()).join("usr/include");
format!("-I{}", inc_path.to_str().expect("invalid include path"))
} else if os == "android" {
let android_ndk_home = env::var("ANDROID_NDK_HOME").expect("ANDROID_NDK_HOME must be set");
} else if os == "android" && env::var("ANDROID_NDK_HOME").is_ok() {
let android_ndk_home = env::var("ANDROID_NDK_HOME").unwrap();

let host_os = std::env::consts::OS;
let host_arch = std::env::consts::ARCH;
let host_os = env::consts::OS;
let host_arch = env::consts::ARCH;
let ndk_arch = format!("{}-{}", host_os, host_arch).to_lowercase();

format!("-I{}/toolchains/llvm/prebuilt/{}/sysroot/usr/include", android_ndk_home, ndk_arch)
} else {
"".to_string()
})
// set the clang include path if android
.clang_arg(if os == "android" {
let android_ndk_home = env::var("ANDROID_NDK_HOME").expect("ANDROID_NDK_HOME must be set");
let clang_version = env::var("CLANG_VERSION").expect("CLANG_VERSION must be set");
.clang_arg(if os == "android" && env::var("ANDROID_NDK_HOME").is_ok() && env::var("CLANG_VERSION").is_ok() {
let android_ndk_home = env::var("ANDROID_NDK_HOME").unwrap();
let clang_version = env::var("CLANG_VERSION").unwrap();

let host_os = std::env::consts::OS;
let host_arch = std::env::consts::ARCH;
let host_os = env::consts::OS;
let host_arch = env::consts::ARCH;
let ndk_arch = format!("{}-{}", host_os, host_arch).to_lowercase();

format!("-I{}/toolchains/llvm/prebuilt/{}/lib/clang/{}/include", android_ndk_home, ndk_arch, clang_version)
Expand All @@ -67,11 +67,11 @@ fn main() {
let os = env::var("CARGO_CFG_TARGET_OS").unwrap();

// set wintun path env variable if windows
if std::env::var("CARGO_FEATURE_INBOUND_TUN").is_ok() && os == "windows" {
if env::var("CARGO_FEATURE_INBOUND_TUN").is_ok() && os == "windows" {
use std::fs::File;
use std::io::Write;

let arch = match std::env::consts::ARCH {
let arch = match env::consts::ARCH {
"x86_64" => "amd64",
"aarch64" => "arm64",
"x86" => "x86",
Expand All @@ -89,8 +89,8 @@ fn main() {
}

// set clang lib env variable if android
if os == "android" {
let android_ndk_home = env::var("ANDROID_NDK_HOME").expect("ANDROID_NDK_HOME must be set");
if os == "android" && env::var("ANDROID_NDK_HOME").is_ok() {
let android_ndk_home = env::var("ANDROID_NDK_HOME").unwrap();

let host_os = std::env::consts::OS;
let host_arch = std::env::consts::ARCH;
Expand Down

0 comments on commit 3935609

Please sign in to comment.