config.h 37 KB

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