xref: /aosp_15_r20/external/cronet/build/build_config.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // This file doesn't belong to any GN target by design for faster build and
6 // less developer overhead.
7 
8 // This file adds build flags about the OS we're currently building on. They are
9 // defined directly in this file instead of via a `buildflag_header` target in a
10 // GN file for faster build. They are defined using the corresponding OS defines
11 // (e.g. OS_WIN) which are also defined in this file (except for OS_CHROMEOS,
12 // which is set by the build system). These defines are deprecated and should
13 // NOT be used directly. For example:
14 //    Please Use: #if BUILDFLAG(IS_WIN)
15 //    Deprecated: #if defined(OS_WIN)
16 //
17 //  Operating System:
18 //    IS_AIX / IS_ANDROID / IS_ASMJS / IS_CHROMEOS / IS_FREEBSD / IS_FUCHSIA /
19 //    IS_IOS / IS_IOS_MACCATALYST / IS_IOS_VISION / IS_IOS_WATCH / IS_LINUX /
20 //    IS_MAC / IS_NACL / IS_NETBSD / IS_OPENBSD / IS_QNX / IS_SOLARIS / IS_WIN
21 //  Operating System family:
22 //    IS_APPLE: MAC or IOS or IOS_MACCATALYST or IOS_VISION or IOS_WATCH
23 //    IS_IOS: IOS or IOS_MACCATALYST or IOS_VISION or IOS_WATCH
24 //    IS_BSD: FREEBSD or NETBSD or OPENBSD
25 //    IS_POSIX: AIX or ANDROID or ASMJS or CHROMEOS or FREEBSD or IOS
26 //              or IOS_MACCATALYST or IOS_VISION or IOS_WATCH or LINUX or MAC
27 //              or NACL or NETBSD or OPENBSD or QNX or SOLARIS
28 
29 // This file also adds defines specific to the platform, architecture etc.
30 //
31 //  Platform:
32 //    IS_OZONE
33 //
34 //  Compiler:
35 //    COMPILER_MSVC / COMPILER_GCC
36 //
37 //  Processor:
38 //    ARCH_CPU_ARM64 / ARCH_CPU_ARMEL / ARCH_CPU_LOONGARCH32 /
39 //    ARCH_CPU_LOONGARCH64 / ARCH_CPU_MIPS / ARCH_CPU_MIPS64 /
40 //    ARCH_CPU_MIPS64EL / ARCH_CPU_MIPSEL / ARCH_CPU_PPC64 / ARCH_CPU_S390 /
41 //    ARCH_CPU_S390X / ARCH_CPU_X86 / ARCH_CPU_X86_64 / ARCH_CPU_RISCV64
42 //  Processor family:
43 //    ARCH_CPU_ARM_FAMILY: ARMEL or ARM64
44 //    ARCH_CPU_LOONGARCH_FAMILY: LOONGARCH32 or LOONGARCH64
45 //    ARCH_CPU_MIPS_FAMILY: MIPS64EL or MIPSEL or MIPS64 or MIPS
46 //    ARCH_CPU_PPC64_FAMILY: PPC64
47 //    ARCH_CPU_S390_FAMILY: S390 or S390X
48 //    ARCH_CPU_X86_FAMILY: X86 or X86_64
49 //    ARCH_CPU_RISCV_FAMILY: Riscv64
50 //  Processor features:
51 //    ARCH_CPU_31_BITS / ARCH_CPU_32_BITS / ARCH_CPU_64_BITS
52 //    ARCH_CPU_BIG_ENDIAN / ARCH_CPU_LITTLE_ENDIAN
53 
54 #ifndef BUILD_BUILD_CONFIG_H_
55 #define BUILD_BUILD_CONFIG_H_
56 
57 #include "build/buildflag.h"  // IWYU pragma: export
58 
59 // A set of macros to use for platform detection.
60 #if defined(__native_client__)
61 // __native_client__ must be first, so that other OS_ defines are not set.
62 #define OS_NACL 1
63 #elif defined(ANDROID)
64 #define OS_ANDROID 1
65 #elif defined(__APPLE__)
66 // Only include TargetConditionals after testing ANDROID as some Android builds
67 // on the Mac have this header available and it's not needed unless the target
68 // is really an Apple platform.
69 #include <TargetConditionals.h>
70 #if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
71 #define OS_IOS 1
72 // Catalyst is the technology that allows running iOS apps on macOS. These
73 // builds are both OS_IOS and OS_IOS_MACCATALYST.
74 #if defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST
75 #define OS_IOS_MACCATALYST
76 #endif  // defined(TARGET_OS_MACCATALYST) && TARGET_OS_MACCATALYST
77 #if defined(TARGET_OS_VISION) && TARGET_OS_VISION
78 #define OS_IOS_VISION 1
79 #endif  // defined(TARGET_OS_VISION) && TARGET_OS_VISION
80 #if defined(TARGET_OS_WATCH) && TARGET_OS_WATCH
81 #define OS_IOS_WATCH 1
82 #endif  // defined(TARGET_OS_WATCH) && TARGET_OS_WATCH
83 #else
84 #define OS_MAC 1
85 #endif  // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
86 #elif defined(__linux__)
87 #if !defined(OS_CHROMEOS)
88 // Do not define OS_LINUX on Chrome OS build.
89 // The OS_CHROMEOS macro is defined in GN.
90 #define OS_LINUX 1
91 #endif  // !defined(OS_CHROMEOS)
92 // Include a system header to pull in features.h for glibc/uclibc macros.
93 #include <assert.h>
94 #if defined(__GLIBC__) && !defined(__UCLIBC__)
95 // We really are using glibc, not uClibc pretending to be glibc.
96 #define LIBC_GLIBC 1
97 #endif
98 #elif defined(_WIN32)
99 #define OS_WIN 1
100 #elif defined(__Fuchsia__)
101 #define OS_FUCHSIA 1
102 #elif defined(__FreeBSD__)
103 #define OS_FREEBSD 1
104 #elif defined(__NetBSD__)
105 #define OS_NETBSD 1
106 #elif defined(__OpenBSD__)
107 #define OS_OPENBSD 1
108 #elif defined(__sun)
109 #define OS_SOLARIS 1
110 #elif defined(__QNXNTO__)
111 #define OS_QNX 1
112 #elif defined(_AIX)
113 #define OS_AIX 1
114 #elif defined(__asmjs__) || defined(__wasm__)
115 #define OS_ASMJS 1
116 #elif defined(__MVS__)
117 #define OS_ZOS 1
118 #else
119 #error Please add support for your platform in build/build_config.h
120 #endif
121 // NOTE: Adding a new port? Please follow
122 // https://chromium.googlesource.com/chromium/src/+/main/docs/new_port_policy.md
123 
124 #if defined(OS_MAC) || defined(OS_IOS)
125 #define OS_APPLE 1
126 #endif
127 
128 // For access to standard BSD features, use OS_BSD instead of a
129 // more specific macro.
130 #if defined(OS_FREEBSD) || defined(OS_NETBSD) || defined(OS_OPENBSD)
131 #define OS_BSD 1
132 #endif
133 
134 // For access to standard POSIXish features, use OS_POSIX instead of a
135 // more specific macro.
136 #if defined(OS_AIX) || defined(OS_ANDROID) || defined(OS_ASMJS) ||  \
137     defined(OS_FREEBSD) || defined(OS_IOS) || defined(OS_LINUX) ||  \
138     defined(OS_CHROMEOS) || defined(OS_MAC) || defined(OS_NACL) ||  \
139     defined(OS_NETBSD) || defined(OS_OPENBSD) || defined(OS_QNX) || \
140     defined(OS_SOLARIS) || defined(OS_ZOS)
141 #define OS_POSIX 1
142 #endif
143 
144 // OS build flags
145 #if defined(OS_AIX)
146 #define BUILDFLAG_INTERNAL_IS_AIX() (1)
147 #else
148 #define BUILDFLAG_INTERNAL_IS_AIX() (0)
149 #endif
150 
151 #if defined(OS_ANDROID)
152 #define BUILDFLAG_INTERNAL_IS_ANDROID() (1)
153 #else
154 #define BUILDFLAG_INTERNAL_IS_ANDROID() (0)
155 #endif
156 
157 #if defined(OS_APPLE)
158 #define BUILDFLAG_INTERNAL_IS_APPLE() (1)
159 #else
160 #define BUILDFLAG_INTERNAL_IS_APPLE() (0)
161 #endif
162 
163 #if defined(OS_ASMJS)
164 #define BUILDFLAG_INTERNAL_IS_ASMJS() (1)
165 #else
166 #define BUILDFLAG_INTERNAL_IS_ASMJS() (0)
167 #endif
168 
169 #if defined(OS_BSD)
170 #define BUILDFLAG_INTERNAL_IS_BSD() (1)
171 #else
172 #define BUILDFLAG_INTERNAL_IS_BSD() (0)
173 #endif
174 
175 #if defined(OS_CHROMEOS)
176 #define BUILDFLAG_INTERNAL_IS_CHROMEOS() (1)
177 #else
178 #define BUILDFLAG_INTERNAL_IS_CHROMEOS() (0)
179 #endif
180 
181 #if defined(OS_FREEBSD)
182 #define BUILDFLAG_INTERNAL_IS_FREEBSD() (1)
183 #else
184 #define BUILDFLAG_INTERNAL_IS_FREEBSD() (0)
185 #endif
186 
187 #if defined(OS_FUCHSIA)
188 #define BUILDFLAG_INTERNAL_IS_FUCHSIA() (1)
189 #else
190 #define BUILDFLAG_INTERNAL_IS_FUCHSIA() (0)
191 #endif
192 
193 #if defined(OS_IOS)
194 #define BUILDFLAG_INTERNAL_IS_IOS() (1)
195 #else
196 #define BUILDFLAG_INTERNAL_IS_IOS() (0)
197 #endif
198 
199 #if defined(OS_IOS_MACCATALYST)
200 #define BUILDFLAG_INTERNAL_IS_IOS_MACCATALYST() (1)
201 #else
202 #define BUILDFLAG_INTERNAL_IS_IOS_MACCATALYST() (0)
203 #endif
204 
205 #if defined(OS_IOS_VISION)
206 #define BUILDFLAG_INTERNAL_IS_IOS_VISION() (1)
207 #else
208 #define BUILDFLAG_INTERNAL_IS_IOS_VISION() (0)
209 #endif
210 
211 #if defined(OS_IOS_WATCH)
212 #define BUILDFLAG_INTERNAL_IS_IOS_WATCH() (1)
213 #else
214 #define BUILDFLAG_INTERNAL_IS_IOS_WATCH() (0)
215 #endif
216 
217 #if defined(OS_LINUX)
218 #define BUILDFLAG_INTERNAL_IS_LINUX() (1)
219 #else
220 #define BUILDFLAG_INTERNAL_IS_LINUX() (0)
221 #endif
222 
223 #if defined(OS_MAC)
224 #define BUILDFLAG_INTERNAL_IS_MAC() (1)
225 #else
226 #define BUILDFLAG_INTERNAL_IS_MAC() (0)
227 #endif
228 
229 #if defined(OS_NACL)
230 #define BUILDFLAG_INTERNAL_IS_NACL() (1)
231 #else
232 #define BUILDFLAG_INTERNAL_IS_NACL() (0)
233 #endif
234 
235 #if defined(OS_NETBSD)
236 #define BUILDFLAG_INTERNAL_IS_NETBSD() (1)
237 #else
238 #define BUILDFLAG_INTERNAL_IS_NETBSD() (0)
239 #endif
240 
241 #if defined(OS_OPENBSD)
242 #define BUILDFLAG_INTERNAL_IS_OPENBSD() (1)
243 #else
244 #define BUILDFLAG_INTERNAL_IS_OPENBSD() (0)
245 #endif
246 
247 #if defined(OS_POSIX)
248 #define BUILDFLAG_INTERNAL_IS_POSIX() (1)
249 #else
250 #define BUILDFLAG_INTERNAL_IS_POSIX() (0)
251 #endif
252 
253 #if defined(OS_QNX)
254 #define BUILDFLAG_INTERNAL_IS_QNX() (1)
255 #else
256 #define BUILDFLAG_INTERNAL_IS_QNX() (0)
257 #endif
258 
259 #if defined(OS_SOLARIS)
260 #define BUILDFLAG_INTERNAL_IS_SOLARIS() (1)
261 #else
262 #define BUILDFLAG_INTERNAL_IS_SOLARIS() (0)
263 #endif
264 
265 #if defined(OS_WIN)
266 #define BUILDFLAG_INTERNAL_IS_WIN() (1)
267 #else
268 #define BUILDFLAG_INTERNAL_IS_WIN() (0)
269 #endif
270 
271 #if defined(USE_OZONE)
272 #define BUILDFLAG_INTERNAL_IS_OZONE() (1)
273 #else
274 #define BUILDFLAG_INTERNAL_IS_OZONE() (0)
275 #endif
276 
277 // Compiler detection. Note: clang masquerades as GCC on POSIX and as MSVC on
278 // Windows.
279 #if defined(__GNUC__)
280 #define COMPILER_GCC 1
281 #elif defined(_MSC_VER)
282 #define COMPILER_MSVC 1
283 #else
284 #error Please add support for your compiler in build/build_config.h
285 #endif
286 
287 // Processor architecture detection.  For more info on what's defined, see:
288 //   http://msdn.microsoft.com/en-us/library/b0084kay.aspx
289 //   http://www.agner.org/optimize/calling_conventions.pdf
290 //   or with gcc, run: "echo | gcc -E -dM -"
291 #if defined(_M_X64) || defined(__x86_64__)
292 #define ARCH_CPU_X86_FAMILY 1
293 #define ARCH_CPU_X86_64 1
294 #define ARCH_CPU_64_BITS 1
295 #define ARCH_CPU_LITTLE_ENDIAN 1
296 #elif defined(_M_IX86) || defined(__i386__)
297 #define ARCH_CPU_X86_FAMILY 1
298 #define ARCH_CPU_X86 1
299 #define ARCH_CPU_32_BITS 1
300 #define ARCH_CPU_LITTLE_ENDIAN 1
301 #elif defined(__s390x__)
302 #define ARCH_CPU_S390_FAMILY 1
303 #define ARCH_CPU_S390X 1
304 #define ARCH_CPU_64_BITS 1
305 #define ARCH_CPU_BIG_ENDIAN 1
306 #elif defined(__s390__)
307 #define ARCH_CPU_S390_FAMILY 1
308 #define ARCH_CPU_S390 1
309 #define ARCH_CPU_31_BITS 1
310 #define ARCH_CPU_BIG_ENDIAN 1
311 #elif (defined(__PPC64__) || defined(__PPC__)) && defined(__BIG_ENDIAN__)
312 #define ARCH_CPU_PPC64_FAMILY 1
313 #define ARCH_CPU_PPC64 1
314 #define ARCH_CPU_64_BITS 1
315 #define ARCH_CPU_BIG_ENDIAN 1
316 #elif defined(__PPC64__)
317 #define ARCH_CPU_PPC64_FAMILY 1
318 #define ARCH_CPU_PPC64 1
319 #define ARCH_CPU_64_BITS 1
320 #define ARCH_CPU_LITTLE_ENDIAN 1
321 #elif defined(__ARMEL__)
322 #define ARCH_CPU_ARM_FAMILY 1
323 #define ARCH_CPU_ARMEL 1
324 #define ARCH_CPU_32_BITS 1
325 #define ARCH_CPU_LITTLE_ENDIAN 1
326 #elif defined(__aarch64__) || defined(_M_ARM64)
327 #define ARCH_CPU_ARM_FAMILY 1
328 #define ARCH_CPU_ARM64 1
329 #define ARCH_CPU_64_BITS 1
330 #define ARCH_CPU_LITTLE_ENDIAN 1
331 #elif defined(__pnacl__) || defined(__asmjs__) || defined(__wasm__)
332 #define ARCH_CPU_32_BITS 1
333 #define ARCH_CPU_LITTLE_ENDIAN 1
334 #elif defined(__MIPSEL__)
335 #if defined(__LP64__)
336 #define ARCH_CPU_MIPS_FAMILY 1
337 #define ARCH_CPU_MIPS64EL 1
338 #define ARCH_CPU_64_BITS 1
339 #define ARCH_CPU_LITTLE_ENDIAN 1
340 #else
341 #define ARCH_CPU_MIPS_FAMILY 1
342 #define ARCH_CPU_MIPSEL 1
343 #define ARCH_CPU_32_BITS 1
344 #define ARCH_CPU_LITTLE_ENDIAN 1
345 #endif
346 #elif defined(__MIPSEB__)
347 #if defined(__LP64__)
348 #define ARCH_CPU_MIPS_FAMILY 1
349 #define ARCH_CPU_MIPS64 1
350 #define ARCH_CPU_64_BITS 1
351 #define ARCH_CPU_BIG_ENDIAN 1
352 #else
353 #define ARCH_CPU_MIPS_FAMILY 1
354 #define ARCH_CPU_MIPS 1
355 #define ARCH_CPU_32_BITS 1
356 #define ARCH_CPU_BIG_ENDIAN 1
357 #endif
358 #elif defined(__loongarch__)
359 #define ARCH_CPU_LOONGARCH_FAMILY 1
360 #define ARCH_CPU_LITTLE_ENDIAN 1
361 #if __loongarch_grlen == 64
362 #define ARCH_CPU_LOONGARCH64 1
363 #define ARCH_CPU_64_BITS 1
364 #else
365 #define ARCH_CPU_LOONGARCH32 1
366 #define ARCH_CPU_32_BITS 1
367 #endif
368 #elif defined(__riscv) && (__riscv_xlen == 64)
369 #define ARCH_CPU_RISCV_FAMILY 1
370 #define ARCH_CPU_RISCV64 1
371 #define ARCH_CPU_64_BITS 1
372 #define ARCH_CPU_LITTLE_ENDIAN 1
373 #else
374 #error Please add support for your architecture in build/build_config.h
375 #endif
376 
377 // Type detection for wchar_t.
378 #if defined(OS_WIN)
379 #define WCHAR_T_IS_16_BIT
380 #elif defined(OS_FUCHSIA)
381 #define WCHAR_T_IS_32_BIT
382 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \
383     (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff)
384 #define WCHAR_T_IS_32_BIT
385 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \
386     (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff)
387 // On Posix, we'll detect short wchar_t, but projects aren't guaranteed to
388 // compile in this mode (in particular, Chrome doesn't). This is intended for
389 // other projects using base who manage their own dependencies and make sure
390 // short wchar works for them.
391 #define WCHAR_T_IS_16_BIT
392 #else
393 #error Please add support for your compiler in build/build_config.h
394 #endif
395 
396 #if defined(OS_ANDROID)
397 // The compiler thinks std::string::const_iterator and "const char*" are
398 // equivalent types.
399 #define STD_STRING_ITERATOR_IS_CHAR_POINTER
400 // The compiler thinks std::u16string::const_iterator and "char16*" are
401 // equivalent types.
402 #define BASE_STRING16_ITERATOR_IS_CHAR16_POINTER
403 #endif
404 
405 #endif  // BUILD_BUILD_CONFIG_H_
406