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