xref: /aosp_15_r20/external/abseil-cpp/absl/base/options.h (revision 9356374a3709195abf420251b3e825997ff56c0f)
1*9356374aSAndroid Build Coastguard Worker // Copyright 2019 The Abseil Authors.
2*9356374aSAndroid Build Coastguard Worker //
3*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
4*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
5*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at
6*9356374aSAndroid Build Coastguard Worker //
7*9356374aSAndroid Build Coastguard Worker //      https://www.apache.org/licenses/LICENSE-2.0
8*9356374aSAndroid Build Coastguard Worker //
9*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
11*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
13*9356374aSAndroid Build Coastguard Worker // limitations under the License.
14*9356374aSAndroid Build Coastguard Worker //
15*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
16*9356374aSAndroid Build Coastguard Worker // File: options.h
17*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
18*9356374aSAndroid Build Coastguard Worker //
19*9356374aSAndroid Build Coastguard Worker // This file contains Abseil configuration options for setting specific
20*9356374aSAndroid Build Coastguard Worker // implementations instead of letting Abseil determine which implementation to
21*9356374aSAndroid Build Coastguard Worker // use at compile-time. Setting these options may be useful for package or build
22*9356374aSAndroid Build Coastguard Worker // managers who wish to guarantee ABI stability within binary builds (which are
23*9356374aSAndroid Build Coastguard Worker // otherwise difficult to enforce).
24*9356374aSAndroid Build Coastguard Worker //
25*9356374aSAndroid Build Coastguard Worker // *** IMPORTANT NOTICE FOR PACKAGE MANAGERS:  It is important that
26*9356374aSAndroid Build Coastguard Worker // maintainers of package managers who wish to package Abseil read and
27*9356374aSAndroid Build Coastguard Worker // understand this file! ***
28*9356374aSAndroid Build Coastguard Worker //
29*9356374aSAndroid Build Coastguard Worker // Abseil contains a number of possible configuration endpoints, based on
30*9356374aSAndroid Build Coastguard Worker // parameters such as the detected platform, language version, or command-line
31*9356374aSAndroid Build Coastguard Worker // flags used to invoke the underlying binary. As is the case with all
32*9356374aSAndroid Build Coastguard Worker // libraries, binaries which contain Abseil code must ensure that separate
33*9356374aSAndroid Build Coastguard Worker // packages use the same compiled copy of Abseil to avoid a diamond dependency
34*9356374aSAndroid Build Coastguard Worker // problem, which can occur if two packages built with different Abseil
35*9356374aSAndroid Build Coastguard Worker // configuration settings are linked together. Diamond dependency problems in
36*9356374aSAndroid Build Coastguard Worker // C++ may manifest as violations to the One Definition Rule (ODR) (resulting in
37*9356374aSAndroid Build Coastguard Worker // linker errors), or undefined behavior (resulting in crashes).
38*9356374aSAndroid Build Coastguard Worker //
39*9356374aSAndroid Build Coastguard Worker // Diamond dependency problems can be avoided if all packages utilize the same
40*9356374aSAndroid Build Coastguard Worker // exact version of Abseil. Building from source code with the same compilation
41*9356374aSAndroid Build Coastguard Worker // parameters is the easiest way to avoid such dependency problems. However, for
42*9356374aSAndroid Build Coastguard Worker // package managers who cannot control such compilation parameters, we are
43*9356374aSAndroid Build Coastguard Worker // providing the file to allow you to inject ABI (Application Binary Interface)
44*9356374aSAndroid Build Coastguard Worker // stability across builds. Settings options in this file will neither change
45*9356374aSAndroid Build Coastguard Worker // API nor ABI, providing a stable copy of Abseil between packages.
46*9356374aSAndroid Build Coastguard Worker //
47*9356374aSAndroid Build Coastguard Worker // Care must be taken to keep options within these configurations isolated
48*9356374aSAndroid Build Coastguard Worker // from any other dynamic settings, such as command-line flags which could alter
49*9356374aSAndroid Build Coastguard Worker // these options. This file is provided specifically to help build and package
50*9356374aSAndroid Build Coastguard Worker // managers provide a stable copy of Abseil within their libraries and binaries;
51*9356374aSAndroid Build Coastguard Worker // other developers should not have need to alter the contents of this file.
52*9356374aSAndroid Build Coastguard Worker //
53*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
54*9356374aSAndroid Build Coastguard Worker // Usage
55*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
56*9356374aSAndroid Build Coastguard Worker //
57*9356374aSAndroid Build Coastguard Worker // For any particular package release, set the appropriate definitions within
58*9356374aSAndroid Build Coastguard Worker // this file to whatever value makes the most sense for your package(s). Note
59*9356374aSAndroid Build Coastguard Worker // that, by default, most of these options, at the moment, affect the
60*9356374aSAndroid Build Coastguard Worker // implementation of types; future options may affect other implementation
61*9356374aSAndroid Build Coastguard Worker // details.
62*9356374aSAndroid Build Coastguard Worker //
63*9356374aSAndroid Build Coastguard Worker // NOTE: the defaults within this file all assume that Abseil can select the
64*9356374aSAndroid Build Coastguard Worker // proper Abseil implementation at compile-time, which will not be sufficient
65*9356374aSAndroid Build Coastguard Worker // to guarantee ABI stability to package managers.
66*9356374aSAndroid Build Coastguard Worker 
67*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_BASE_OPTIONS_H_
68*9356374aSAndroid Build Coastguard Worker #define ABSL_BASE_OPTIONS_H_
69*9356374aSAndroid Build Coastguard Worker 
70*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
71*9356374aSAndroid Build Coastguard Worker // Type Compatibility Options
72*9356374aSAndroid Build Coastguard Worker // -----------------------------------------------------------------------------
73*9356374aSAndroid Build Coastguard Worker //
74*9356374aSAndroid Build Coastguard Worker // ABSL_OPTION_USE_STD_ANY
75*9356374aSAndroid Build Coastguard Worker //
76*9356374aSAndroid Build Coastguard Worker // This option controls whether absl::any is implemented as an alias to
77*9356374aSAndroid Build Coastguard Worker // std::any, or as an independent implementation.
78*9356374aSAndroid Build Coastguard Worker //
79*9356374aSAndroid Build Coastguard Worker // A value of 0 means to use Abseil's implementation.  This requires only C++11
80*9356374aSAndroid Build Coastguard Worker // support, and is expected to work on every toolchain we support.
81*9356374aSAndroid Build Coastguard Worker //
82*9356374aSAndroid Build Coastguard Worker // A value of 1 means to use an alias to std::any.  This requires that all code
83*9356374aSAndroid Build Coastguard Worker // using Abseil is built in C++17 mode or later.
84*9356374aSAndroid Build Coastguard Worker //
85*9356374aSAndroid Build Coastguard Worker // A value of 2 means to detect the C++ version being used to compile Abseil,
86*9356374aSAndroid Build Coastguard Worker // and use an alias only if a working std::any is available.  This option is
87*9356374aSAndroid Build Coastguard Worker // useful when you are building your entire program, including all of its
88*9356374aSAndroid Build Coastguard Worker // dependencies, from source.  It should not be used otherwise -- for example,
89*9356374aSAndroid Build Coastguard Worker // if you are distributing Abseil in a binary package manager -- since in
90*9356374aSAndroid Build Coastguard Worker // mode 2, absl::any will name a different type, with a different mangled name
91*9356374aSAndroid Build Coastguard Worker // and binary layout, depending on the compiler flags passed by the end user.
92*9356374aSAndroid Build Coastguard Worker // For more info, see https://abseil.io/about/design/dropin-types.
93*9356374aSAndroid Build Coastguard Worker //
94*9356374aSAndroid Build Coastguard Worker // User code should not inspect this macro.  To check in the preprocessor if
95*9356374aSAndroid Build Coastguard Worker // absl::any is a typedef of std::any, use the feature macro ABSL_USES_STD_ANY.
96*9356374aSAndroid Build Coastguard Worker 
97*9356374aSAndroid Build Coastguard Worker #define ABSL_OPTION_USE_STD_ANY 1
98*9356374aSAndroid Build Coastguard Worker 
99*9356374aSAndroid Build Coastguard Worker 
100*9356374aSAndroid Build Coastguard Worker // ABSL_OPTION_USE_STD_OPTIONAL
101*9356374aSAndroid Build Coastguard Worker //
102*9356374aSAndroid Build Coastguard Worker // This option controls whether absl::optional is implemented as an alias to
103*9356374aSAndroid Build Coastguard Worker // std::optional, or as an independent implementation.
104*9356374aSAndroid Build Coastguard Worker //
105*9356374aSAndroid Build Coastguard Worker // A value of 0 means to use Abseil's implementation.  This requires only C++11
106*9356374aSAndroid Build Coastguard Worker // support, and is expected to work on every toolchain we support.
107*9356374aSAndroid Build Coastguard Worker //
108*9356374aSAndroid Build Coastguard Worker // A value of 1 means to use an alias to std::optional.  This requires that all
109*9356374aSAndroid Build Coastguard Worker // code using Abseil is built in C++17 mode or later.
110*9356374aSAndroid Build Coastguard Worker //
111*9356374aSAndroid Build Coastguard Worker // A value of 2 means to detect the C++ version being used to compile Abseil,
112*9356374aSAndroid Build Coastguard Worker // and use an alias only if a working std::optional is available.  This option
113*9356374aSAndroid Build Coastguard Worker // is useful when you are building your program from source.  It should not be
114*9356374aSAndroid Build Coastguard Worker // used otherwise -- for example, if you are distributing Abseil in a binary
115*9356374aSAndroid Build Coastguard Worker // package manager -- since in mode 2, absl::optional will name a different
116*9356374aSAndroid Build Coastguard Worker // type, with a different mangled name and binary layout, depending on the
117*9356374aSAndroid Build Coastguard Worker // compiler flags passed by the end user.  For more info, see
118*9356374aSAndroid Build Coastguard Worker // https://abseil.io/about/design/dropin-types.
119*9356374aSAndroid Build Coastguard Worker 
120*9356374aSAndroid Build Coastguard Worker // User code should not inspect this macro.  To check in the preprocessor if
121*9356374aSAndroid Build Coastguard Worker // absl::optional is a typedef of std::optional, use the feature macro
122*9356374aSAndroid Build Coastguard Worker // ABSL_USES_STD_OPTIONAL.
123*9356374aSAndroid Build Coastguard Worker 
124*9356374aSAndroid Build Coastguard Worker #define ABSL_OPTION_USE_STD_OPTIONAL 1
125*9356374aSAndroid Build Coastguard Worker 
126*9356374aSAndroid Build Coastguard Worker 
127*9356374aSAndroid Build Coastguard Worker // ABSL_OPTION_USE_STD_STRING_VIEW
128*9356374aSAndroid Build Coastguard Worker //
129*9356374aSAndroid Build Coastguard Worker // This option controls whether absl::string_view is implemented as an alias to
130*9356374aSAndroid Build Coastguard Worker // std::string_view, or as an independent implementation.
131*9356374aSAndroid Build Coastguard Worker //
132*9356374aSAndroid Build Coastguard Worker // A value of 0 means to use Abseil's implementation.  This requires only C++11
133*9356374aSAndroid Build Coastguard Worker // support, and is expected to work on every toolchain we support.
134*9356374aSAndroid Build Coastguard Worker //
135*9356374aSAndroid Build Coastguard Worker // A value of 1 means to use an alias to std::string_view.  This requires that
136*9356374aSAndroid Build Coastguard Worker // all code using Abseil is built in C++17 mode or later.
137*9356374aSAndroid Build Coastguard Worker //
138*9356374aSAndroid Build Coastguard Worker // A value of 2 means to detect the C++ version being used to compile Abseil,
139*9356374aSAndroid Build Coastguard Worker // and use an alias only if a working std::string_view is available.  This
140*9356374aSAndroid Build Coastguard Worker // option is useful when you are building your program from source.  It should
141*9356374aSAndroid Build Coastguard Worker // not be used otherwise -- for example, if you are distributing Abseil in a
142*9356374aSAndroid Build Coastguard Worker // binary package manager -- since in mode 2, absl::string_view will name a
143*9356374aSAndroid Build Coastguard Worker // different type, with a different mangled name and binary layout, depending on
144*9356374aSAndroid Build Coastguard Worker // the compiler flags passed by the end user.  For more info, see
145*9356374aSAndroid Build Coastguard Worker // https://abseil.io/about/design/dropin-types.
146*9356374aSAndroid Build Coastguard Worker //
147*9356374aSAndroid Build Coastguard Worker // User code should not inspect this macro.  To check in the preprocessor if
148*9356374aSAndroid Build Coastguard Worker // absl::string_view is a typedef of std::string_view, use the feature macro
149*9356374aSAndroid Build Coastguard Worker // ABSL_USES_STD_STRING_VIEW.
150*9356374aSAndroid Build Coastguard Worker 
151*9356374aSAndroid Build Coastguard Worker #define ABSL_OPTION_USE_STD_STRING_VIEW 1
152*9356374aSAndroid Build Coastguard Worker 
153*9356374aSAndroid Build Coastguard Worker // ABSL_OPTION_USE_STD_VARIANT
154*9356374aSAndroid Build Coastguard Worker //
155*9356374aSAndroid Build Coastguard Worker // This option controls whether absl::variant is implemented as an alias to
156*9356374aSAndroid Build Coastguard Worker // std::variant, or as an independent implementation.
157*9356374aSAndroid Build Coastguard Worker //
158*9356374aSAndroid Build Coastguard Worker // A value of 0 means to use Abseil's implementation.  This requires only C++11
159*9356374aSAndroid Build Coastguard Worker // support, and is expected to work on every toolchain we support.
160*9356374aSAndroid Build Coastguard Worker //
161*9356374aSAndroid Build Coastguard Worker // A value of 1 means to use an alias to std::variant.  This requires that all
162*9356374aSAndroid Build Coastguard Worker // code using Abseil is built in C++17 mode or later.
163*9356374aSAndroid Build Coastguard Worker //
164*9356374aSAndroid Build Coastguard Worker // A value of 2 means to detect the C++ version being used to compile Abseil,
165*9356374aSAndroid Build Coastguard Worker // and use an alias only if a working std::variant is available.  This option
166*9356374aSAndroid Build Coastguard Worker // is useful when you are building your program from source.  It should not be
167*9356374aSAndroid Build Coastguard Worker // used otherwise -- for example, if you are distributing Abseil in a binary
168*9356374aSAndroid Build Coastguard Worker // package manager -- since in mode 2, absl::variant will name a different
169*9356374aSAndroid Build Coastguard Worker // type, with a different mangled name and binary layout, depending on the
170*9356374aSAndroid Build Coastguard Worker // compiler flags passed by the end user.  For more info, see
171*9356374aSAndroid Build Coastguard Worker // https://abseil.io/about/design/dropin-types.
172*9356374aSAndroid Build Coastguard Worker //
173*9356374aSAndroid Build Coastguard Worker // User code should not inspect this macro.  To check in the preprocessor if
174*9356374aSAndroid Build Coastguard Worker // absl::variant is a typedef of std::variant, use the feature macro
175*9356374aSAndroid Build Coastguard Worker // ABSL_USES_STD_VARIANT.
176*9356374aSAndroid Build Coastguard Worker 
177*9356374aSAndroid Build Coastguard Worker #define ABSL_OPTION_USE_STD_VARIANT 1
178*9356374aSAndroid Build Coastguard Worker 
179*9356374aSAndroid Build Coastguard Worker // ABSL_OPTION_USE_STD_ORDERING
180*9356374aSAndroid Build Coastguard Worker //
181*9356374aSAndroid Build Coastguard Worker // This option controls whether absl::{partial,weak,strong}_ordering are
182*9356374aSAndroid Build Coastguard Worker // implemented as aliases to the std:: ordering types, or as an independent
183*9356374aSAndroid Build Coastguard Worker // implementation.
184*9356374aSAndroid Build Coastguard Worker //
185*9356374aSAndroid Build Coastguard Worker // A value of 0 means to use Abseil's implementation.  This requires only C++11
186*9356374aSAndroid Build Coastguard Worker // support, and is expected to work on every toolchain we support.
187*9356374aSAndroid Build Coastguard Worker //
188*9356374aSAndroid Build Coastguard Worker // A value of 1 means to use aliases.  This requires that all code using Abseil
189*9356374aSAndroid Build Coastguard Worker // is built in C++20 mode or later.
190*9356374aSAndroid Build Coastguard Worker //
191*9356374aSAndroid Build Coastguard Worker // A value of 2 means to detect the C++ version being used to compile Abseil,
192*9356374aSAndroid Build Coastguard Worker // and use an alias only if working std:: ordering types are available.  This
193*9356374aSAndroid Build Coastguard Worker // option is useful when you are building your program from source.  It should
194*9356374aSAndroid Build Coastguard Worker // not be used otherwise -- for example, if you are distributing Abseil in a
195*9356374aSAndroid Build Coastguard Worker // binary package manager -- since in mode 2, they will name different types,
196*9356374aSAndroid Build Coastguard Worker // with different mangled names and binary layout, depending on the compiler
197*9356374aSAndroid Build Coastguard Worker // flags passed by the end user.  For more info, see
198*9356374aSAndroid Build Coastguard Worker // https://abseil.io/about/design/dropin-types.
199*9356374aSAndroid Build Coastguard Worker //
200*9356374aSAndroid Build Coastguard Worker // User code should not inspect this macro.  To check in the preprocessor if
201*9356374aSAndroid Build Coastguard Worker // the ordering types are aliases of std:: ordering types, use the feature macro
202*9356374aSAndroid Build Coastguard Worker // ABSL_USES_STD_ORDERING.
203*9356374aSAndroid Build Coastguard Worker 
204*9356374aSAndroid Build Coastguard Worker #define ABSL_OPTION_USE_STD_ORDERING 2
205*9356374aSAndroid Build Coastguard Worker 
206*9356374aSAndroid Build Coastguard Worker // ABSL_OPTION_USE_INLINE_NAMESPACE
207*9356374aSAndroid Build Coastguard Worker // ABSL_OPTION_INLINE_NAMESPACE_NAME
208*9356374aSAndroid Build Coastguard Worker //
209*9356374aSAndroid Build Coastguard Worker // These options controls whether all entities in the absl namespace are
210*9356374aSAndroid Build Coastguard Worker // contained within an inner inline namespace.  This does not affect the
211*9356374aSAndroid Build Coastguard Worker // user-visible API of Abseil, but it changes the mangled names of all symbols.
212*9356374aSAndroid Build Coastguard Worker //
213*9356374aSAndroid Build Coastguard Worker // This can be useful as a version tag if you are distributing Abseil in
214*9356374aSAndroid Build Coastguard Worker // precompiled form.  This will prevent a binary library build of Abseil with
215*9356374aSAndroid Build Coastguard Worker // one inline namespace being used with headers configured with a different
216*9356374aSAndroid Build Coastguard Worker // inline namespace name.  Binary packagers are reminded that Abseil does not
217*9356374aSAndroid Build Coastguard Worker // guarantee any ABI stability in Abseil, so any update of Abseil or
218*9356374aSAndroid Build Coastguard Worker // configuration change in such a binary package should be combined with a
219*9356374aSAndroid Build Coastguard Worker // new, unique value for the inline namespace name.
220*9356374aSAndroid Build Coastguard Worker //
221*9356374aSAndroid Build Coastguard Worker // A value of 0 means not to use inline namespaces.
222*9356374aSAndroid Build Coastguard Worker //
223*9356374aSAndroid Build Coastguard Worker // A value of 1 means to use an inline namespace with the given name inside
224*9356374aSAndroid Build Coastguard Worker // namespace absl.  If this is set, ABSL_OPTION_INLINE_NAMESPACE_NAME must also
225*9356374aSAndroid Build Coastguard Worker // be changed to a new, unique identifier name.  In particular "head" is not
226*9356374aSAndroid Build Coastguard Worker // allowed.
227*9356374aSAndroid Build Coastguard Worker 
228*9356374aSAndroid Build Coastguard Worker #define ABSL_OPTION_USE_INLINE_NAMESPACE 1
229*9356374aSAndroid Build Coastguard Worker #define ABSL_OPTION_INLINE_NAMESPACE_NAME lts_20240722
230*9356374aSAndroid Build Coastguard Worker 
231*9356374aSAndroid Build Coastguard Worker // ABSL_OPTION_HARDENED
232*9356374aSAndroid Build Coastguard Worker //
233*9356374aSAndroid Build Coastguard Worker // This option enables a "hardened" build in release mode (in this context,
234*9356374aSAndroid Build Coastguard Worker // release mode is defined as a build where the `NDEBUG` macro is defined).
235*9356374aSAndroid Build Coastguard Worker //
236*9356374aSAndroid Build Coastguard Worker // A value of 0 means that "hardened" mode is not enabled.
237*9356374aSAndroid Build Coastguard Worker //
238*9356374aSAndroid Build Coastguard Worker // A value of 1 means that "hardened" mode is enabled.
239*9356374aSAndroid Build Coastguard Worker //
240*9356374aSAndroid Build Coastguard Worker // Hardened builds have additional security checks enabled when `NDEBUG` is
241*9356374aSAndroid Build Coastguard Worker // defined. Defining `NDEBUG` is normally used to turn `assert()` macro into a
242*9356374aSAndroid Build Coastguard Worker // no-op, as well as disabling other bespoke program consistency checks. By
243*9356374aSAndroid Build Coastguard Worker // defining ABSL_OPTION_HARDENED to 1, a select set of checks remain enabled in
244*9356374aSAndroid Build Coastguard Worker // release mode. These checks guard against programming errors that may lead to
245*9356374aSAndroid Build Coastguard Worker // security vulnerabilities. In release mode, when one of these programming
246*9356374aSAndroid Build Coastguard Worker // errors is encountered, the program will immediately abort, possibly without
247*9356374aSAndroid Build Coastguard Worker // any attempt at logging.
248*9356374aSAndroid Build Coastguard Worker //
249*9356374aSAndroid Build Coastguard Worker // The checks enabled by this option are not free; they do incur runtime cost.
250*9356374aSAndroid Build Coastguard Worker //
251*9356374aSAndroid Build Coastguard Worker // The checks enabled by this option are always active when `NDEBUG` is not
252*9356374aSAndroid Build Coastguard Worker // defined, even in the case when ABSL_OPTION_HARDENED is defined to 0. The
253*9356374aSAndroid Build Coastguard Worker // checks enabled by this option may abort the program in a different way and
254*9356374aSAndroid Build Coastguard Worker // log additional information when `NDEBUG` is not defined.
255*9356374aSAndroid Build Coastguard Worker 
256*9356374aSAndroid Build Coastguard Worker #define ABSL_OPTION_HARDENED 0
257*9356374aSAndroid Build Coastguard Worker 
258*9356374aSAndroid Build Coastguard Worker #endif  // ABSL_BASE_OPTIONS_H_
259