config.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  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 (`Y_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 "y_absl/base/config.h"
  37. //
  38. // #ifdef Y_ABSL_HAVE_MMAP
  39. // #include "sys/mman.h"
  40. // #endif //Y_ABSL_HAVE_MMAP
  41. //
  42. // ...
  43. // #ifdef Y_ABSL_HAVE_MMAP
  44. // void *ptr = mmap(...);
  45. // ...
  46. // #endif // Y_ABSL_HAVE_MMAP
  47. #ifndef Y_ABSL_BASE_CONFIG_H_
  48. #define Y_ABSL_BASE_CONFIG_H_
  49. // Included for the __GLIBC__ macro (or similar macros on other systems).
  50. #include <limits.h>
  51. #ifdef __cplusplus
  52. // Included for __GLIBCXX__, _LIBCPP_VERSION
  53. #include <cstddef>
  54. #endif // __cplusplus
  55. #if defined(__APPLE__)
  56. // Included for TARGET_OS_IPHONE, __IPHONE_OS_VERSION_MIN_REQUIRED,
  57. // __IPHONE_8_0.
  58. #include <Availability.h>
  59. #include <TargetConditionals.h>
  60. #endif
  61. #include "y_absl/base/options.h"
  62. #include "y_absl/base/policy_checks.h"
  63. // Abseil long-term support (LTS) releases will define
  64. // `Y_ABSL_LTS_RELEASE_VERSION` to the integer representing the date string of the
  65. // LTS release version, and will define `Y_ABSL_LTS_RELEASE_PATCH_LEVEL` to the
  66. // integer representing the patch-level for that release.
  67. //
  68. // For example, for LTS release version "20300401.2", this would give us
  69. // Y_ABSL_LTS_RELEASE_VERSION == 20300401 && Y_ABSL_LTS_RELEASE_PATCH_LEVEL == 2
  70. //
  71. // These symbols will not be defined in non-LTS code.
  72. //
  73. // Abseil recommends that clients live-at-head. Therefore, if you are using
  74. // these symbols to assert a minimum version requirement, we recommend you do it
  75. // as
  76. //
  77. // #if defined(Y_ABSL_LTS_RELEASE_VERSION) && Y_ABSL_LTS_RELEASE_VERSION < 20300401
  78. // #error Project foo requires Abseil LTS version >= 20300401
  79. // #endif
  80. //
  81. // The `defined(Y_ABSL_LTS_RELEASE_VERSION)` part of the check excludes
  82. // live-at-head clients from the minimum version assertion.
  83. //
  84. // See https://abseil.io/about/releases for more information on Abseil release
  85. // management.
  86. //
  87. // LTS releases can be obtained from
  88. // https://github.com/abseil/abseil-cpp/releases.
  89. #define Y_ABSL_LTS_RELEASE_VERSION 20211102
  90. #define Y_ABSL_LTS_RELEASE_PATCH_LEVEL 0
  91. // Helper macro to convert a CPP variable to a string literal.
  92. #define Y_ABSL_INTERNAL_DO_TOKEN_STR(x) #x
  93. #define Y_ABSL_INTERNAL_TOKEN_STR(x) Y_ABSL_INTERNAL_DO_TOKEN_STR(x)
  94. // -----------------------------------------------------------------------------
  95. // Abseil namespace annotations
  96. // -----------------------------------------------------------------------------
  97. // Y_ABSL_NAMESPACE_BEGIN/Y_ABSL_NAMESPACE_END
  98. //
  99. // An annotation placed at the beginning/end of each `namespace y_absl` scope.
  100. // This is used to inject an inline namespace.
  101. //
  102. // The proper way to write Abseil code in the `y_absl` namespace is:
  103. //
  104. // namespace y_absl {
  105. // Y_ABSL_NAMESPACE_BEGIN
  106. //
  107. // void Foo(); // y_absl::Foo().
  108. //
  109. // Y_ABSL_NAMESPACE_END
  110. // } // namespace y_absl
  111. //
  112. // Users of Abseil should not use these macros, because users of Abseil should
  113. // not write `namespace y_absl {` in their own code for any reason. (Abseil does
  114. // not support forward declarations of its own types, nor does it support
  115. // user-provided specialization of Abseil templates. Code that violates these
  116. // rules may be broken without warning.)
  117. #if !defined(Y_ABSL_OPTION_USE_INLINE_NAMESPACE) || \
  118. !defined(Y_ABSL_OPTION_INLINE_NAMESPACE_NAME)
  119. #error options.h is misconfigured.
  120. #endif
  121. // Check that Y_ABSL_OPTION_INLINE_NAMESPACE_NAME is neither "head" nor ""
  122. #if defined(__cplusplus) && Y_ABSL_OPTION_USE_INLINE_NAMESPACE == 1
  123. #define Y_ABSL_INTERNAL_INLINE_NAMESPACE_STR \
  124. Y_ABSL_INTERNAL_TOKEN_STR(Y_ABSL_OPTION_INLINE_NAMESPACE_NAME)
  125. static_assert(Y_ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != '\0',
  126. "options.h misconfigured: Y_ABSL_OPTION_INLINE_NAMESPACE_NAME must "
  127. "not be empty.");
  128. static_assert(Y_ABSL_INTERNAL_INLINE_NAMESPACE_STR[0] != 'h' ||
  129. Y_ABSL_INTERNAL_INLINE_NAMESPACE_STR[1] != 'e' ||
  130. Y_ABSL_INTERNAL_INLINE_NAMESPACE_STR[2] != 'a' ||
  131. Y_ABSL_INTERNAL_INLINE_NAMESPACE_STR[3] != 'd' ||
  132. Y_ABSL_INTERNAL_INLINE_NAMESPACE_STR[4] != '\0',
  133. "options.h misconfigured: Y_ABSL_OPTION_INLINE_NAMESPACE_NAME must "
  134. "be changed to a new, unique identifier name.");
  135. #endif
  136. #if Y_ABSL_OPTION_USE_INLINE_NAMESPACE == 0
  137. #define Y_ABSL_NAMESPACE_BEGIN
  138. #define Y_ABSL_NAMESPACE_END
  139. #define Y_ABSL_INTERNAL_C_SYMBOL(x) x
  140. #elif Y_ABSL_OPTION_USE_INLINE_NAMESPACE == 1
  141. #define Y_ABSL_NAMESPACE_BEGIN \
  142. inline namespace Y_ABSL_OPTION_INLINE_NAMESPACE_NAME {
  143. #define Y_ABSL_NAMESPACE_END }
  144. #define Y_ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v) x##_##v
  145. #define Y_ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, v) \
  146. Y_ABSL_INTERNAL_C_SYMBOL_HELPER_2(x, v)
  147. #define Y_ABSL_INTERNAL_C_SYMBOL(x) \
  148. Y_ABSL_INTERNAL_C_SYMBOL_HELPER_1(x, Y_ABSL_OPTION_INLINE_NAMESPACE_NAME)
  149. #else
  150. #error options.h is misconfigured.
  151. #endif
  152. // -----------------------------------------------------------------------------
  153. // Compiler Feature Checks
  154. // -----------------------------------------------------------------------------
  155. // Y_ABSL_HAVE_BUILTIN()
  156. //
  157. // Checks whether the compiler supports a Clang Feature Checking Macro, and if
  158. // so, checks whether it supports the provided builtin function "x" where x
  159. // is one of the functions noted in
  160. // https://clang.llvm.org/docs/LanguageExtensions.html
  161. //
  162. // Note: Use this macro to avoid an extra level of #ifdef __has_builtin check.
  163. // http://releases.llvm.org/3.3/tools/clang/docs/LanguageExtensions.html
  164. #ifdef __has_builtin
  165. #define Y_ABSL_HAVE_BUILTIN(x) __has_builtin(x)
  166. #else
  167. #define Y_ABSL_HAVE_BUILTIN(x) 0
  168. #endif
  169. #if defined(__is_identifier)
  170. #define Y_ABSL_INTERNAL_HAS_KEYWORD(x) !(__is_identifier(x))
  171. #else
  172. #define Y_ABSL_INTERNAL_HAS_KEYWORD(x) 0
  173. #endif
  174. #ifdef __has_feature
  175. #define Y_ABSL_HAVE_FEATURE(f) __has_feature(f)
  176. #else
  177. #define Y_ABSL_HAVE_FEATURE(f) 0
  178. #endif
  179. // Portable check for GCC minimum version:
  180. // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
  181. #if defined(__GNUC__) && defined(__GNUC_MINOR__)
  182. #define Y_ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) \
  183. (__GNUC__ > (x) || __GNUC__ == (x) && __GNUC_MINOR__ >= (y))
  184. #else
  185. #define Y_ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(x, y) 0
  186. #endif
  187. #if defined(__clang__) && defined(__clang_major__) && defined(__clang_minor__)
  188. #define Y_ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) \
  189. (__clang_major__ > (x) || __clang_major__ == (x) && __clang_minor__ >= (y))
  190. #else
  191. #define Y_ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(x, y) 0
  192. #endif
  193. // Y_ABSL_HAVE_TLS is defined to 1 when __thread should be supported.
  194. // We assume __thread is supported on Linux when compiled with Clang or compiled
  195. // against libstdc++ with _GLIBCXX_HAVE_TLS defined.
  196. #ifdef Y_ABSL_HAVE_TLS
  197. #error Y_ABSL_HAVE_TLS cannot be directly set
  198. #elif defined(__linux__) && (defined(__clang__) || defined(_GLIBCXX_HAVE_TLS))
  199. #define Y_ABSL_HAVE_TLS 1
  200. #endif
  201. // Y_ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
  202. //
  203. // Checks whether `std::is_trivially_destructible<T>` is supported.
  204. //
  205. // Notes: All supported compilers using libc++ support this feature, as does
  206. // gcc >= 4.8.1 using libstdc++, and Visual Studio.
  207. #ifdef Y_ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE
  208. #error Y_ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE cannot be directly set
  209. #elif defined(_LIBCPP_VERSION) || defined(_MSC_VER) || \
  210. (!defined(__clang__) && defined(__GLIBCXX__) && \
  211. Y_ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(4, 8))
  212. #define Y_ABSL_HAVE_STD_IS_TRIVIALLY_DESTRUCTIBLE 1
  213. #endif
  214. // Y_ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE
  215. //
  216. // Checks whether `std::is_trivially_default_constructible<T>` and
  217. // `std::is_trivially_copy_constructible<T>` are supported.
  218. // Y_ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE
  219. //
  220. // Checks whether `std::is_trivially_copy_assignable<T>` is supported.
  221. // Notes: Clang with libc++ supports these features, as does gcc >= 7.4 with
  222. // libstdc++, or gcc >= 8.2 with libc++, and Visual Studio (but not NVCC).
  223. #if defined(Y_ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE)
  224. #error Y_ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE cannot be directly set
  225. #elif defined(Y_ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE)
  226. #error Y_ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE cannot directly set
  227. #elif (defined(__clang__) && defined(_LIBCPP_VERSION)) || \
  228. (!defined(__clang__) && \
  229. ((Y_ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(7, 4) && defined(__GLIBCXX__)) || \
  230. (Y_ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(8, 2) && \
  231. defined(_LIBCPP_VERSION)))) || \
  232. (defined(_MSC_VER) && !defined(__NVCC__))
  233. #define Y_ABSL_HAVE_STD_IS_TRIVIALLY_CONSTRUCTIBLE 1
  234. #define Y_ABSL_HAVE_STD_IS_TRIVIALLY_ASSIGNABLE 1
  235. #endif
  236. // Y_ABSL_HAVE_SOURCE_LOCATION_CURRENT
  237. //
  238. // Indicates whether `y_absl::SourceLocation::current()` will return useful
  239. // information in some contexts.
  240. #ifndef Y_ABSL_HAVE_SOURCE_LOCATION_CURRENT
  241. #if Y_ABSL_INTERNAL_HAS_KEYWORD(__builtin_LINE) && \
  242. Y_ABSL_INTERNAL_HAS_KEYWORD(__builtin_FILE)
  243. #define Y_ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
  244. #elif Y_ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(5, 0)
  245. #define Y_ABSL_HAVE_SOURCE_LOCATION_CURRENT 1
  246. #endif
  247. #endif
  248. // Y_ABSL_HAVE_THREAD_LOCAL
  249. //
  250. // Checks whether C++11's `thread_local` storage duration specifier is
  251. // supported.
  252. #ifdef Y_ABSL_HAVE_THREAD_LOCAL
  253. #error Y_ABSL_HAVE_THREAD_LOCAL cannot be directly set
  254. #elif defined(__APPLE__)
  255. // Notes:
  256. // * Xcode's clang did not support `thread_local` until version 8, and
  257. // even then not for all iOS < 9.0.
  258. // * Xcode 9.3 started disallowing `thread_local` for 32-bit iOS simulator
  259. // targeting iOS 9.x.
  260. // * Xcode 10 moves the deployment target check for iOS < 9.0 to link time
  261. // making Y_ABSL_HAVE_FEATURE unreliable there.
  262. //
  263. #if Y_ABSL_HAVE_FEATURE(cxx_thread_local) && \
  264. !(TARGET_OS_IPHONE && __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_9_0)
  265. #define Y_ABSL_HAVE_THREAD_LOCAL 1
  266. #endif
  267. #else // !defined(__APPLE__)
  268. #define Y_ABSL_HAVE_THREAD_LOCAL 1
  269. #endif
  270. // There are platforms for which TLS should not be used even though the compiler
  271. // makes it seem like it's supported (Android NDK < r12b for example).
  272. // This is primarily because of linker problems and toolchain misconfiguration:
  273. // Abseil does not intend to support this indefinitely. Currently, the newest
  274. // toolchain that we intend to support that requires this behavior is the
  275. // r11 NDK - allowing for a 5 year support window on that means this option
  276. // is likely to be removed around June of 2021.
  277. // TLS isn't supported until NDK r12b per
  278. // https://developer.android.com/ndk/downloads/revision_history.html
  279. // Since NDK r16, `__NDK_MAJOR__` and `__NDK_MINOR__` are defined in
  280. // <android/ndk-version.h>. For NDK < r16, users should define these macros,
  281. // e.g. `-D__NDK_MAJOR__=11 -D__NKD_MINOR__=0` for NDK r11.
  282. #if defined(__ANDROID__) && defined(__clang__)
  283. #if __has_include(<android/ndk-version.h>)
  284. #include <android/ndk-version.h>
  285. #endif // __has_include(<android/ndk-version.h>)
  286. #if defined(__ANDROID__) && defined(__clang__) && defined(__NDK_MAJOR__) && \
  287. defined(__NDK_MINOR__) && \
  288. ((__NDK_MAJOR__ < 12) || ((__NDK_MAJOR__ == 12) && (__NDK_MINOR__ < 1)))
  289. #undef Y_ABSL_HAVE_TLS
  290. #undef Y_ABSL_HAVE_THREAD_LOCAL
  291. #endif
  292. #endif // defined(__ANDROID__) && defined(__clang__)
  293. // Y_ABSL_HAVE_INTRINSIC_INT128
  294. //
  295. // Checks whether the __int128 compiler extension for a 128-bit integral type is
  296. // supported.
  297. //
  298. // Note: __SIZEOF_INT128__ is defined by Clang and GCC when __int128 is
  299. // supported, but we avoid using it in certain cases:
  300. // * On Clang:
  301. // * Building using Clang for Windows, where the Clang runtime library has
  302. // 128-bit support only on LP64 architectures, but Windows is LLP64.
  303. // * On Nvidia's nvcc:
  304. // * nvcc also defines __GNUC__ and __SIZEOF_INT128__, but not all versions
  305. // actually support __int128.
  306. #ifdef Y_ABSL_HAVE_INTRINSIC_INT128
  307. #error Y_ABSL_HAVE_INTRINSIC_INT128 cannot be directly set
  308. #elif defined(__SIZEOF_INT128__)
  309. #if (defined(__clang__) && !defined(_WIN32)) || \
  310. (defined(__CUDACC__) && __CUDACC_VER_MAJOR__ >= 9) || \
  311. (defined(__GNUC__) && !defined(__clang__) && !defined(__CUDACC__))
  312. #define Y_ABSL_HAVE_INTRINSIC_INT128 1
  313. #elif defined(__CUDACC__)
  314. // __CUDACC_VER__ is a full version number before CUDA 9, and is defined to a
  315. // string explaining that it has been removed starting with CUDA 9. We use
  316. // nested #ifs because there is no short-circuiting in the preprocessor.
  317. // NOTE: `__CUDACC__` could be undefined while `__CUDACC_VER__` is defined.
  318. #if __CUDACC_VER__ >= 70000
  319. #define Y_ABSL_HAVE_INTRINSIC_INT128 1
  320. #endif // __CUDACC_VER__ >= 70000
  321. #endif // defined(__CUDACC__)
  322. #endif // Y_ABSL_HAVE_INTRINSIC_INT128
  323. // Y_ABSL_HAVE_EXCEPTIONS
  324. //
  325. // Checks whether the compiler both supports and enables exceptions. Many
  326. // compilers support a "no exceptions" mode that disables exceptions.
  327. //
  328. // Generally, when Y_ABSL_HAVE_EXCEPTIONS is not defined:
  329. //
  330. // * Code using `throw` and `try` may not compile.
  331. // * The `noexcept` specifier will still compile and behave as normal.
  332. // * The `noexcept` operator may still return `false`.
  333. //
  334. // For further details, consult the compiler's documentation.
  335. #ifdef Y_ABSL_HAVE_EXCEPTIONS
  336. #error Y_ABSL_HAVE_EXCEPTIONS cannot be directly set.
  337. #elif Y_ABSL_INTERNAL_HAVE_MIN_CLANG_VERSION(3, 6)
  338. // Clang >= 3.6
  339. #if Y_ABSL_HAVE_FEATURE(cxx_exceptions)
  340. #define Y_ABSL_HAVE_EXCEPTIONS 1
  341. #endif // Y_ABSL_HAVE_FEATURE(cxx_exceptions)
  342. #elif defined(__clang__)
  343. // Clang < 3.6
  344. // http://releases.llvm.org/3.6.0/tools/clang/docs/ReleaseNotes.html#the-exceptions-macro
  345. #if defined(__EXCEPTIONS) && Y_ABSL_HAVE_FEATURE(cxx_exceptions)
  346. #define Y_ABSL_HAVE_EXCEPTIONS 1
  347. #endif // defined(__EXCEPTIONS) && Y_ABSL_HAVE_FEATURE(cxx_exceptions)
  348. // Handle remaining special cases and default to exceptions being supported.
  349. #elif !(defined(__GNUC__) && (__GNUC__ < 5) && !defined(__EXCEPTIONS)) && \
  350. !(Y_ABSL_INTERNAL_HAVE_MIN_GNUC_VERSION(5, 0) && \
  351. !defined(__cpp_exceptions)) && \
  352. !(defined(_MSC_VER) && !defined(_CPPUNWIND))
  353. #define Y_ABSL_HAVE_EXCEPTIONS 1
  354. #endif
  355. // -----------------------------------------------------------------------------
  356. // Platform Feature Checks
  357. // -----------------------------------------------------------------------------
  358. // Currently supported operating systems and associated preprocessor
  359. // symbols:
  360. //
  361. // Linux and Linux-derived __linux__
  362. // Android __ANDROID__ (implies __linux__)
  363. // Linux (non-Android) __linux__ && !__ANDROID__
  364. // Darwin (macOS and iOS) __APPLE__
  365. // Akaros (http://akaros.org) __ros__
  366. // Windows _WIN32
  367. // NaCL __native_client__
  368. // AsmJS __asmjs__
  369. // WebAssembly __wasm__
  370. // Fuchsia __Fuchsia__
  371. //
  372. // Note that since Android defines both __ANDROID__ and __linux__, one
  373. // may probe for either Linux or Android by simply testing for __linux__.
  374. // Y_ABSL_HAVE_MMAP
  375. //
  376. // Checks whether the platform has an mmap(2) implementation as defined in
  377. // POSIX.1-2001.
  378. #ifdef Y_ABSL_HAVE_MMAP
  379. #error Y_ABSL_HAVE_MMAP cannot be directly set
  380. #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
  381. defined(_AIX) || defined(__ros__) || defined(__native_client__) || \
  382. defined(__asmjs__) || defined(__wasm__) || defined(__Fuchsia__) || \
  383. defined(__sun) || defined(__ASYLO__) || defined(__myriad2__) || \
  384. defined(__HAIKU__)
  385. #define Y_ABSL_HAVE_MMAP 1
  386. #endif
  387. // Y_ABSL_HAVE_PTHREAD_GETSCHEDPARAM
  388. //
  389. // Checks whether the platform implements the pthread_(get|set)schedparam(3)
  390. // functions as defined in POSIX.1-2001.
  391. #ifdef Y_ABSL_HAVE_PTHREAD_GETSCHEDPARAM
  392. #error Y_ABSL_HAVE_PTHREAD_GETSCHEDPARAM cannot be directly set
  393. #elif defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
  394. defined(_AIX) || defined(__ros__)
  395. #define Y_ABSL_HAVE_PTHREAD_GETSCHEDPARAM 1
  396. #endif
  397. // Y_ABSL_HAVE_SCHED_GETCPU
  398. //
  399. // Checks whether sched_getcpu is available.
  400. #ifdef Y_ABSL_HAVE_SCHED_GETCPU
  401. #error Y_ABSL_HAVE_SCHED_GETCPU cannot be directly set
  402. #elif defined(__linux__)
  403. #define Y_ABSL_HAVE_SCHED_GETCPU 1
  404. #endif
  405. // Y_ABSL_HAVE_SCHED_YIELD
  406. //
  407. // Checks whether the platform implements sched_yield(2) as defined in
  408. // POSIX.1-2001.
  409. #ifdef Y_ABSL_HAVE_SCHED_YIELD
  410. #error Y_ABSL_HAVE_SCHED_YIELD cannot be directly set
  411. #elif defined(__linux__) || defined(__ros__) || defined(__native_client__)
  412. #define Y_ABSL_HAVE_SCHED_YIELD 1
  413. #endif
  414. // Y_ABSL_HAVE_SEMAPHORE_H
  415. //
  416. // Checks whether the platform supports the <semaphore.h> header and sem_init(3)
  417. // family of functions as standardized in POSIX.1-2001.
  418. //
  419. // Note: While Apple provides <semaphore.h> for both iOS and macOS, it is
  420. // explicitly deprecated and will cause build failures if enabled for those
  421. // platforms. We side-step the issue by not defining it here for Apple
  422. // platforms.
  423. #ifdef Y_ABSL_HAVE_SEMAPHORE_H
  424. #error Y_ABSL_HAVE_SEMAPHORE_H cannot be directly set
  425. #elif defined(__linux__) || defined(__ros__)
  426. #define Y_ABSL_HAVE_SEMAPHORE_H 1
  427. #endif
  428. // Y_ABSL_HAVE_ALARM
  429. //
  430. // Checks whether the platform supports the <signal.h> header and alarm(2)
  431. // function as standardized in POSIX.1-2001.
  432. #ifdef Y_ABSL_HAVE_ALARM
  433. #error Y_ABSL_HAVE_ALARM cannot be directly set
  434. #elif defined(__GOOGLE_GRTE_VERSION__)
  435. // feature tests for Google's GRTE
  436. #define Y_ABSL_HAVE_ALARM 1
  437. #elif defined(__GLIBC__)
  438. // feature test for glibc
  439. #define Y_ABSL_HAVE_ALARM 1
  440. #elif defined(_MSC_VER)
  441. // feature tests for Microsoft's library
  442. #elif defined(__MINGW32__)
  443. // mingw32 doesn't provide alarm(2):
  444. // https://osdn.net/projects/mingw/scm/git/mingw-org-wsl/blobs/5.2-trunk/mingwrt/include/unistd.h
  445. // mingw-w64 provides a no-op implementation:
  446. // https://sourceforge.net/p/mingw-w64/mingw-w64/ci/master/tree/mingw-w64-crt/misc/alarm.c
  447. #elif defined(__EMSCRIPTEN__)
  448. // emscripten doesn't support signals
  449. #elif defined(__Fuchsia__)
  450. // Signals don't exist on fuchsia.
  451. #elif defined(__native_client__)
  452. #else
  453. // other standard libraries
  454. #define Y_ABSL_HAVE_ALARM 1
  455. #endif
  456. // Y_ABSL_IS_LITTLE_ENDIAN
  457. // Y_ABSL_IS_BIG_ENDIAN
  458. //
  459. // Checks the endianness of the platform.
  460. //
  461. // Notes: uses the built in endian macros provided by GCC (since 4.6) and
  462. // Clang (since 3.2); see
  463. // https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html.
  464. // Otherwise, if _WIN32, assume little endian. Otherwise, bail with an error.
  465. #if defined(Y_ABSL_IS_BIG_ENDIAN)
  466. #error "Y_ABSL_IS_BIG_ENDIAN cannot be directly set."
  467. #endif
  468. #if defined(Y_ABSL_IS_LITTLE_ENDIAN)
  469. #error "Y_ABSL_IS_LITTLE_ENDIAN cannot be directly set."
  470. #endif
  471. #if (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  472. __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
  473. #define Y_ABSL_IS_LITTLE_ENDIAN 1
  474. #elif defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && \
  475. __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
  476. #define Y_ABSL_IS_BIG_ENDIAN 1
  477. #elif defined(_WIN32)
  478. #define Y_ABSL_IS_LITTLE_ENDIAN 1
  479. #else
  480. #error "y_absl endian detection needs to be set up for your compiler"
  481. #endif
  482. // macOS 10.13 and iOS 10.11 don't let you use <any>, <optional>, or <variant>
  483. // even though the headers exist and are publicly noted to work. See
  484. // https://github.com/abseil/abseil-cpp/issues/207 and
  485. // https://developer.apple.com/documentation/xcode_release_notes/xcode_10_release_notes
  486. // libc++ spells out the availability requirements in the file
  487. // llvm-project/libcxx/include/__config via the #define
  488. // _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS.
  489. #if defined(__APPLE__) && defined(_LIBCPP_VERSION) && \
  490. ((defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \
  491. __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 101400) || \
  492. (defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) && \
  493. __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ < 120000) || \
  494. (defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) && \
  495. __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ < 50000) || \
  496. (defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) && \
  497. __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ < 120000))
  498. #define Y_ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 1
  499. #else
  500. #define Y_ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE 0
  501. #endif
  502. // Y_ABSL_HAVE_STD_ANY
  503. //
  504. // Checks whether C++17 std::any is available by checking whether <any> exists.
  505. #ifdef Y_ABSL_HAVE_STD_ANY
  506. #error "Y_ABSL_HAVE_STD_ANY cannot be directly set."
  507. #endif
  508. #ifdef __has_include
  509. #if __has_include(<any>) && defined(__cplusplus) && __cplusplus >= 201703L && \
  510. !Y_ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
  511. #define Y_ABSL_HAVE_STD_ANY 1
  512. #endif
  513. #endif
  514. // Y_ABSL_HAVE_STD_OPTIONAL
  515. //
  516. // Checks whether C++17 std::optional is available.
  517. #ifdef Y_ABSL_HAVE_STD_OPTIONAL
  518. #error "Y_ABSL_HAVE_STD_OPTIONAL cannot be directly set."
  519. #endif
  520. #ifdef __has_include
  521. #if __has_include(<optional>) && defined(__cplusplus) && \
  522. __cplusplus >= 201703L && !Y_ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
  523. #define Y_ABSL_HAVE_STD_OPTIONAL 1
  524. #endif
  525. #endif
  526. // Y_ABSL_HAVE_STD_VARIANT
  527. //
  528. // Checks whether C++17 std::variant is available.
  529. #ifdef Y_ABSL_HAVE_STD_VARIANT
  530. #error "Y_ABSL_HAVE_STD_VARIANT cannot be directly set."
  531. #endif
  532. #ifdef __has_include
  533. #if __has_include(<variant>) && defined(__cplusplus) && \
  534. __cplusplus >= 201703L && !Y_ABSL_INTERNAL_APPLE_CXX17_TYPES_UNAVAILABLE
  535. #define Y_ABSL_HAVE_STD_VARIANT 1
  536. #endif
  537. #endif
  538. // Y_ABSL_HAVE_STD_STRING_VIEW
  539. //
  540. // Checks whether C++17 std::string_view is available.
  541. #ifdef Y_ABSL_HAVE_STD_STRING_VIEW
  542. #error "Y_ABSL_HAVE_STD_STRING_VIEW cannot be directly set."
  543. #endif
  544. #define Y_ABSL_HAVE_STD_STRING_VIEW 1
  545. // For MSVC, `__has_include` is supported in VS 2017 15.3, which is later than
  546. // the support for <optional>, <any>, <string_view>, <variant>. So we use
  547. // _MSC_VER to check whether we have VS 2017 RTM (when <optional>, <any>,
  548. // <string_view>, <variant> is implemented) or higher. Also, `__cplusplus` is
  549. // not correctly set by MSVC, so we use `_MSVC_LANG` to check the language
  550. // version.
  551. // TODO(zhangxy): fix tests before enabling aliasing for `std::any`.
  552. #if defined(_MSC_VER) && _MSC_VER >= 1910 && \
  553. ((defined(_MSVC_LANG) && _MSVC_LANG > 201402) || \
  554. (defined(__cplusplus) && __cplusplus > 201402))
  555. // #define Y_ABSL_HAVE_STD_ANY 1
  556. #define Y_ABSL_HAVE_STD_OPTIONAL 1
  557. #define Y_ABSL_HAVE_STD_VARIANT 1
  558. #define Y_ABSL_HAVE_STD_STRING_VIEW 1
  559. #endif
  560. // Y_ABSL_USES_STD_ANY
  561. //
  562. // Indicates whether y_absl::any is an alias for std::any.
  563. #if !defined(Y_ABSL_OPTION_USE_STD_ANY)
  564. #error options.h is misconfigured.
  565. #elif Y_ABSL_OPTION_USE_STD_ANY == 0 || \
  566. (Y_ABSL_OPTION_USE_STD_ANY == 2 && !defined(Y_ABSL_HAVE_STD_ANY))
  567. #undef Y_ABSL_USES_STD_ANY
  568. #elif Y_ABSL_OPTION_USE_STD_ANY == 1 || \
  569. (Y_ABSL_OPTION_USE_STD_ANY == 2 && defined(Y_ABSL_HAVE_STD_ANY))
  570. #define Y_ABSL_USES_STD_ANY 1
  571. #else
  572. #error options.h is misconfigured.
  573. #endif
  574. // Y_ABSL_USES_STD_OPTIONAL
  575. //
  576. // Indicates whether y_absl::optional is an alias for std::optional.
  577. #if !defined(Y_ABSL_OPTION_USE_STD_OPTIONAL)
  578. #error options.h is misconfigured.
  579. #elif Y_ABSL_OPTION_USE_STD_OPTIONAL == 0 || \
  580. (Y_ABSL_OPTION_USE_STD_OPTIONAL == 2 && !defined(Y_ABSL_HAVE_STD_OPTIONAL))
  581. #undef Y_ABSL_USES_STD_OPTIONAL
  582. #elif Y_ABSL_OPTION_USE_STD_OPTIONAL == 1 || \
  583. (Y_ABSL_OPTION_USE_STD_OPTIONAL == 2 && defined(Y_ABSL_HAVE_STD_OPTIONAL))
  584. #define Y_ABSL_USES_STD_OPTIONAL 1
  585. #else
  586. #error options.h is misconfigured.
  587. #endif
  588. // Y_ABSL_USES_STD_VARIANT
  589. //
  590. // Indicates whether y_absl::variant is an alias for std::variant.
  591. #if !defined(Y_ABSL_OPTION_USE_STD_VARIANT)
  592. #error options.h is misconfigured.
  593. #elif Y_ABSL_OPTION_USE_STD_VARIANT == 0 || \
  594. (Y_ABSL_OPTION_USE_STD_VARIANT == 2 && !defined(Y_ABSL_HAVE_STD_VARIANT))
  595. #undef Y_ABSL_USES_STD_VARIANT
  596. #elif Y_ABSL_OPTION_USE_STD_VARIANT == 1 || \
  597. (Y_ABSL_OPTION_USE_STD_VARIANT == 2 && defined(Y_ABSL_HAVE_STD_VARIANT))
  598. #define Y_ABSL_USES_STD_VARIANT 1
  599. #else
  600. #error options.h is misconfigured.
  601. #endif
  602. // Y_ABSL_USES_STD_STRING_VIEW
  603. //
  604. // Indicates whether y_absl::string_view is an alias for std::string_view.
  605. #if !defined(Y_ABSL_OPTION_USE_STD_STRING_VIEW)
  606. #error options.h is misconfigured.
  607. #elif Y_ABSL_OPTION_USE_STD_STRING_VIEW == 0 || \
  608. (Y_ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
  609. !defined(Y_ABSL_HAVE_STD_STRING_VIEW))
  610. #undef Y_ABSL_USES_STD_STRING_VIEW
  611. #elif Y_ABSL_OPTION_USE_STD_STRING_VIEW == 1 || \
  612. (Y_ABSL_OPTION_USE_STD_STRING_VIEW == 2 && \
  613. defined(Y_ABSL_HAVE_STD_STRING_VIEW))
  614. #define Y_ABSL_USES_STD_STRING_VIEW 1
  615. #else
  616. #error options.h is misconfigured.
  617. #endif
  618. // In debug mode, MSVC 2017's std::variant throws a EXCEPTION_ACCESS_VIOLATION
  619. // SEH exception from emplace for variant<SomeStruct> when constructing the
  620. // struct can throw. This defeats some of variant_test and
  621. // variant_exception_safety_test.
  622. #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_DEBUG)
  623. #define Y_ABSL_INTERNAL_MSVC_2017_DBG_MODE
  624. #endif
  625. // Y_ABSL_INTERNAL_MANGLED_NS
  626. // Y_ABSL_INTERNAL_MANGLED_BACKREFERENCE
  627. //
  628. // Internal macros for building up mangled names in our internal fork of CCTZ.
  629. // This implementation detail is only needed and provided for the MSVC build.
  630. //
  631. // These macros both expand to string literals. Y_ABSL_INTERNAL_MANGLED_NS is
  632. // the mangled spelling of the `y_absl` namespace, and
  633. // Y_ABSL_INTERNAL_MANGLED_BACKREFERENCE is a back-reference integer representing
  634. // the proper count to skip past the CCTZ fork namespace names. (This number
  635. // is one larger when there is an inline namespace name to skip.)
  636. #if defined(_MSC_VER)
  637. #if Y_ABSL_OPTION_USE_INLINE_NAMESPACE == 0
  638. #define Y_ABSL_INTERNAL_MANGLED_NS "y_absl"
  639. #define Y_ABSL_INTERNAL_MANGLED_BACKREFERENCE "5"
  640. #else
  641. #define Y_ABSL_INTERNAL_MANGLED_NS \
  642. Y_ABSL_INTERNAL_TOKEN_STR(Y_ABSL_OPTION_INLINE_NAMESPACE_NAME) "@y_absl"
  643. #define Y_ABSL_INTERNAL_MANGLED_BACKREFERENCE "6"
  644. #endif
  645. #endif
  646. #undef Y_ABSL_INTERNAL_HAS_KEYWORD
  647. // Y_ABSL_DLL
  648. //
  649. // When building Abseil as a DLL, this macro expands to `__declspec(dllexport)`
  650. // so we can annotate symbols appropriately as being exported. When used in
  651. // headers consuming a DLL, this macro expands to `__declspec(dllimport)` so
  652. // that consumers know the symbol is defined inside the DLL. In all other cases,
  653. // the macro expands to nothing.
  654. #if defined(_MSC_VER)
  655. #if defined(Y_ABSL_BUILD_DLL)
  656. #define Y_ABSL_DLL __declspec(dllexport)
  657. #elif defined(Y_ABSL_CONSUME_DLL)
  658. #define Y_ABSL_DLL __declspec(dllimport)
  659. #else
  660. #define Y_ABSL_DLL
  661. #endif
  662. #else
  663. #define Y_ABSL_DLL
  664. #endif // defined(_MSC_VER)
  665. // Y_ABSL_HAVE_MEMORY_SANITIZER
  666. //
  667. // MemorySanitizer (MSan) is a detector of uninitialized reads. It consists of
  668. // a compiler instrumentation module and a run-time library.
  669. #ifdef Y_ABSL_HAVE_MEMORY_SANITIZER
  670. #error "Y_ABSL_HAVE_MEMORY_SANITIZER cannot be directly set."
  671. #elif defined(__SANITIZE_MEMORY__)
  672. #define Y_ABSL_HAVE_MEMORY_SANITIZER 1
  673. #elif !defined(__native_client__) && Y_ABSL_HAVE_FEATURE(memory_sanitizer)
  674. #define Y_ABSL_HAVE_MEMORY_SANITIZER 1
  675. #endif
  676. // Y_ABSL_HAVE_THREAD_SANITIZER
  677. //
  678. // ThreadSanitizer (TSan) is a fast data race detector.
  679. #ifdef Y_ABSL_HAVE_THREAD_SANITIZER
  680. #error "Y_ABSL_HAVE_THREAD_SANITIZER cannot be directly set."
  681. #elif defined(__SANITIZE_THREAD__)
  682. #define Y_ABSL_HAVE_THREAD_SANITIZER 1
  683. #elif Y_ABSL_HAVE_FEATURE(thread_sanitizer)
  684. #define Y_ABSL_HAVE_THREAD_SANITIZER 1
  685. #endif
  686. // Y_ABSL_HAVE_ADDRESS_SANITIZER
  687. //
  688. // AddressSanitizer (ASan) is a fast memory error detector.
  689. #ifdef Y_ABSL_HAVE_ADDRESS_SANITIZER
  690. #error "Y_ABSL_HAVE_ADDRESS_SANITIZER cannot be directly set."
  691. #elif defined(__SANITIZE_ADDRESS__)
  692. #define Y_ABSL_HAVE_ADDRESS_SANITIZER 1
  693. #elif Y_ABSL_HAVE_FEATURE(address_sanitizer)
  694. #define Y_ABSL_HAVE_ADDRESS_SANITIZER 1
  695. #endif
  696. // Y_ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
  697. //
  698. // Class template argument deduction is a language feature added in C++17.
  699. #ifdef Y_ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION
  700. #error "Y_ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION cannot be directly set."
  701. #elif defined(__cpp_deduction_guides)
  702. #define Y_ABSL_HAVE_CLASS_TEMPLATE_ARGUMENT_DEDUCTION 1
  703. #endif
  704. #endif // Y_ABSL_BASE_CONFIG_H_