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_LINUX / IS_MAC / IS_NACL / IS_NETBSD / 20 // IS_OPENBSD / IS_QNX / IS_SOLARIS / IS_WATCHOS / IS_WIN 21 // Operating System family: 22 // IS_APPLE: IOS or MAC or IOS_MACCATALYST 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_WATCH) && TARGET_OS_WATCH 81 #define OS_WATCHOS 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_LINUX) 206 #define BUILDFLAG_INTERNAL_IS_LINUX() (1) 207 #else 208 #define BUILDFLAG_INTERNAL_IS_LINUX() (0) 209 #endif 210 211 #if defined(OS_MAC) 212 #define BUILDFLAG_INTERNAL_IS_MAC() (1) 213 #else 214 #define BUILDFLAG_INTERNAL_IS_MAC() (0) 215 #endif 216 217 #if defined(OS_NACL) 218 #define BUILDFLAG_INTERNAL_IS_NACL() (1) 219 #else 220 #define BUILDFLAG_INTERNAL_IS_NACL() (0) 221 #endif 222 223 #if defined(OS_NETBSD) 224 #define BUILDFLAG_INTERNAL_IS_NETBSD() (1) 225 #else 226 #define BUILDFLAG_INTERNAL_IS_NETBSD() (0) 227 #endif 228 229 #if defined(OS_OPENBSD) 230 #define BUILDFLAG_INTERNAL_IS_OPENBSD() (1) 231 #else 232 #define BUILDFLAG_INTERNAL_IS_OPENBSD() (0) 233 #endif 234 235 #if defined(OS_POSIX) 236 #define BUILDFLAG_INTERNAL_IS_POSIX() (1) 237 #else 238 #define BUILDFLAG_INTERNAL_IS_POSIX() (0) 239 #endif 240 241 #if defined(OS_QNX) 242 #define BUILDFLAG_INTERNAL_IS_QNX() (1) 243 #else 244 #define BUILDFLAG_INTERNAL_IS_QNX() (0) 245 #endif 246 247 #if defined(OS_SOLARIS) 248 #define BUILDFLAG_INTERNAL_IS_SOLARIS() (1) 249 #else 250 #define BUILDFLAG_INTERNAL_IS_SOLARIS() (0) 251 #endif 252 253 #if defined(OS_WATCHOS) 254 #define BUILDFLAG_INTERNAL_IS_WATCHOS() (1) 255 #else 256 #define BUILDFLAG_INTERNAL_IS_WATCHOS() (0) 257 #endif 258 259 #if defined(OS_WIN) 260 #define BUILDFLAG_INTERNAL_IS_WIN() (1) 261 #else 262 #define BUILDFLAG_INTERNAL_IS_WIN() (0) 263 #endif 264 265 #if defined(USE_OZONE) 266 #define BUILDFLAG_INTERNAL_IS_OZONE() (1) 267 #else 268 #define BUILDFLAG_INTERNAL_IS_OZONE() (0) 269 #endif 270 271 // Compiler detection. Note: clang masquerades as GCC on POSIX and as MSVC on 272 // Windows. 273 #if defined(__GNUC__) 274 #define COMPILER_GCC 1 275 #elif defined(_MSC_VER) 276 #define COMPILER_MSVC 1 277 #else 278 #error Please add support for your compiler in build/build_config.h 279 #endif 280 281 // Processor architecture detection. For more info on what's defined, see: 282 // http://msdn.microsoft.com/en-us/library/b0084kay.aspx 283 // http://www.agner.org/optimize/calling_conventions.pdf 284 // or with gcc, run: "echo | gcc -E -dM -" 285 #if defined(_M_X64) || defined(__x86_64__) 286 #define ARCH_CPU_X86_FAMILY 1 287 #define ARCH_CPU_X86_64 1 288 #define ARCH_CPU_64_BITS 1 289 #define ARCH_CPU_LITTLE_ENDIAN 1 290 #elif defined(_M_IX86) || defined(__i386__) 291 #define ARCH_CPU_X86_FAMILY 1 292 #define ARCH_CPU_X86 1 293 #define ARCH_CPU_32_BITS 1 294 #define ARCH_CPU_LITTLE_ENDIAN 1 295 #elif defined(__s390x__) 296 #define ARCH_CPU_S390_FAMILY 1 297 #define ARCH_CPU_S390X 1 298 #define ARCH_CPU_64_BITS 1 299 #define ARCH_CPU_BIG_ENDIAN 1 300 #elif defined(__s390__) 301 #define ARCH_CPU_S390_FAMILY 1 302 #define ARCH_CPU_S390 1 303 #define ARCH_CPU_31_BITS 1 304 #define ARCH_CPU_BIG_ENDIAN 1 305 #elif (defined(__PPC64__) || defined(__PPC__)) && defined(__BIG_ENDIAN__) 306 #define ARCH_CPU_PPC64_FAMILY 1 307 #define ARCH_CPU_PPC64 1 308 #define ARCH_CPU_64_BITS 1 309 #define ARCH_CPU_BIG_ENDIAN 1 310 #elif defined(__PPC64__) 311 #define ARCH_CPU_PPC64_FAMILY 1 312 #define ARCH_CPU_PPC64 1 313 #define ARCH_CPU_64_BITS 1 314 #define ARCH_CPU_LITTLE_ENDIAN 1 315 #elif defined(__ARMEL__) 316 #define ARCH_CPU_ARM_FAMILY 1 317 #define ARCH_CPU_ARMEL 1 318 #define ARCH_CPU_32_BITS 1 319 #define ARCH_CPU_LITTLE_ENDIAN 1 320 #elif defined(__aarch64__) || defined(_M_ARM64) 321 #define ARCH_CPU_ARM_FAMILY 1 322 #define ARCH_CPU_ARM64 1 323 #define ARCH_CPU_64_BITS 1 324 #define ARCH_CPU_LITTLE_ENDIAN 1 325 #elif defined(__pnacl__) || defined(__asmjs__) || defined(__wasm__) 326 #define ARCH_CPU_32_BITS 1 327 #define ARCH_CPU_LITTLE_ENDIAN 1 328 #elif defined(__MIPSEL__) 329 #if defined(__LP64__) 330 #define ARCH_CPU_MIPS_FAMILY 1 331 #define ARCH_CPU_MIPS64EL 1 332 #define ARCH_CPU_64_BITS 1 333 #define ARCH_CPU_LITTLE_ENDIAN 1 334 #else 335 #define ARCH_CPU_MIPS_FAMILY 1 336 #define ARCH_CPU_MIPSEL 1 337 #define ARCH_CPU_32_BITS 1 338 #define ARCH_CPU_LITTLE_ENDIAN 1 339 #endif 340 #elif defined(__MIPSEB__) 341 #if defined(__LP64__) 342 #define ARCH_CPU_MIPS_FAMILY 1 343 #define ARCH_CPU_MIPS64 1 344 #define ARCH_CPU_64_BITS 1 345 #define ARCH_CPU_BIG_ENDIAN 1 346 #else 347 #define ARCH_CPU_MIPS_FAMILY 1 348 #define ARCH_CPU_MIPS 1 349 #define ARCH_CPU_32_BITS 1 350 #define ARCH_CPU_BIG_ENDIAN 1 351 #endif 352 #elif defined(__loongarch__) 353 #define ARCH_CPU_LOONGARCH_FAMILY 1 354 #define ARCH_CPU_LITTLE_ENDIAN 1 355 #if __loongarch_grlen == 64 356 #define ARCH_CPU_LOONGARCH64 1 357 #define ARCH_CPU_64_BITS 1 358 #else 359 #define ARCH_CPU_LOONGARCH32 1 360 #define ARCH_CPU_32_BITS 1 361 #endif 362 #elif defined(__riscv) && (__riscv_xlen == 64) 363 #define ARCH_CPU_RISCV_FAMILY 1 364 #define ARCH_CPU_RISCV64 1 365 #define ARCH_CPU_64_BITS 1 366 #define ARCH_CPU_LITTLE_ENDIAN 1 367 #else 368 #error Please add support for your architecture in build/build_config.h 369 #endif 370 371 // Type detection for wchar_t. 372 #if defined(OS_WIN) 373 #define WCHAR_T_IS_16_BIT 374 #elif defined(OS_FUCHSIA) 375 #define WCHAR_T_IS_32_BIT 376 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \ 377 (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff) 378 #define WCHAR_T_IS_32_BIT 379 #elif defined(OS_POSIX) && defined(COMPILER_GCC) && defined(__WCHAR_MAX__) && \ 380 (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff) 381 // On Posix, we'll detect short wchar_t, but projects aren't guaranteed to 382 // compile in this mode (in particular, Chrome doesn't). This is intended for 383 // other projects using base who manage their own dependencies and make sure 384 // short wchar works for them. 385 #define WCHAR_T_IS_16_BIT 386 #else 387 #error Please add support for your compiler in build/build_config.h 388 #endif 389 390 #if defined(OS_ANDROID) 391 // The compiler thinks std::string::const_iterator and "const char*" are 392 // equivalent types. 393 #define STD_STRING_ITERATOR_IS_CHAR_POINTER 394 // The compiler thinks std::u16string::const_iterator and "char16*" are 395 // equivalent types. 396 #define BASE_STRING16_ITERATOR_IS_CHAR16_POINTER 397 #endif 398 399 // Architecture-specific feature detection. 400 401 #if !defined(CPU_ARM_NEON) 402 #if defined(__arm__) 403 #if !defined(__ARMEB__) && !defined(__ARM_EABI__) && !defined(__EABI__) && \ 404 !defined(__VFP_FP__) && !defined(_WIN32_WCE) && !defined(ANDROID) 405 #error Chromium does not support middle endian architecture 406 #endif 407 #if defined(__ARM_NEON__) 408 #define CPU_ARM_NEON 1 409 #endif 410 #endif // defined(__arm__) 411 #endif // !defined(CPU_ARM_NEON) 412 413 #if !defined(HAVE_MIPS_MSA_INTRINSICS) 414 #if defined(__mips_msa) && defined(__mips_isa_rev) && (__mips_isa_rev >= 5) 415 #define HAVE_MIPS_MSA_INTRINSICS 1 416 #endif 417 #endif 418 419 #endif // BUILD_BUILD_CONFIG_H_ 420