From 8a254a0ce45b265a19eda0f7522ba357965c0dbf Mon Sep 17 00:00:00 2001 From: Christopher Peterson Sauer Date: Tue, 15 Nov 2022 01:11:34 -0800 Subject: [PATCH 1/2] Add support for using conditionally available NDK APIs Coming in r26. For more, see https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#weak-symbols-for-api-definitions and https://github.com/android/ndk/issues/837 --- ndk_cc_toolchain_config.bzl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ndk_cc_toolchain_config.bzl b/ndk_cc_toolchain_config.bzl index 7cfebd2..7d9186b 100644 --- a/ndk_cc_toolchain_config.bzl +++ b/ndk_cc_toolchain_config.bzl @@ -532,6 +532,15 @@ def ndk_cc_toolchain_config( enabled = True, ), + # By default, allow use of APIs above the api_level, so long as the use is + # protected with a call to __builtin_available(android , *). + # For more, see https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#weak-symbols-for-api-definitions + # This takes effect with NDK r26 and greater. + feature( + name = "android_ndk_conditional_api_availabilty", + enabled = True, + ), + # User-settable feature controls warning aggressiveness for compilation. feature(name = "warnings_as_errors"), @@ -682,6 +691,14 @@ def ndk_cc_toolchain_config( ], features = ["android_unwind_tables"], ), + flag_set( + actions = actions.all_compile, + flags = [ + "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__", + "-Werror=unguarded-availability", + ], + features = ["android_ndk_conditional_api_availabilty"], + ), ## Options for particular compile modes: From 647886990453f8278ab80fffb0d60798d904ff67 Mon Sep 17 00:00:00 2001 From: Chris Sauer Date: Tue, 8 Aug 2023 14:55:04 -0700 Subject: [PATCH 2/2] Make conditionally available NDK API feature opt-in This better reflects its soft launch. See discussion in https://github.com/bazelbuild/rules_android_ndk/pull/27 Also fixes typo. --- ndk_cc_toolchain_config.bzl | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ndk_cc_toolchain_config.bzl b/ndk_cc_toolchain_config.bzl index 7d9186b..05647a0 100644 --- a/ndk_cc_toolchain_config.bzl +++ b/ndk_cc_toolchain_config.bzl @@ -532,14 +532,11 @@ def ndk_cc_toolchain_config( enabled = True, ), - # By default, allow use of APIs above the api_level, so long as the use is + # Optionally, allow use of APIs above the api_level, so long as the use is # protected with a call to __builtin_available(android , *). # For more, see https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#weak-symbols-for-api-definitions # This takes effect with NDK r26 and greater. - feature( - name = "android_ndk_conditional_api_availabilty", - enabled = True, - ), + feature(name = "android_ndk_conditional_api_availability"), # User-settable feature controls warning aggressiveness for compilation. feature(name = "warnings_as_errors"), @@ -697,7 +694,7 @@ def ndk_cc_toolchain_config( "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__", "-Werror=unguarded-availability", ], - features = ["android_ndk_conditional_api_availabilty"], + features = ["android_ndk_conditional_api_availability"], ), ## Options for particular compile modes: