xref: /aosp_15_r20/external/cronet/third_party/protobuf/objectivec/GPBBootstrap.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker // Protocol Buffers - Google's data interchange format
2*6777b538SAndroid Build Coastguard Worker // Copyright 2008 Google Inc.  All rights reserved.
3*6777b538SAndroid Build Coastguard Worker // https://developers.google.com/protocol-buffers/
4*6777b538SAndroid Build Coastguard Worker //
5*6777b538SAndroid Build Coastguard Worker // Redistribution and use in source and binary forms, with or without
6*6777b538SAndroid Build Coastguard Worker // modification, are permitted provided that the following conditions are
7*6777b538SAndroid Build Coastguard Worker // met:
8*6777b538SAndroid Build Coastguard Worker //
9*6777b538SAndroid Build Coastguard Worker //     * Redistributions of source code must retain the above copyright
10*6777b538SAndroid Build Coastguard Worker // notice, this list of conditions and the following disclaimer.
11*6777b538SAndroid Build Coastguard Worker //     * Redistributions in binary form must reproduce the above
12*6777b538SAndroid Build Coastguard Worker // copyright notice, this list of conditions and the following disclaimer
13*6777b538SAndroid Build Coastguard Worker // in the documentation and/or other materials provided with the
14*6777b538SAndroid Build Coastguard Worker // distribution.
15*6777b538SAndroid Build Coastguard Worker //     * Neither the name of Google Inc. nor the names of its
16*6777b538SAndroid Build Coastguard Worker // contributors may be used to endorse or promote products derived from
17*6777b538SAndroid Build Coastguard Worker // this software without specific prior written permission.
18*6777b538SAndroid Build Coastguard Worker //
19*6777b538SAndroid Build Coastguard Worker // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20*6777b538SAndroid Build Coastguard Worker // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21*6777b538SAndroid Build Coastguard Worker // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22*6777b538SAndroid Build Coastguard Worker // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23*6777b538SAndroid Build Coastguard Worker // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24*6777b538SAndroid Build Coastguard Worker // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25*6777b538SAndroid Build Coastguard Worker // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26*6777b538SAndroid Build Coastguard Worker // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27*6777b538SAndroid Build Coastguard Worker // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28*6777b538SAndroid Build Coastguard Worker // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29*6777b538SAndroid Build Coastguard Worker // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30*6777b538SAndroid Build Coastguard Worker 
31*6777b538SAndroid Build Coastguard Worker /**
32*6777b538SAndroid Build Coastguard Worker  * The Objective C runtime has complete enough info that most protos don’t end
33*6777b538SAndroid Build Coastguard Worker  * up using this, so leaving it on is no cost or very little cost.  If you
34*6777b538SAndroid Build Coastguard Worker  * happen to see it causing bloat, this is the way to disable it. If you do
35*6777b538SAndroid Build Coastguard Worker  * need to disable it, try only disabling it for Release builds as having
36*6777b538SAndroid Build Coastguard Worker  * full TextFormat can be useful for debugging.
37*6777b538SAndroid Build Coastguard Worker  **/
38*6777b538SAndroid Build Coastguard Worker #ifndef GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS
39*6777b538SAndroid Build Coastguard Worker #define GPBOBJC_SKIP_MESSAGE_TEXTFORMAT_EXTRAS 0
40*6777b538SAndroid Build Coastguard Worker #endif
41*6777b538SAndroid Build Coastguard Worker 
42*6777b538SAndroid Build Coastguard Worker // Used in the generated code to give sizes to enums. int32_t was chosen based
43*6777b538SAndroid Build Coastguard Worker // on the fact that Protocol Buffers enums are limited to this range.
44*6777b538SAndroid Build Coastguard Worker #if !__has_feature(objc_fixed_enum)
45*6777b538SAndroid Build Coastguard Worker  #error All supported Xcode versions should support objc_fixed_enum.
46*6777b538SAndroid Build Coastguard Worker #endif
47*6777b538SAndroid Build Coastguard Worker 
48*6777b538SAndroid Build Coastguard Worker // If the headers are imported into Objective-C++, we can run into an issue
49*6777b538SAndroid Build Coastguard Worker // where the definition of NS_ENUM (really CF_ENUM) changes based on the C++
50*6777b538SAndroid Build Coastguard Worker // standard that is in effect.  If it isn't C++11 or higher, the definition
51*6777b538SAndroid Build Coastguard Worker // doesn't allow us to forward declare. We work around this one case by
52*6777b538SAndroid Build Coastguard Worker // providing a local definition. The default case has to use NS_ENUM for the
53*6777b538SAndroid Build Coastguard Worker // magic that is Swift bridging of enums.
54*6777b538SAndroid Build Coastguard Worker #if (defined(__cplusplus) && __cplusplus && __cplusplus < 201103L)
55*6777b538SAndroid Build Coastguard Worker  #define GPB_ENUM(X) enum X : int32_t X; enum X : int32_t
56*6777b538SAndroid Build Coastguard Worker #else
57*6777b538SAndroid Build Coastguard Worker  #define GPB_ENUM(X) NS_ENUM(int32_t, X)
58*6777b538SAndroid Build Coastguard Worker #endif
59*6777b538SAndroid Build Coastguard Worker 
60*6777b538SAndroid Build Coastguard Worker /**
61*6777b538SAndroid Build Coastguard Worker  * GPB_ENUM_FWD_DECLARE is used for forward declaring enums, for example:
62*6777b538SAndroid Build Coastguard Worker  *
63*6777b538SAndroid Build Coastguard Worker  * ```
64*6777b538SAndroid Build Coastguard Worker  * GPB_ENUM_FWD_DECLARE(Foo_Enum)
65*6777b538SAndroid Build Coastguard Worker  *
66*6777b538SAndroid Build Coastguard Worker  * @interface BarClass : NSObject
67*6777b538SAndroid Build Coastguard Worker  * @property (nonatomic) enum Foo_Enum value;
68*6777b538SAndroid Build Coastguard Worker  * - (void)bazMethod:(enum Foo_Enum):value;
69*6777b538SAndroid Build Coastguard Worker  * @end
70*6777b538SAndroid Build Coastguard Worker  * ```
71*6777b538SAndroid Build Coastguard Worker  **/
72*6777b538SAndroid Build Coastguard Worker #define GPB_ENUM_FWD_DECLARE(X) enum X : int32_t
73*6777b538SAndroid Build Coastguard Worker 
74*6777b538SAndroid Build Coastguard Worker /**
75*6777b538SAndroid Build Coastguard Worker  * Based upon CF_INLINE. Forces inlining in non DEBUG builds.
76*6777b538SAndroid Build Coastguard Worker  **/
77*6777b538SAndroid Build Coastguard Worker #if !defined(DEBUG)
78*6777b538SAndroid Build Coastguard Worker #define GPB_INLINE static __inline__ __attribute__((always_inline))
79*6777b538SAndroid Build Coastguard Worker #else
80*6777b538SAndroid Build Coastguard Worker #define GPB_INLINE static __inline__
81*6777b538SAndroid Build Coastguard Worker #endif
82*6777b538SAndroid Build Coastguard Worker 
83*6777b538SAndroid Build Coastguard Worker /**
84*6777b538SAndroid Build Coastguard Worker  * For use in public headers that might need to deal with ARC.
85*6777b538SAndroid Build Coastguard Worker  **/
86*6777b538SAndroid Build Coastguard Worker #ifndef GPB_UNSAFE_UNRETAINED
87*6777b538SAndroid Build Coastguard Worker #if __has_feature(objc_arc)
88*6777b538SAndroid Build Coastguard Worker #define GPB_UNSAFE_UNRETAINED __unsafe_unretained
89*6777b538SAndroid Build Coastguard Worker #else
90*6777b538SAndroid Build Coastguard Worker #define GPB_UNSAFE_UNRETAINED
91*6777b538SAndroid Build Coastguard Worker #endif
92*6777b538SAndroid Build Coastguard Worker #endif
93*6777b538SAndroid Build Coastguard Worker 
94*6777b538SAndroid Build Coastguard Worker /**
95*6777b538SAndroid Build Coastguard Worker  * Attribute used for Objective-C proto interface deprecations without messages.
96*6777b538SAndroid Build Coastguard Worker  **/
97*6777b538SAndroid Build Coastguard Worker #ifndef GPB_DEPRECATED
98*6777b538SAndroid Build Coastguard Worker #define GPB_DEPRECATED __attribute__((deprecated))
99*6777b538SAndroid Build Coastguard Worker #endif
100*6777b538SAndroid Build Coastguard Worker 
101*6777b538SAndroid Build Coastguard Worker /**
102*6777b538SAndroid Build Coastguard Worker  * Attribute used for Objective-C proto interface deprecations with messages.
103*6777b538SAndroid Build Coastguard Worker  **/
104*6777b538SAndroid Build Coastguard Worker #ifndef GPB_DEPRECATED_MSG
105*6777b538SAndroid Build Coastguard Worker #if __has_extension(attribute_deprecated_with_message)
106*6777b538SAndroid Build Coastguard Worker #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated(msg)))
107*6777b538SAndroid Build Coastguard Worker #else
108*6777b538SAndroid Build Coastguard Worker #define GPB_DEPRECATED_MSG(msg) __attribute__((deprecated))
109*6777b538SAndroid Build Coastguard Worker #endif
110*6777b538SAndroid Build Coastguard Worker #endif
111*6777b538SAndroid Build Coastguard Worker 
112*6777b538SAndroid Build Coastguard Worker // If property name starts with init we need to annotate it to get past ARC.
113*6777b538SAndroid Build Coastguard Worker // http://stackoverflow.com/questions/18723226/how-do-i-annotate-an-objective-c-property-with-an-objc-method-family/18723227#18723227
114*6777b538SAndroid Build Coastguard Worker //
115*6777b538SAndroid Build Coastguard Worker // Meant to be used internally by generated code.
116*6777b538SAndroid Build Coastguard Worker #define GPB_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
117*6777b538SAndroid Build Coastguard Worker 
118*6777b538SAndroid Build Coastguard Worker // Prevent subclassing of generated proto classes.
119*6777b538SAndroid Build Coastguard Worker #ifndef GPB_FINAL
120*6777b538SAndroid Build Coastguard Worker #define GPB_FINAL __attribute__((objc_subclassing_restricted))
121*6777b538SAndroid Build Coastguard Worker #endif  // GPB_FINAL
122*6777b538SAndroid Build Coastguard Worker 
123*6777b538SAndroid Build Coastguard Worker // ----------------------------------------------------------------------------
124*6777b538SAndroid Build Coastguard Worker // These version numbers are all internal to the ObjC Protobuf runtime; they
125*6777b538SAndroid Build Coastguard Worker // are used to ensure compatibility between the generated sources and the
126*6777b538SAndroid Build Coastguard Worker // headers being compiled against and/or the version of sources being run
127*6777b538SAndroid Build Coastguard Worker // against.
128*6777b538SAndroid Build Coastguard Worker //
129*6777b538SAndroid Build Coastguard Worker // They are all #defines so the values are captured into every .o file they
130*6777b538SAndroid Build Coastguard Worker // are used in and to allow comparisons in the preprocessor.
131*6777b538SAndroid Build Coastguard Worker 
132*6777b538SAndroid Build Coastguard Worker // Current library runtime version.
133*6777b538SAndroid Build Coastguard Worker // - Gets bumped when the runtime makes changes to the interfaces between the
134*6777b538SAndroid Build Coastguard Worker //   generated code and runtime (things added/removed, etc).
135*6777b538SAndroid Build Coastguard Worker #define GOOGLE_PROTOBUF_OBJC_VERSION 30004
136*6777b538SAndroid Build Coastguard Worker 
137*6777b538SAndroid Build Coastguard Worker // Minimum runtime version supported for compiling/running against.
138*6777b538SAndroid Build Coastguard Worker // - Gets changed when support for the older generated code is dropped.
139*6777b538SAndroid Build Coastguard Worker #define GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION 30001
140*6777b538SAndroid Build Coastguard Worker 
141*6777b538SAndroid Build Coastguard Worker 
142*6777b538SAndroid Build Coastguard Worker // This is a legacy constant now frozen in time for old generated code. If
143*6777b538SAndroid Build Coastguard Worker // GOOGLE_PROTOBUF_OBJC_MIN_SUPPORTED_VERSION ever gets moved above 30001 then
144*6777b538SAndroid Build Coastguard Worker // this should also change to break code compiled with an old runtime that
145*6777b538SAndroid Build Coastguard Worker // can't be supported any more.
146*6777b538SAndroid Build Coastguard Worker #define GOOGLE_PROTOBUF_OBJC_GEN_VERSION 30001
147