1 // 2 // Copyright 2017 The Abseil Authors. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // https://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 // ----------------------------------------------------------------------------- 17 // File: config.h 18 // ----------------------------------------------------------------------------- 19 // 20 // This header file defines a set of macros for checking the presence of 21 // important compiler and platform features. Such macros can be used to 22 // produce portable code by parameterizing compilation based on the presence or 23 // lack of a given feature. 24 // 25 // We define a "feature" as some interface we wish to program to: for example, 26 // a library function or system call. A value of `1` indicates support for 27 // that feature; any other value indicates the feature support is undefined. 28 // 29 // Example: 30 // 31 // Suppose a programmer wants to write a program that uses the 'mmap()' system 32 // call. The Abseil macro for that feature (`ABSL_HAVE_MMAP`) allows you to 33 // selectively include the `mmap.h` header and bracket code using that feature 34 // in the macro: 35 // 36 // #include "absl/base/config.h" 37 // 38 // #ifdef ABSL_HAVE_MMAP 39 // #include "sys/mman.h" 40 // #endif //ABSL_HAVE_MMAP 41 // 42 // ... 43 // #ifdef ABSL_HAVE_MMAP 44 // void *ptr = mmap(...); 45 // ... 46 // #endif // ABSL_HAVE_MMAP 47 48 #ifndef ABSL_BASE_CONFIG_H_ 49 #define ABSL_BASE_CONFIG_H_ 50 51 // Included for the __GLIBC__ macro (or similar macros on other systems). 52 #include <limits.h> 53 54 #ifdef __cplusplus 55 // Included for __GLIBCXX__, _LIBCPP_VERSION 56 #include <cstddef> 57 #endif // __cplusplus 58 59 // ABSL_INTERNAL_CPLUSPLUS_LANG 60 // 61 // MSVC does not set the value of __cplusplus correctly, but instead uses 62 // _MSVC_LANG as a stand-in. 63 // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros 64 // 65 // However, there are reports that MSVC even sets _MSVC_LANG incorrectly at 66 // times, for example: 67 // https://github.com/microsoft/vscode-cpptools/issues/1770 68 // https://reviews.llvm.org/D70996 69 // 70 // For this reason, this symbol is considered INTERNAL and code outside of 71 // Abseil must not use it. 72 #if defined(_MSVC_LANG) 73 #define ABSL_INTERNAL_CPLUSPLUS_LANG _MSVC_LANG 74 #elif defined(__cplusplus) 75 #define ABSL_INTERNAL_CPLUSPLUS_LANG __cplusplus 76 #endif 77 78 #if defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ 79 ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L 80 // Include library feature test macros. 81 #include <version> 82 #endif 83 84 #if defined(__APPLE__) 85 // Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED, 86 // __IPHONE_8_0. 87 #include <Availability.h> 88 #include <TargetConditionals.h> 89 #endif 90 91 #include "absl/base/options.h" 92 #include "absl/base/policy_checks.h" 93 94 // Abseil long-term support (LTS) releases will define 95 // `ABSL_LTS_RELEASE_VERSION` to the integer representing the date string of the 96 // LTS release version, and will define `ABSL_LTS_RELEASE_PATCH_LEVEL` to the 97 // integer representing the patch-level for that release. 98 // 99 // For example, for LTS release version "20300401.2", this would give us 100 // ABSL_LTS_RELEASE_VERSION == 20300401 && ABSL_LTS_RELEASE_PATCH_LEVEL == 2 101 // 102 // These symbols will not be defined in non-LTS code. 103 // 104 // Abseil recommends that clients live-at-head. Therefore, if you are using 105 // these symbols to assert a minimum version requirement, we recommend you do it 106 // as 107 // 108 // #if defined(ABSL_LTS_RELEASE_VERSION) && ABSL_LTS_RELEASE_VERSION < 20300401 109 // #error Project foo requires Abseil LTS version >= 20300401 110 // #endif 111 // 112 // The `defined(ABSL_LTS_RELEASE_VERSION)` part of the check excludes 113 // live-at-head clients from the minimum version assertion. 114 // 115 // See https://abseil.io/about/releases for more information on Abseil release 116 // management. 117 // 118 // LTS releases can be obtained from 119 // https://github.com/abseil/abseil-cpp/releases. 120 #undef ABSL_LTS_RELEASE_VERSION 121 #undef ABSL_LTS_RELEASE_PATCH_LEVEL 122 123 // Helper macro to convert a CPP variable to a string literal. 124 #define ABSL_INTERNAL_DO_TOKEN_STR(x) #x 125 #define ABSL_INTERNAL_TOKEN_STR(x) ABSL_INTERNAL_DO_TOKEN_STR(x) 126 127 // ----------------------------------------------------------------------------- 128 // Abseil namespace annotations 129 // ----------------------------------------------------------------------------- 130 131 // ABSL_NAMESPACE_BEGIN/ABSL_NAMESPACE_END 132 // 133 // An annotation placed at the beginning/end of each `namespace absl` scope. 134 // This is used to inject an inline namespace. 135 // 136 // The proper way to write Abseil code in the `absl` namespace is: 137 // 138 // namespace absl { 139 // ABSL_NAMESPACE_BEGIN 140 // 141 // void Foo(); // absl::Foo(). 142 // 143 // ABSL_NAMESPACE_END 144 // } // namespace absl 145 // 146 // Users of Abseil should not use these macros, because users of Abseil should 147 // not write `namespace absl {` in their own code for any reason. (Abseil does 148 // not support forward declarations of its own types, nor does it support 149 // user-provided specialization of Abseil templates. Code that violates these 150 // rules may be broken without warning.) 151 #if !defined(ABSL_OPTION_USE_INLINE_NAMESPACE) || \ 152 !defined(ABSL_OPTION_INLINE_NAMESPACE_NAME) 153 #error options.h is misconfigured. 154 #endif 155 156 // Check that ABSL_OPTION_INLINE_NAMESPACE_NAME is neither "head" nor "" 157 #if defined(__cplusplus) && ABSL_OPTION_USE_INLINE_NAMESPACE == 1 158 159 #define ABSL_INTERNAL_INLINE_NAMESPACE_STR \ 160 ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME) 161 162 static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0', 163 "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must " 164 "not be empty."); 165 static_assert(ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' || 166 ABSL_INTERNAL_INLINE_NAMESPACE_STR[1] != 'e' || 167 ABSL_INTERNAL_INLINE_NAMESPACE_STR[2] != 'a' || 168 ABSL_INTERNAL_INLINE_NAMESPACE_STR[3] != 'd' || 169 ABSL_INTERNAL_INLINE_NAMESPACE_STR[4] != '\0', 170 "options.h misconfigured: ABSL_OPTION_INLINE_NAMESPACE_NAME must " 171 "be changed to a new, unique identifier name."); 172 173 #endif 174 175 #if ABSL_OPTION_USE_INLINE_NAMESPACE == 0 176 #define ABSL_NAMESPACE_BEGIN 177 #define ABSL_NAMESPACE_END 178 #define ABSL_INTERNAL_C_SYMBOL(x) x 179 #elif ABSL_OPTION_USE_INLINE_NAMESPACE == 1 180 #define ABSL_NAMESPACE_BEGIN \ 181 inline namespace ABSL_OPTION_INLINE_NAMESPACE_NAME { 182 #define ABSL_NAMESPACE_END } 183 #define ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v) x##_##v 184 #define ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, v) \ 185 ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v) 186 #define ABSL_INTERNAL_C_SYMBOL(x) \ 187 ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, ABSL_OPTION_INLINE_NAMESPACE_NAME) 188 #else 189 #error options.h is misconfigured. 190 #endif 191 192 // ----------------------------------------------------------------------------- 193 // Compiler Feature Checks 194 // ----------------------------------------------------------------------------- 195 196 // ABSL_HAVE_BUILTIN() 197 // 198 // Checks whether the compiler supports a Clang Feature Checking Macro, and if 199 // so, checks whether it supports the provided builtin function "x" where x 200 // is one of the functions noted in 201 // https://clang.llvm.org/docs/LanguageExtensions.html 202 // 203 // Note: Use this macro to avoid an extra level of #ifdef __has_builtin check. 204 // http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html 205 #ifdef __has_builtin 206 #define ABSL_HAVE_BUILTIN(x) __has_builtin(x) 207 #else 208 #define ABSL_HAVE_BUILTIN(x) 0 209 #endif 210 211 #ifdef __has_feature 212 #define ABSL_HAVE_FEATURE(f) __has_feature(f) 213 #else 214 #define ABSL_HAVE_FEATURE(f) 0 215 #endif 216 217 // Portable check for GCC minimum version: 218 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html 219 #if defined(__GNUC__) && defined(__GNUC_MINOR__) 220 #define ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) \ 221 (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y)) 222 #else 223 #define ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) 0 224 #endif 225 226 #if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__) 227 #define ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) \ 228 (__clang_major__ > (x) || __clang_major__ == (x) && __clang_minor__ >= (y)) 229 #else 230 #define ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) 0 231 #endif 232 233 // ABSL_HAVE_TLS is defined to 1 when __thread should be supported. 234 // We assume __thread is supported on Linux when compiled with Clang or 235 // compiled against libstdc++ with _GLIBCXX_HAVE_TLS defined. 236 #ifdef ABSL_HAVE_TLS 237 #error ABSL_HAVE_TLS cannot be directly set 238 #elif (defined(__linux__)) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS)) 239 #define ABSL_HAVE_TLS 1 240 #endif 241 242 // ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 243 // 244 // Checks whether `std::is_trivially_destructible<T>` is supported. 245 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 246 #error ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set 247 #define ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1 248 #endif 249 250 // ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 251 // 252 // Checks whether `std::is_trivially_default_constructible<T>` and 253 // `std::is_trivially_copy_constructible<T>` are supported. 254 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 255 #error ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set 256 #else 257 #define ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1 258 #endif 259 260 // ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 261 // 262 // Checks whether `std::is_trivially_copy_assignable<T>` is supported. 263 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 264 #error ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot be directly set 265 #else 266 #define ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1 267 #endif 268 269 // ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE 270 // 271 // Checks whether `std::is_trivially_copyable<T>` is supported. 272 #ifdef ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE 273 #error ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE cannot be directly set 274 #define ABSL_HAVE_STD_IS_TRIVIALLY_COPYABLE 1 275 #endif 276 277 // ABSL_HAVE_THREAD_LOCAL 278 // 279 // Checks whether the `thread_local` storage duration specifier is supported. 280 #ifdef ABSL_HAVE_THREAD_LOCAL 281 #error ABSL_HAVE_THREAD_LOCAL cannot be directly set 282 #elif !defined(__XTENSA__) 283 #define ABSL_HAVE_THREAD_LOCAL 1 284 #endif 285 286 // ABSL_HAVE_INTRINSIC_INT128 287 // 288 // Checks whether the __int128 compiler extension for a 128-bit integral type is 289 // supported. 290 // 291 // Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is 292 // supported, but we avoid using it in certain cases: 293 // * On Clang: 294 // * Building using Clang for Windows, where the Clang runtime library has 295 // 128-bit support only on LP64 architectures, but Windows is LLP64. 296 // * On Nvidia's nvcc: 297 // * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions 298 // actually support __int128. 299 #ifdef ABSL_HAVE_INTRINSIC_INT128 300 #error ABSL_HAVE_INTRINSIC_INT128 cannot be directly set 301 #elif defined(__SIZEOF_INT128__) 302 #if (defined(__clang__) && !defined(_WIN32)) || \ 303 (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \ 304 (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__)) 305 #define ABSL_HAVE_INTRINSIC_INT128 1 306 #elif defined(__CUDACC__) 307 // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a 308 // string explaining that it has been removed starting with CUDA 9. We use 309 // nested #ifs because there is no short-circuiting in the preprocessor. 310 // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined. 311 #if __CUDACC_VER__ >= 70000 312 #define ABSL_HAVE_INTRINSIC_INT128 1 313 #endif // __CUDACC_VER__ >= 70000 314 #endif // defined(__CUDACC__) 315 #endif // ABSL_HAVE_INTRINSIC_INT128 316 317 // ABSL_HAVE_EXCEPTIONS 318 // 319 // Checks whether the compiler both supports and enables exceptions. Many 320 // compilers support a "no exceptions" mode that disables exceptions. 321 // 322 // Generally, when ABSL_HAVE_EXCEPTIONS is not defined: 323 // 324 // * Code using `throw` and `try` may not compile. 325 // * The `noexcept` specifier will still compile and behave as normal. 326 // * The `noexcept` operator may still return `false`. 327 // 328 // For further details, consult the compiler's documentation. 329 #ifdef ABSL_HAVE_EXCEPTIONS 330 #error ABSL_HAVE_EXCEPTIONS cannot be directly set. 331 #elif ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(3, 6) 332 // Clang >= 3.6 333 #if ABSL_HAVE_FEATURE(cxx_exceptions) 334 #define ABSL_HAVE_EXCEPTIONS 1 335 #endif // ABSL_HAVE_FEATURE(cxx_exceptions) 336 #elif defined(__clang__) 337 // Clang < 3.6 338 // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro 339 #if defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions) 340 #define ABSL_HAVE_EXCEPTIONS 1 341 #endif // defined(__EXCEPTIONS) && ABSL_HAVE_FEATURE(cxx_exceptions) 342 // Handle remaining special cases and default to exceptions being supported. 343 #elif !(defined(__GNUC__) && !defined(__cpp_exceptions)) && \ 344 !(defined(_MSC_VER) && !defined(_CPPUNWIND)) 345 #define ABSL_HAVE_EXCEPTIONS 1 346 #endif 347 348 // ----------------------------------------------------------------------------- 349 // Platform Feature Checks 350 // ----------------------------------------------------------------------------- 351 352 // Currently supported operating systems and associated preprocessor 353 // symbols: 354 // 355 // Linux and Linux-derived __linux__ 356 // Android __ANDROID__ (implies __linux__) 357 // Linux (non-Android) __linux__ && !__ANDROID__ 358 // Darwin (macOS and iOS) __APPLE__ 359 // Akaros (http://akaros.org) __ros__ 360 // Windows _WIN32 361 // NaCL __native_client__ 362 // AsmJS __asmjs__ 363 // WebAssembly (Emscripten) __EMSCRIPTEN__ 364 // Fuchsia __Fuchsia__ 365 // 366 // Note that since Android defines both __ANDROID__ and __linux__, one 367 // may probe for either Linux or Android by simply testing for __linux__. 368 369 // ABSL_HAVE_MMAP 370 // 371 // Checks whether the platform has an mmap(2) implementation as defined in 372 // POSIX.1-2001. 373 #ifdef ABSL_HAVE_MMAP 374 #error ABSL_HAVE_MMAP cannot be directly set 375 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ 376 defined(_AIX) || defined(__ros__) || defined(__native_client__) || \ 377 defined(__asmjs__) || defined(__EMSCRIPTEN__) || defined(__Fuchsia__) || \ 378 defined(__sun) || defined(__myriad2__) || defined(__HAIKU__) || \ 379 defined(__OpenBSD__) || defined(__NetBSD__) || defined(__QNX__) || \ 380 defined(__VXWORKS__) || defined(__hexagon__) || defined(__XTENSA__) 381 #define ABSL_HAVE_MMAP 1 382 #endif 383 384 // ABSL_HAVE_PTHREAD_GETSCHEDPARAM 385 // 386 // Checks whether the platform implements the pthread_(get|set)schedparam(3) 387 // functions as defined in POSIX.1-2001. 388 #ifdef ABSL_HAVE_PTHREAD_GETSCHEDPARAM 389 #error ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set 390 #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ 391 defined(_AIX) || defined(__ros__) || defined(__OpenBSD__) || \ 392 defined(__NetBSD__) || defined(__VXWORKS__) 393 #define ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1 394 #endif 395 396 // ABSL_HAVE_SCHED_GETCPU 397 // 398 // Checks whether sched_getcpu is available. 399 #ifdef ABSL_HAVE_SCHED_GETCPU 400 #error ABSL_HAVE_SCHED_GETCPU cannot be directly set 401 #elif defined(__linux__) 402 #define ABSL_HAVE_SCHED_GETCPU 1 403 #endif 404 405 // ABSL_HAVE_SCHED_YIELD 406 // 407 // Checks whether the platform implements sched_yield(2) as defined in 408 // POSIX.1-2001. 409 #ifdef ABSL_HAVE_SCHED_YIELD 410 #error ABSL_HAVE_SCHED_YIELD cannot be directly set 411 #elif defined(__linux__) || defined(__ros__) || defined(__native_client__) || \ 412 defined(__VXWORKS__) 413 #define ABSL_HAVE_SCHED_YIELD 1 414 #endif 415 416 // ABSL_HAVE_SEMAPHORE_H 417 // 418 // Checks whether the platform supports the <semaphore.h> header and sem_init(3) 419 // family of functions as standardized in POSIX.1-2001. 420 // 421 // Note: While Apple provides <semaphore.h> for both iOS and macOS, it is 422 // explicitly deprecated and will cause build failures if enabled for those 423 // platforms. We side-step the issue by not defining it here for Apple 424 // platforms. 425 #ifdef ABSL_HAVE_SEMAPHORE_H 426 #error ABSL_HAVE_SEMAPHORE_H cannot be directly set 427 #elif defined(__linux__) || defined(__ros__) || defined(__VXWORKS__) 428 #define ABSL_HAVE_SEMAPHORE_H 1 429 #endif 430 431 // ABSL_HAVE_ALARM 432 // 433 // Checks whether the platform supports the <signal.h> header and alarm(2) 434 // function as standardized in POSIX.1-2001. 435 #ifdef ABSL_HAVE_ALARM 436 #error ABSL_HAVE_ALARM cannot be directly set 437 #elif defined(__GOOGLE_GRTE_VERSION__) 438 // feature tests for Google's GRTE 439 #define ABSL_HAVE_ALARM 1 440 #elif defined(__GLIBC__) 441 // feature test for glibc 442 #define ABSL_HAVE_ALARM 1 443 #elif defined(_MSC_VER) 444 // feature tests for Microsoft's library 445 #elif defined(__MINGW32__) 446 // mingw32 doesn't provide alarm(2): 447 // https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h 448 // mingw-w64 provides a no-op implementation: 449 // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c 450 #elif defined(__EMSCRIPTEN__) 451 // emscripten doesn't support signals 452 #elif defined(__wasi__) 453 // WASI doesn't support signals 454 #elif defined(__Fuchsia__) 455 // Signals don't exist on fuchsia. 456 #elif defined(__native_client__) 457 // Signals don't exist on hexagon/QuRT 458 #elif defined(__hexagon__) 459 #else 460 // other standard libraries 461 #define ABSL_HAVE_ALARM 1 462 #endif 463 464 // ABSL_IS_LITTLE_ENDIAN 465 // ABSL_IS_BIG_ENDIAN 466 // 467 // Checks the endianness of the platform. 468 // 469 // Prefer using `std::endian` in C++20, or `absl::endian` from 470 // absl/numeric/bits.h prior to C++20. 471 // 472 // Notes: uses the built in endian macros provided by GCC (since 4.6) and 473 // Clang (since 3.2); see 474 // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html. 475 // Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error. 476 #if defined(ABSL_IS_BIG_ENDIAN) 477 #error "ABSL_IS_BIG_ENDIAN cannot be directly set." 478 #endif 479 #if defined(ABSL_IS_LITTLE_ENDIAN) 480 #error "ABSL_IS_LITTLE_ENDIAN cannot be directly set." 481 #endif 482 483 #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \ 484 __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) 485 #define ABSL_IS_LITTLE_ENDIAN 1 486 #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \ 487 __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 488 #define ABSL_IS_BIG_ENDIAN 1 489 #elif defined(_WIN32) 490 #define ABSL_IS_LITTLE_ENDIAN 1 491 #else 492 #error "absl endian detection needs to be set up for your compiler" 493 #endif 494 495 // macOS < 10.13 and iOS < 12 don't support <any>, <optional>, or <variant> 496 // because the libc++ shared library shipped on the system doesn't have the 497 // requisite exported symbols. See 498 // https://github.com/abseil/abseil-cpp/issues/207 and 499 // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes 500 // 501 // libc++ spells out the availability requirements in the file 502 // llvm-project/libcxx/include/__config via the #define 503 // _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS. The set of versions has been 504 // modified a few times, via 505 // https://github.com/llvm/llvm-project/commit/7fb40e1569dd66292b647f4501b85517e9247953 506 // and 507 // https://github.com/llvm/llvm-project/commit/0bc451e7e137c4ccadcd3377250874f641ca514a 508 // The second has the actually correct versions, thus, is what we copy here. 509 #if defined(__APPLE__) && \ 510 ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ 511 __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101300) || \ 512 (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \ 513 __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \ 514 (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \ 515 __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000) || \ 516 (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \ 517 __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 120000)) 518 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1 519 #else 520 #define ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0 521 #endif 522 523 // Deprecated macros for polyfill detection. 524 #define ABSL_HAVE_STD_ANY 1 525 #define ABSL_USES_STD_ANY 1 526 #define ABSL_HAVE_STD_OPTIONAL 1 527 #define ABSL_USES_STD_OPTIONAL 1 528 #define ABSL_HAVE_STD_VARIANT 1 529 #define ABSL_USES_STD_VARIANT 1 530 531 // ABSL_HAVE_STD_STRING_VIEW 532 // 533 // Checks whether C++17 std::string_view is available. 534 #ifdef ABSL_HAVE_STD_STRING_VIEW 535 #error "ABSL_HAVE_STD_STRING_VIEW cannot be directly set." 536 #elif defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L 537 #define ABSL_HAVE_STD_STRING_VIEW 1 538 #elif defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ 539 ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L 540 #define ABSL_HAVE_STD_STRING_VIEW 1 541 #endif 542 543 // ABSL_HAVE_STD_ORDERING 544 // 545 // Checks whether C++20 std::{partial,weak,strong}_ordering are available. 546 // 547 // __cpp_lib_three_way_comparison is missing on libc++ 548 // (https://github.com/llvm/llvm-project/issues/73953) so treat it as defined 549 // when building in C++20 mode. 550 #ifdef ABSL_HAVE_STD_ORDERING 551 #error "ABSL_HAVE_STD_ORDERING cannot be directly set." 552 #elif (defined(__cpp_lib_three_way_comparison) && \ 553 __cpp_lib_three_way_comparison >= 201907L) || \ 554 (defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ 555 ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L) 556 #define ABSL_HAVE_STD_ORDERING 1 557 #endif 558 559 // ABSL_USES_STD_STRING_VIEW 560 // 561 // Indicates whether absl::string_view is an alias for std::string_view. 562 #if !defined(ABSL_OPTION_USE_STD_STRING_VIEW) 563 #error options.h is misconfigured. 564 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \ 565 (ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \ 566 !defined(ABSL_HAVE_STD_STRING_VIEW)) 567 #undef ABSL_USES_STD_STRING_VIEW 568 #elif ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \ 569 (ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \ 570 defined(ABSL_HAVE_STD_STRING_VIEW)) 571 #define ABSL_USES_STD_STRING_VIEW 1 572 #else 573 #error options.h is misconfigured. 574 #endif 575 576 // ABSL_USES_STD_ORDERING 577 // 578 // Indicates whether absl::{partial,weak,strong}_ordering are aliases for the 579 // std:: ordering types. 580 #if !defined(ABSL_OPTION_USE_STD_ORDERING) 581 #error options.h is misconfigured. 582 #elif ABSL_OPTION_USE_STD_ORDERING == 0 || \ 583 (ABSL_OPTION_USE_STD_ORDERING == 2 && !defined(ABSL_HAVE_STD_ORDERING)) 584 #undef ABSL_USES_STD_ORDERING 585 #elif ABSL_OPTION_USE_STD_ORDERING == 1 || \ 586 (ABSL_OPTION_USE_STD_ORDERING == 2 && defined(ABSL_HAVE_STD_ORDERING)) 587 #define ABSL_USES_STD_ORDERING 1 588 #else 589 #error options.h is misconfigured. 590 #endif 591 592 // ABSL_INTERNAL_MANGLED_NS 593 // ABSL_INTERNAL_MANGLED_BACKREFERENCE 594 // 595 // Internal macros for building up mangled names in our internal fork of CCTZ. 596 // This implementation detail is only needed and provided for the MSVC build. 597 // 598 // These macros both expand to string literals. ABSL_INTERNAL_MANGLED_NS is 599 // the mangled spelling of the `absl` namespace, and 600 // ABSL_INTERNAL_MANGLED_BACKREFERENCE is a back-reference integer representing 601 // the proper count to skip past the CCTZ fork namespace names. (This number 602 // is one larger when there is an inline namespace name to skip.) 603 #if defined(_MSC_VER) 604 #if ABSL_OPTION_USE_INLINE_NAMESPACE == 0 605 #define ABSL_INTERNAL_MANGLED_NS "absl" 606 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "5" 607 #else 608 #define ABSL_INTERNAL_MANGLED_NS \ 609 ABSL_INTERNAL_TOKEN_STR(ABSL_OPTION_INLINE_NAMESPACE_NAME) "@absl" 610 #define ABSL_INTERNAL_MANGLED_BACKREFERENCE "6" 611 #endif 612 #endif 613 614 // ABSL_DLL 615 // 616 // When building Abseil as a DLL, this macro expands to `__declspec(dllexport)` 617 // so we can annotate symbols appropriately as being exported. When used in 618 // headers consuming a DLL, this macro expands to `__declspec(dllimport)` so 619 // that consumers know the symbol is defined inside the DLL. In all other cases, 620 // the macro expands to nothing. 621 #if defined(_MSC_VER) 622 #if defined(ABSL_BUILD_DLL) 623 #define ABSL_DLL __declspec(dllexport) 624 #elif defined(ABSL_CONSUME_DLL) 625 #define ABSL_DLL __declspec(dllimport) 626 #else 627 #define ABSL_DLL 628 #endif 629 #else 630 #define ABSL_DLL 631 #endif // defined(_MSC_VER) 632 633 #if defined(_MSC_VER) 634 #if defined(ABSL_BUILD_TEST_DLL) 635 #define ABSL_TEST_DLL __declspec(dllexport) 636 #elif defined(ABSL_CONSUME_TEST_DLL) 637 #define ABSL_TEST_DLL __declspec(dllimport) 638 #else 639 #define ABSL_TEST_DLL 640 #endif 641 #else 642 #define ABSL_TEST_DLL 643 #endif // defined(_MSC_VER) 644 645 // ABSL_HAVE_MEMORY_SANITIZER 646 // 647 // MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of 648 // a compiler instrumentation module and a run-time library. 649 #ifdef ABSL_HAVE_MEMORY_SANITIZER 650 #error "ABSL_HAVE_MEMORY_SANITIZER cannot be directly set." 651 #elif !defined(__native_client__) && ABSL_HAVE_FEATURE(memory_sanitizer) 652 #define ABSL_HAVE_MEMORY_SANITIZER 1 653 #endif 654 655 // ABSL_HAVE_THREAD_SANITIZER 656 // 657 // ThreadSanitizer (TSan) is a fast data race detector. 658 #ifdef ABSL_HAVE_THREAD_SANITIZER 659 #error "ABSL_HAVE_THREAD_SANITIZER cannot be directly set." 660 #elif defined(__SANITIZE_THREAD__) 661 #define ABSL_HAVE_THREAD_SANITIZER 1 662 #elif ABSL_HAVE_FEATURE(thread_sanitizer) 663 #define ABSL_HAVE_THREAD_SANITIZER 1 664 #endif 665 666 // ABSL_HAVE_ADDRESS_SANITIZER 667 // 668 // AddressSanitizer (ASan) is a fast memory error detector. 669 #ifdef ABSL_HAVE_ADDRESS_SANITIZER 670 #error "ABSL_HAVE_ADDRESS_SANITIZER cannot be directly set." 671 #elif defined(__SANITIZE_ADDRESS__) 672 #define ABSL_HAVE_ADDRESS_SANITIZER 1 673 #elif ABSL_HAVE_FEATURE(address_sanitizer) 674 #define ABSL_HAVE_ADDRESS_SANITIZER 1 675 #endif 676 677 // ABSL_HAVE_HWADDRESS_SANITIZER 678 // 679 // Hardware-Assisted AddressSanitizer (or HWASAN) is even faster than asan 680 // memory error detector which can use CPU features like ARM TBI, Intel LAM or 681 // AMD UAI. 682 #ifdef ABSL_HAVE_HWADDRESS_SANITIZER 683 #error "ABSL_HAVE_HWADDRESS_SANITIZER cannot be directly set." 684 #elif defined(__SANITIZE_HWADDRESS__) 685 #define ABSL_HAVE_HWADDRESS_SANITIZER 1 686 #elif ABSL_HAVE_FEATURE(hwaddress_sanitizer) 687 #define ABSL_HAVE_HWADDRESS_SANITIZER 1 688 #endif 689 690 // ABSL_HAVE_DATAFLOW_SANITIZER 691 // 692 // Dataflow Sanitizer (or DFSAN) is a generalised dynamic data flow analysis. 693 #ifdef ABSL_HAVE_DATAFLOW_SANITIZER 694 #error "ABSL_HAVE_DATAFLOW_SANITIZER cannot be directly set." 695 #elif defined(DATAFLOW_SANITIZER) 696 // GCC provides no method for detecting the presence of the standalone 697 // DataFlowSanitizer (-fsanitize=dataflow), so GCC users of -fsanitize=dataflow 698 // should also use -DDATAFLOW_SANITIZER. 699 #define ABSL_HAVE_DATAFLOW_SANITIZER 1 700 #elif ABSL_HAVE_FEATURE(dataflow_sanitizer) 701 #define ABSL_HAVE_DATAFLOW_SANITIZER 1 702 #endif 703 704 // ABSL_HAVE_LEAK_SANITIZER 705 // 706 // LeakSanitizer (or lsan) is a detector of memory leaks. 707 // https://clang.llvm.org/docs/LeakSanitizer.html 708 // https://github.com/google/sanitizers/wiki/AddressSanitizerLeakSanitizer 709 // 710 // The macro ABSL_HAVE_LEAK_SANITIZER can be used to detect at compile-time 711 // whether the LeakSanitizer is potentially available. However, just because the 712 // LeakSanitizer is available does not mean it is active. Use the 713 // always-available run-time interface in //absl/debugging/leak_check.h for 714 // interacting with LeakSanitizer. 715 #ifdef ABSL_HAVE_LEAK_SANITIZER 716 #error "ABSL_HAVE_LEAK_SANITIZER cannot be directly set." 717 #elif defined(LEAK_SANITIZER) 718 // GCC provides no method for detecting the presence of the standalone 719 // LeakSanitizer (-fsanitize=leak), so GCC users of -fsanitize=leak should also 720 // use -DLEAK_SANITIZER. 721 #define ABSL_HAVE_LEAK_SANITIZER 1 722 // Clang standalone LeakSanitizer (-fsanitize=leak) 723 #elif ABSL_HAVE_FEATURE(leak_sanitizer) 724 #define ABSL_HAVE_LEAK_SANITIZER 1 725 #elif defined(ABSL_HAVE_ADDRESS_SANITIZER) 726 // GCC or Clang using the LeakSanitizer integrated into AddressSanitizer. 727 #define ABSL_HAVE_LEAK_SANITIZER 1 728 #endif 729 730 // ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 731 // 732 // Deprecated: always defined to 1. 733 // Class template argument deduction is a language feature added in C++17, 734 // which means all versions of C++ supported by Abseil have it. 735 #ifdef ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 736 #error "ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION cannot be directly set." 737 #else 738 #define ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1 739 #endif 740 741 // `ABSL_INTERNAL_HAS_RTTI` determines whether abseil is being compiled with 742 // RTTI support. 743 #ifdef ABSL_INTERNAL_HAS_RTTI 744 #error ABSL_INTERNAL_HAS_RTTI cannot be directly set 745 #elif ABSL_HAVE_FEATURE(cxx_rtti) 746 #define ABSL_INTERNAL_HAS_RTTI 1 747 #elif defined(__GNUC__) && defined(__GXX_RTTI) 748 #define ABSL_INTERNAL_HAS_RTTI 1 749 #elif defined(_MSC_VER) && defined(_CPPRTTI) 750 #define ABSL_INTERNAL_HAS_RTTI 1 751 #elif !defined(__GNUC__) && !defined(_MSC_VER) 752 // Unknown compiler, default to RTTI 753 #define ABSL_INTERNAL_HAS_RTTI 1 754 #endif 755 756 // `ABSL_INTERNAL_HAS_CXA_DEMANGLE` determines whether `abi::__cxa_demangle` is 757 // available. 758 #ifdef ABSL_INTERNAL_HAS_CXA_DEMANGLE 759 #error ABSL_INTERNAL_HAS_CXA_DEMANGLE cannot be directly set 760 #elif defined(OS_ANDROID) && (defined(__i386__) || defined(__x86_64__)) 761 #define ABSL_INTERNAL_HAS_CXA_DEMANGLE 0 762 #elif defined(__GNUC__) 763 #define ABSL_INTERNAL_HAS_CXA_DEMANGLE 1 764 #elif defined(__clang__) && !defined(_MSC_VER) 765 #define ABSL_INTERNAL_HAS_CXA_DEMANGLE 1 766 #endif 767 768 // ABSL_INTERNAL_HAVE_SSE is used for compile-time detection of SSE support. 769 // See https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html for an overview of 770 // which architectures support the various x86 instruction sets. 771 #ifdef ABSL_INTERNAL_HAVE_SSE 772 #error ABSL_INTERNAL_HAVE_SSE cannot be directly set 773 #elif defined(__SSE__) 774 #define ABSL_INTERNAL_HAVE_SSE 1 775 #elif (defined(_M_X64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 1)) && \ 776 !defined(_M_ARM64EC) 777 // MSVC only defines _M_IX86_FP for x86 32-bit code, and _M_IX86_FP >= 1 778 // indicates that at least SSE was targeted with the /arch:SSE option. 779 // All x86-64 processors support SSE, so support can be assumed. 780 // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros 781 #define ABSL_INTERNAL_HAVE_SSE 1 782 #endif 783 784 // ABSL_INTERNAL_HAVE_SSE2 is used for compile-time detection of SSE2 support. 785 // See https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html for an overview of 786 // which architectures support the various x86 instruction sets. 787 #ifdef ABSL_INTERNAL_HAVE_SSE2 788 #error ABSL_INTERNAL_HAVE_SSE2 cannot be directly set 789 #elif defined(__SSE2__) 790 #define ABSL_INTERNAL_HAVE_SSE2 1 791 #elif (defined(_M_X64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2)) && \ 792 !defined(_M_ARM64EC) 793 // MSVC only defines _M_IX86_FP for x86 32-bit code, and _M_IX86_FP >= 2 794 // indicates that at least SSE2 was targeted with the /arch:SSE2 option. 795 // All x86-64 processors support SSE2, so support can be assumed. 796 // https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros 797 #define ABSL_INTERNAL_HAVE_SSE2 1 798 #endif 799 800 // ABSL_INTERNAL_HAVE_SSSE3 is used for compile-time detection of SSSE3 support. 801 // See https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html for an overview of 802 // which architectures support the various x86 instruction sets. 803 // 804 // MSVC does not have a mode that targets SSSE3 at compile-time. To use SSSE3 805 // with MSVC requires either assuming that the code will only every run on CPUs 806 // that support SSSE3, otherwise __cpuid() can be used to detect support at 807 // runtime and fallback to a non-SSSE3 implementation when SSSE3 is unsupported 808 // by the CPU. 809 #ifdef ABSL_INTERNAL_HAVE_SSSE3 810 #error ABSL_INTERNAL_HAVE_SSSE3 cannot be directly set 811 #elif defined(__SSSE3__) 812 #define ABSL_INTERNAL_HAVE_SSSE3 1 813 #endif 814 815 // ABSL_INTERNAL_HAVE_ARM_NEON is used for compile-time detection of NEON (ARM 816 // SIMD). 817 // 818 // If __CUDA_ARCH__ is defined, then we are compiling CUDA code in device mode. 819 // In device mode, NEON intrinsics are not available, regardless of host 820 // platform. 821 // https://llvm.org/docs/CompileCudaWithLLVM.html#detecting-clang-vs-nvcc-from-code 822 #ifdef ABSL_INTERNAL_HAVE_ARM_NEON 823 #error ABSL_INTERNAL_HAVE_ARM_NEON cannot be directly set 824 #elif defined(__ARM_NEON) && !(defined(__NVCC__) && defined(__CUDACC__)) 825 #define ABSL_INTERNAL_HAVE_ARM_NEON 1 826 #endif 827 828 // ABSL_HAVE_CONSTANT_EVALUATED is used for compile-time detection of 829 // constant evaluation support through `absl::is_constant_evaluated`. 830 #ifdef ABSL_HAVE_CONSTANT_EVALUATED 831 #error ABSL_HAVE_CONSTANT_EVALUATED cannot be directly set 832 #endif 833 #ifdef __cpp_lib_is_constant_evaluated 834 #define ABSL_HAVE_CONSTANT_EVALUATED 1 835 #elif ABSL_HAVE_BUILTIN(__builtin_is_constant_evaluated) 836 #define ABSL_HAVE_CONSTANT_EVALUATED 1 837 #endif 838 839 // ABSL_INTERNAL_CONSTEXPR_SINCE_CXXYY is used to conditionally define constexpr 840 // for different C++ versions. 841 // 842 // These macros are an implementation detail and will be unconditionally removed 843 // once the minimum supported C++ version catches up to a given version. 844 // 845 // For this reason, this symbol is considered INTERNAL and code outside of 846 // Abseil must not use it. 847 #if defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ 848 ABSL_INTERNAL_CPLUSPLUS_LANG >= 201703L 849 #define ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 constexpr 850 #else 851 #define ABSL_INTERNAL_CONSTEXPR_SINCE_CXX17 852 #endif 853 #if defined(ABSL_INTERNAL_CPLUSPLUS_LANG) && \ 854 ABSL_INTERNAL_CPLUSPLUS_LANG >= 202002L 855 #define ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 constexpr 856 #else 857 #define ABSL_INTERNAL_CONSTEXPR_SINCE_CXX20 858 #endif 859 860 // ABSL_INTERNAL_EMSCRIPTEN_VERSION combines Emscripten's three version macros 861 // into an integer that can be compared against. 862 #ifdef ABSL_INTERNAL_EMSCRIPTEN_VERSION 863 #error ABSL_INTERNAL_EMSCRIPTEN_VERSION cannot be directly set 864 #endif 865 #ifdef __EMSCRIPTEN__ 866 #include <emscripten/version.h> 867 #ifdef __EMSCRIPTEN_major__ 868 #if __EMSCRIPTEN_minor__ >= 1000 869 #error __EMSCRIPTEN_minor__ is too big to fit in ABSL_INTERNAL_EMSCRIPTEN_VERSION 870 #endif 871 #if __EMSCRIPTEN_tiny__ >= 1000 872 #error __EMSCRIPTEN_tiny__ is too big to fit in ABSL_INTERNAL_EMSCRIPTEN_VERSION 873 #endif 874 #define ABSL_INTERNAL_EMSCRIPTEN_VERSION \ 875 ((__EMSCRIPTEN_major__) * 1000000 + (__EMSCRIPTEN_minor__) * 1000 + \ 876 (__EMSCRIPTEN_tiny__)) 877 #endif 878 #endif 879 880 #endif // ABSL_BASE_CONFIG_H_ 881