diff --git a/leaf/build.rs b/leaf/build.rs index 15dd69756..8f1047cd9 100644 --- a/leaf/build.rs +++ b/leaf/build.rs @@ -29,11 +29,11 @@ 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) @@ -41,12 +41,12 @@ fn generate_mobile_bindings() { "".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) @@ -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", @@ -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;