From b2fd4fabee20e321c4f327f15e6de76dfb21eea2 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Mon, 14 May 2018 17:00:48 -1000 Subject: [PATCH] Revert "Check __ANDROID_API__ instead of defining it" This reverts commit f934a0ba45a53812bd04694c0e1781ffd9d01671. --- BUILDING.md | 3 --- build.rs | 11 +++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 7de129485..b5bab72e1 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -58,9 +58,6 @@ Note in particular that if you are cross-compiling an x86 build on a 64-bit version of Linux, then you need to have the proper gcc-multilibs and g++-multilibs packages or equivalent installed. -On Android, you will need to define the `__ANDROID_API__` constant to at least -`21` on 64-bit and `18` on 32-bit. - Additional Features that are Useful for Development diff --git a/build.rs b/build.rs index 70474a34a..a9cd5241e 100644 --- a/build.rs +++ b/build.rs @@ -589,6 +589,17 @@ fn cc(file: &Path, ext: &str, target: &Target, warnings_are_errors: bool, // http://www.openwall.com/lists/musl/2015/06/17/1 let _ = c.flag("-U_FORTIFY_SOURCE"); } + if target.os() == "android" { + // Define __ANDROID_API__ to the Android API level we want. + // Needed for Android NDK Unified Headers, see: + // https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md#Supporting-Unified-Headers-in-Your-Build-System + if target.arch() == "aarch64" { + // Minimum API level where AArch64 is available is 21. + let _ = c.define("__ANDROID_API__", Some("21")); + } else { + let _ = c.define("__ANDROID_API__", Some("18")); + } + } let mut c = c.get_compiler().to_command(); let _ = c.arg("-c")