1 // Copyright 2024 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_ANDROID_REQUIRES_API_H_ 6 #define BASE_ANDROID_REQUIRES_API_H_ 7 8 // Sets the API version of a symbol. Analogous to how @RequiresApi sets the API 9 // version of Java symbols. 10 // 11 // A compiler warning (-Wunguarded-availability) is emitted when symbols with 12 // this annotation are reference by code that has a lower API version. 13 // 14 // The default API version is set by the default_min_sdk_version GN arg. 15 // 16 // To reference a symbol from code with a lower api level, you must use: 17 // if (__builtin_available(android API_VERSION, *)) { ... } 18 // 19 // See also: 20 // https://android.googlesource.com/platform/ndk/+/master/docs/BuildSystemMaintainers.md#weak-symbols-for-api-definitions 21 #define REQUIRES_ANDROID_API(x) \ 22 __attribute__((__availability__(android, introduced = x))) 23 24 // Sets the default API version for all symbols. 25 // 26 // Usage: 27 // #pragma clang attribute push DEFAULT_REQUIRES_ANDROID_API(29) 28 // ... 29 // #pragma clang attribute pop 30 // 31 // For use only within .cc files so that declarations within header files are 32 // clearly labeled. 33 #define DEFAULT_REQUIRES_ANDROID_API(x) \ 34 (REQUIRES_ANDROID_API(x), \ 35 apply_to = any(enum, enum_constant, field, function, namespace, record, \ 36 type_alias, variable)) 37 38 #endif // BASE_ANDROID_REQUIRES_API_H_ 39