Skip to content

Commit 3d6b352

Browse files
committed
Fix Android builds
For starters, they should link against libc++, as they have always intended to use STL "c++_shared". https://github.com/Kitware/CMake/blob/824f2a7a200f9d3e41a2b68be2d5e1cc678afffa/Modules/Platform/Android-Common.cmake#L70-L75 Also, fix the variable names we define, as far as I know cmake never cared about ANDROID_NATIVE_API_LEVEL nor ANDROID_STL.
1 parent f75006f commit 3d6b352

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

boring-sys/build/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) struct Config {
1010
pub(crate) target: String,
1111
pub(crate) target_arch: String,
1212
pub(crate) target_os: String,
13+
pub(crate) unix: bool,
1314
pub(crate) features: Features,
1415
pub(crate) env: Env,
1516
}
@@ -46,6 +47,7 @@ impl Config {
4647
let target = env::var("TARGET").unwrap();
4748
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
4849
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
50+
let unix = env::var("CARGO_CFG_UNIX").is_ok();
4951

5052
let features = Features::from_env();
5153
let env = Env::from_env(&host, &target, features.is_fips_like());
@@ -63,6 +65,7 @@ impl Config {
6365
target,
6466
target_arch,
6567
target_os,
68+
unix,
6669
features,
6770
env,
6871
};

boring-sys/build/main.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use fslock::LockFile;
2-
use std::env;
32
use std::ffi::OsString;
43
use std::fs;
54
use std::io;
@@ -262,8 +261,8 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
262261
boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", toolchain_file);
263262

264263
// 21 is the minimum level tested. You can give higher value.
265-
boringssl_cmake.define("ANDROID_NATIVE_API_LEVEL", "21");
266-
boringssl_cmake.define("ANDROID_STL", "c++_shared");
264+
boringssl_cmake.define("CMAKE_SYSTEM_VERSION", "21");
265+
boringssl_cmake.define("CMAKE_ANDROID_STL_TYPE", "c++_shared");
267266
}
268267

269268
"macos" => {
@@ -561,14 +560,11 @@ fn get_cpp_runtime_lib(config: &Config) -> Option<String> {
561560
return cpp_lib.clone().into_string().ok();
562561
}
563562

564-
// TODO(rmehra): figure out how to do this for windows
565-
if env::var_os("CARGO_CFG_UNIX").is_some() {
566-
match env::var("CARGO_CFG_TARGET_OS").unwrap().as_ref() {
567-
"macos" | "ios" | "freebsd" => Some("c++".into()),
568-
_ => Some("stdc++".into()),
569-
}
570-
} else {
571-
None
563+
match &*config.target_os {
564+
"macos" | "ios" | "freebsd" | "android " => Some("c++".into()),
565+
_ if config.unix => Some("stdc++".into()),
566+
// TODO(rmehra): figure out how to do this for windows
567+
_ => None,
572568
}
573569
}
574570

0 commit comments

Comments
 (0)