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