Skip to content

Commit 3218133

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 3218133

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
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 & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ fn get_boringssl_cmake_config(config: &Config) -> cmake::Config {
262262
boringssl_cmake.define("CMAKE_TOOLCHAIN_FILE", toolchain_file);
263263

264264
// 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");
265+
boringssl_cmake.define("CMAKE_SYSTEM_VERSION", "21");
266+
boringssl_cmake.define("CMAKE_ANDROID_STL_TYPE", "c++_shared");
267267
}
268268

269269
"macos" => {
@@ -561,14 +561,11 @@ fn get_cpp_runtime_lib(config: &Config) -> Option<String> {
561561
return cpp_lib.clone().into_string().ok();
562562
}
563563

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
564+
match &*config.target_os {
565+
"macos" | "ios" | "freebsd" | "android " => Some("c++".into()),
566+
_ if config.unix => Some("stdc++".into()),
567+
// TODO(rmehra): figure out how to do this for windows
568+
_ => None,
572569
}
573570
}
574571

0 commit comments

Comments
 (0)