BUILDCONFIG.gn (32551B)
1 # Copyright 2013 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 # ============================================================================= 6 # WHAT IS THIS FILE? 7 # ============================================================================= 8 # 9 # This is the main GN build configuration. This file is loaded after the 10 # build args (args.gn) for the build directory and after the toplevel ".gn" 11 # file (which points to this file as the build configuration). 12 # 13 # This file will be executed and the resulting context will be used to execute 14 # every other file in the build. So variables declared here (that don't start 15 # with an underscore) will be implicitly global. 16 17 # ============================================================================= 18 # PLATFORM SELECTION 19 # ============================================================================= 20 # 21 # There are two main things to set: "os" and "cpu". The "toolchain" is the name 22 # of the GN thing that encodes combinations of these things. 23 # 24 # Users typically only set the variables "target_os" and "target_cpu" in "gn 25 # args", the rest are set up by our build and internal to GN. 26 # 27 # There are three different types of each of these things: The "host" 28 # represents the computer doing the compile and never changes. The "target" 29 # represents the main thing we're trying to build. The "current" represents 30 # which configuration is currently being defined, which can be either the 31 # host, the target, or something completely different (like nacl). GN will 32 # run the same build file multiple times for the different required 33 # configuration in the same build. 34 # 35 # This gives the following variables: 36 # - host_os, host_cpu, host_toolchain 37 # - target_os, target_cpu, default_toolchain 38 # - current_os, current_cpu, current_toolchain. 39 # 40 # Note the default_toolchain isn't symmetrical (you would expect 41 # target_toolchain). This is because the "default" toolchain is a GN built-in 42 # concept, and "target" is something our build sets up that's symmetrical with 43 # its GYP counterpart. Potentially the built-in default_toolchain variable 44 # could be renamed in the future. 45 # 46 # When writing build files, to do something only for the host: 47 # if (current_toolchain == host_toolchain) { ... 48 49 if (target_os == "") { 50 target_os = host_os 51 } 52 53 if (target_cpu == "") { 54 if (target_os == "android") { 55 # If we're building for Android, we should assume that we want to 56 # build for ARM by default, not the host_cpu (which is likely x64). 57 # This allows us to not have to specify both target_os and target_cpu 58 # on the command line. 59 target_cpu = "arm" 60 } else { 61 target_cpu = host_cpu 62 } 63 } 64 65 if (current_cpu == "") { 66 current_cpu = target_cpu 67 } 68 if (current_os == "") { 69 current_os = target_os 70 } 71 72 # ============================================================================= 73 # BUILD FLAGS 74 # ============================================================================= 75 # 76 # This block lists input arguments to the build, along with their default 77 # values. 78 # 79 # If a value is specified on the command line, it will overwrite the defaults 80 # given in a declare_args block, otherwise the default will be used. 81 # 82 # YOU SHOULD ALMOST NEVER NEED TO ADD FLAGS TO THIS FILE. GN allows any file in 83 # the build to declare build flags. If you need a flag for a single component, 84 # you can just declare it in the corresponding BUILD.gn file. 85 # 86 # - If your feature is a single target, say //components/foo, you can put 87 # a declare_args() block in //components/foo/BUILD.gn and use it there. 88 # Nobody else in the build needs to see the flag. 89 # 90 # - Defines based on build variables should be implemented via the generated 91 # build flag header system. See //build/buildflag_header.gni. You can put 92 # the buildflag_header target in the same file as the build flag itself. You 93 # should almost never set "defines" directly. 94 # 95 # - If your flag toggles a target on and off or toggles between different 96 # versions of similar things, write a "group" target that forwards to the 97 # right target (or no target) depending on the value of the build flag. This 98 # group can be in the same BUILD.gn file as the build flag, and targets can 99 # depend unconditionally on the group rather than duplicating flag checks 100 # across many targets. 101 # 102 # - If a semi-random set of build files REALLY needs to know about a define and 103 # the above pattern for isolating the build logic in a forwarding group 104 # doesn't work, you can put the argument in a .gni file. This should be put 105 # in the lowest level of the build that knows about this feature (which should 106 # almost always be outside of the //build directory!). 107 # 108 # Other flag advice: 109 # 110 # - Use boolean values when possible. If you need a default value that expands 111 # to some complex thing in the default case (like the location of the 112 # compiler which would be computed by a script), use a default value of -1 or 113 # the empty string. Outside of the declare_args block, conditionally expand 114 # the default value as necessary. 115 # 116 # - Use a name like "use_foo" or "is_foo" (whatever is more appropriate for 117 # your feature) rather than just "foo". 118 # 119 # - Write good comments directly above the declaration with no blank line. 120 # These comments will appear as documentation in "gn args --list". 121 # 122 # - Don't call exec_script inside declare_args. This will execute the script 123 # even if the value is overridden, which is wasteful. See first bullet. 124 125 declare_args() { 126 # Set to enable the official build level of optimization. This has nothing 127 # to do with branding, but enables an additional level of optimization above 128 # release (!is_debug). This might be better expressed as a tri-state 129 # (debug, release, official) but for historical reasons there are two 130 # separate flags. 131 # 132 # IMPORTANT NOTE: (!is_debug) is *not* sufficient to get satisfying 133 # performance. In particular, DCHECK()s are still enabled for release builds, 134 # which can halve overall performance, and do increase memory usage. Always 135 # set "is_official_build" to true for any build intended to ship to end-users. 136 is_official_build = false 137 138 # Set to true when compiling with the Clang compiler. 139 is_clang = current_os != "linux" || current_os == "openbsd" || 140 (current_cpu != "s390x" && current_cpu != "s390" && 141 current_cpu != "ppc64" && current_cpu != "ppc" && 142 current_cpu != "mips" && current_cpu != "mips64" && 143 current_cpu != "riscv64") 144 145 # Allows the path to a custom target toolchain to be injected as a single 146 # argument, and set as the default toolchain. 147 custom_toolchain = "" 148 149 # This should not normally be set as a build argument. It's here so that 150 # every toolchain can pass through the "global" value via toolchain_args(). 151 host_toolchain = "" 152 153 # Do not set this directly. 154 # It should be set only by //build/toolchains/android:robolectric_x64. 155 # True when compiling native code for use with robolectric_binary(). 156 is_robolectric = false 157 158 # DON'T ADD MORE FLAGS HERE. Read the comment above. 159 } 160 161 declare_args() { 162 # Debug build. Enabling official builds automatically sets is_debug to false. 163 is_debug = !is_official_build 164 } 165 166 declare_args() { 167 # Component build. Setting to true compiles targets declared as "components" 168 # as shared libraries loaded dynamically. This speeds up development time. 169 # When false, components will be linked statically. 170 # 171 # For more information see 172 # https://chromium.googlesource.com/chromium/src/+/main/docs/component_build.md 173 is_component_build = 174 is_debug && current_os != "ios" && current_os != "watchos" 175 } 176 177 assert(!(is_debug && is_official_build), "Can't do official debug builds") 178 assert(!(current_os == "ios" && is_component_build), 179 "Can't use component build on iOS") 180 assert(!(current_os == "watchos" && is_component_build), 181 "Can't use component build on watchOS") 182 183 declare_args() { 184 # Unsafe buffers. Location of file used by plugins to track portions of 185 # the codebase which have been made manifestly safe. 186 clang_unsafe_buffers_paths = "" 187 clang_warning_suppression_file = "" 188 } 189 190 # ============================================================================== 191 # TOOLCHAIN SETUP 192 # ============================================================================== 193 # 194 # Here we set the default toolchain, as well as the variable host_toolchain 195 # which will identify the toolchain corresponding to the local system when 196 # doing cross-compiles. When not cross-compiling, this will be the same as the 197 # default toolchain. 198 # 199 # We do this before anything else to make sure we complain about any 200 # unsupported os/cpu combinations as early as possible. 201 202 if (host_toolchain == "") { 203 # This should only happen in the top-level context. 204 # In a specific toolchain context, the toolchain_args() 205 # block should have propagated a value down. 206 # TODO(dpranke): Add some sort of assert here that verifies that 207 # no toolchain omitted host_toolchain from its toolchain_args(). 208 209 if (host_os == "linux" || host_os == "openbsd") { 210 if (target_os != "linux") { 211 host_toolchain = "//chromium/build/toolchain/linux:clang_$host_cpu" 212 } else if (is_clang) { 213 host_toolchain = "//chromium/build/toolchain/linux:clang_$host_cpu" 214 } else { 215 host_toolchain = "//chromium/build/toolchain/linux:$host_cpu" 216 } 217 } else if (host_os == "mac") { 218 host_toolchain = "//chromium/build/toolchain/mac:clang_$host_cpu" 219 } else if (host_os == "win") { 220 # On Windows always use the target CPU for host builds for x86/x64. On the 221 # configurations we support this will always work and it saves build steps. 222 # Windows ARM64 targets require an x64 host for cross build. 223 if (target_cpu == "x86" || target_cpu == "x64") { 224 if (is_clang) { 225 host_toolchain = "//chromium/build/toolchain/win:win_clang_$target_cpu" 226 } else { 227 host_toolchain = "//chromium/build/toolchain/win:$target_cpu" 228 } 229 } else if (is_clang) { 230 host_toolchain = "//chromium/build/toolchain/win:win_clang_$host_cpu" 231 } else { 232 host_toolchain = "//chromium/build/toolchain/win:$host_cpu" 233 } 234 } else if (host_os == "aix") { 235 host_toolchain = "//chromium/build/toolchain/aix:$host_cpu" 236 } else if (host_os == "zos") { 237 host_toolchain = "//chromium/build/toolchain/zos:$host_cpu" 238 } else { 239 assert(false, "Unsupported host_os: $host_os") 240 } 241 } 242 243 _default_toolchain = "" 244 245 if (target_os == "android") { 246 # Targeting android on Mac is best-effort and not guaranteed to work. 247 #assert(host_os == "linux", "Android builds are only supported on Linux.") 248 _default_toolchain = "//chromium/build/toolchain/android:android_clang_$target_cpu" 249 } else if (target_os == "chromeos" || target_os == "linux" || target_os == "openbsd") { 250 # See comments in build/toolchain/cros/BUILD.gn about board compiles. 251 if (is_clang) { 252 _default_toolchain = "//chromium/build/toolchain/linux:clang_$target_cpu" 253 } else { 254 _default_toolchain = "//chromium/build/toolchain/linux:$target_cpu" 255 } 256 } else if (target_os == "fuchsia") { 257 _default_toolchain = "//chromium/build/toolchain/fuchsia:$target_cpu" 258 } else if (target_os == "ios") { 259 _default_toolchain = "//chromium/build/toolchain/ios:ios_clang_$target_cpu" 260 } else if (target_os == "mac") { 261 #assert(host_os == "mac" || host_os == "linux", 262 # "Mac cross-compiles are unsupported.") 263 _default_toolchain = "//chromium/build/toolchain/mac:clang_$target_cpu" 264 } else if (target_os == "win") { 265 # On Windows, we use the same toolchain for host and target by default. 266 # Beware, win cross builds have some caveats, see docs/win_cross.md 267 if (is_clang) { 268 _default_toolchain = "//chromium/build/toolchain/win:win_clang_$target_cpu" 269 } else { 270 _default_toolchain = "//chromium/build/toolchain/win:$target_cpu" 271 } 272 } else if (target_os == "winuwp") { 273 # Only target WinUWP on for a Windows store application and only 274 # x86, x64 and arm are supported target CPUs. 275 assert(target_cpu == "x86" || target_cpu == "x64" || target_cpu == "arm" || 276 target_cpu == "arm64") 277 _default_toolchain = "//chromium/build/toolchain/win:uwp_$target_cpu" 278 } else if (target_os == "aix") { 279 _default_toolchain = "//chromium/build/toolchain/aix:$target_cpu" 280 } else if (target_os == "zos") { 281 _default_toolchain = "//chromium/build/toolchain/zos:$target_cpu" 282 } else { 283 assert(false, "Unsupported target_os: $target_os") 284 } 285 286 # If a custom toolchain has been set in the args, set it as default. Otherwise, 287 # set the default toolchain for the platform (if any). 288 if (custom_toolchain != "") { 289 set_default_toolchain(custom_toolchain) 290 } else if (_default_toolchain != "") { 291 set_default_toolchain(_default_toolchain) 292 } 293 294 # ============================================================================= 295 # OS DEFINITIONS 296 # ============================================================================= 297 # 298 # We set these various is_FOO booleans for convenience in writing OS-based 299 # conditions. 300 # 301 # - is_android, is_chromeos, is_ios, and is_win should be obvious. 302 # - is_mac is set only for desktop Mac. It is not set on iOS. 303 # - is_posix is true for mac and any Unix-like system (basically everything 304 # except Fuchsia and Windows). 305 # - is_linux is true for desktop Linux, but not for ChromeOS nor Android (which 306 # is generally too different despite being based on the Linux kernel). 307 # 308 # Do not add more is_* variants here for random lesser-used Unix systems like 309 # aix or one of the BSDs. If you need to check these, just check the 310 # current_os value directly. 311 312 is_android = current_os == "android" 313 is_chromeos = current_os == "chromeos" 314 is_fuchsia = current_os == "fuchsia" 315 is_ios = current_os == "ios" 316 is_linux = current_os == "linux" 317 is_bsd = current_os == "openbsd" 318 is_mac = current_os == "mac" 319 is_nacl = current_os == "nacl" 320 is_wasm = current_os == "emscripten" 321 is_watchos = current_os == "watchos" 322 is_win = current_os == "win" || current_os == "winuwp" 323 324 is_apple = is_ios || is_mac || is_watchos 325 is_posix = !is_win && !is_fuchsia 326 327 # ============================================================================= 328 # TARGET DEFAULTS 329 # ============================================================================= 330 # 331 # Set up the default configuration for every build target of the given type. 332 # The values configured here will be automatically set on the scope of the 333 # corresponding target. Target definitions can add or remove to the settings 334 # here as needed. 335 # 336 # WHAT GOES HERE? 337 # 338 # Other than the main compiler and linker configs, the only reason for a config 339 # to be in this list is if some targets need to explicitly override that config 340 # by removing it. This is how targets opt-out of flags. If you don't have that 341 # requirement and just need to add a config everywhere, reference it as a 342 # sub-config of an existing one, most commonly the main "compiler" one. 343 344 # Holds all configs used for running the compiler. 345 default_compiler_configs = [ 346 "//chromium/build/config:feature_flags", 347 "//chromium/build/config/compiler:afdo", 348 "//chromium/build/config/compiler:afdo_optimize_size", 349 "//chromium/build/config/compiler:cet_shadow_stack", 350 "//chromium/build/config/compiler:chromium_code", 351 "//chromium/build/config/compiler:compiler", 352 "//chromium/build/config/compiler:compiler_arm_fpu", 353 "//chromium/build/config/compiler:compiler_arm_thumb", 354 "//chromium/build/config/compiler:default_include_dirs", 355 "//chromium/build/config/compiler:default_init_stack_vars", 356 "//chromium/build/config/compiler:default_optimization", 357 "//chromium/build/config/compiler:default_stack_frames", 358 "//chromium/build/config/compiler:default_symbols", 359 "//chromium/build/config/compiler:disallow_unstable_features", 360 "//chromium/build/config/compiler:libcxx_hardening", 361 "//chromium/build/config/compiler:libcxx_module", 362 "//chromium/build/config/compiler:no_exceptions", 363 "//chromium/build/config/compiler:no_rtti", 364 "//chromium/build/config/compiler:no_unresolved_symbols", 365 "//chromium/build/config/compiler:runtime_library", 366 "//chromium/build/config/compiler:thin_archive", 367 "//chromium/build/config/compiler:thinlto_optimize_default", 368 "//chromium/build/config/compiler/pgo:default_pgo_flags", 369 "//chromium/build/config/coverage:default_coverage", 370 "//chromium/build/config/sanitizers:default_sanitizer_flags", 371 ] 372 373 if (is_win) { 374 default_compiler_configs += [ 375 "//chromium/build/config/win:default_cfg_compiler", 376 "//chromium/build/config/win:default_crt", 377 "//chromium/build/config/win:lean_and_mean", 378 "//chromium/build/config/win:nominmax", 379 "//chromium/build/config/win:unicode", 380 "//chromium/build/config/win:winver", 381 ] 382 } 383 384 if (is_apple) { 385 default_compiler_configs += [ "//chromium/build/config/compiler:enable_arc" ] 386 } 387 388 if (is_posix) { 389 if (current_os != "aix") { 390 default_compiler_configs += 391 [ "//chromium/build/config/gcc:symbol_visibility_hidden" ] 392 } 393 } 394 395 if (is_fuchsia) { 396 default_compiler_configs += [ "//chromium/build/config/gcc:symbol_visibility_hidden" ] 397 } 398 399 if (is_android) { 400 default_compiler_configs += 401 [ "//chromium/build/config/android:default_orderfile_instrumentation" ] 402 } 403 404 if (is_clang && !is_nacl) { 405 default_compiler_configs += [ 406 "//chromium/build/config/clang:extra_warnings", 407 "//chromium/build/config/clang:find_bad_constructs", 408 "//chromium/build/config/clang:unsafe_buffers", 409 ] 410 } 411 412 # Debug/release-related defines. 413 if (is_debug) { 414 default_compiler_configs += [ "//chromium/build/config:debug" ] 415 } else { 416 default_compiler_configs += [ "//chromium/build/config:release" ] 417 } 418 419 # Static libraries and source sets use only the compiler ones. 420 set_defaults("static_library") { 421 configs = default_compiler_configs 422 } 423 set_defaults("source_set") { 424 configs = default_compiler_configs 425 } 426 set_defaults("rust_library") { 427 configs = default_compiler_configs 428 } 429 430 # Compute the set of configs common to all linked targets (shared libraries, 431 # loadable modules, executables) to avoid duplication below. 432 if (is_win) { 433 # Many targets remove these configs, so they are not contained within 434 # //build/config:executable_config for easy removal. 435 _linker_configs = [ 436 "//chromium/build/config/win:default_incremental_linking", 437 438 # Default to console-mode apps. Most of our targets are tests and such 439 # that shouldn't use the windows subsystem. 440 "//chromium/build/config/win:console", 441 ] 442 } else if (is_apple) { 443 _linker_configs = [ "//chromium/build/config/apple:strip_all" ] 444 } else { 445 _linker_configs = [] 446 } 447 448 # Executable defaults. 449 default_executable_configs = default_compiler_configs + [ 450 "//chromium/build/config/compiler:export_dynamic", 451 "//chromium/build/config:default_libs", 452 "//chromium/build/config:executable_config", 453 ] + _linker_configs 454 455 if (is_win) { 456 # Turn on linker CFI for executables, and position it so it can be removed 457 # if needed. 458 default_executable_configs += [ "//chromium/build/config/win:cfi_linker" ] 459 } 460 if (is_fuchsia) { 461 # Sometimes executables are linked by rustc passing a command line to 462 # clang++. It includes "-pie" which is pointless on Fuchsia. Suppress the 463 # resulting (fatal) warning. Unfortunately there's no way to do this only 464 # for binaries linked by rustc; gn does not make the distinction. 465 default_executable_configs += 466 [ "//chromium/build/config/fuchsia:rustc_no_pie_warning" ] 467 } 468 469 set_defaults("executable") { 470 configs = default_executable_configs 471 } 472 473 # Shared library and loadable module defaults (also for components in component 474 # mode). 475 default_shared_library_configs = default_compiler_configs + [ 476 "//chromium/build/config:default_libs", 477 "//chromium/build/config:shared_library_config", 478 ] + _linker_configs 479 if (is_win) { 480 # Turn on linker CFI for DLLs, and position it so it can be removed if needed. 481 default_shared_library_configs += [ "//chromium/build/config/win:cfi_linker" ] 482 } 483 484 if (is_android) { 485 # Strip native JNI exports from shared libraries by default. Binaries that 486 # want this can remove this config. 487 default_shared_library_configs += 488 [ "//chromium/build/config/android:hide_all_but_jni_onload" ] 489 } 490 if (is_fuchsia) { 491 # Sometimes shared libraries are linked by rustc passing a command line to 492 # clang++. It includes "-pie" which is pointless on Fuchsia. Suppress the 493 # resulting (fatal) warning. Unfortunately there's no way to do this only 494 # for binaries linked by rustc; gn does not make the distinction. 495 default_shared_library_configs += 496 [ "//chromium/build/config/fuchsia:rustc_no_pie_warning" ] 497 } 498 set_defaults("shared_library") { 499 configs = default_shared_library_configs 500 } 501 set_defaults("loadable_module") { 502 configs = default_shared_library_configs 503 504 # loadable_modules are generally used by other libs, not just via JNI. 505 if (is_android) { 506 configs -= [ "//chromium/build/config/android:hide_all_but_jni_onload" ] 507 } 508 } 509 510 default_rust_proc_macro_configs = 511 default_shared_library_configs + [ "//chromium/build/rust:proc_macro_extern" ] + 512 # Rust proc macros don't support (Thin)LTO, so always remove it. 513 [ 514 "//chromium/build/config/compiler:thinlto_optimize_default", 515 "//chromium/build/config/compiler:thinlto_optimize_max", 516 ] - 517 [ 518 "//chromium/build/config/compiler:thinlto_optimize_default", 519 "//chromium/build/config/compiler:thinlto_optimize_max", 520 ] 521 522 set_defaults("rust_proc_macro") { 523 configs = default_rust_proc_macro_configs 524 } 525 526 # A helper for forwarding testonly and visibility. 527 # Forwarding "*" does not include variables from outer scopes (to avoid copying 528 # all globals into each template invocation), so it will not pick up 529 # file-scoped or outer-template-scoped variables. Normally this behavior is 530 # desired, but "visibility" and "testonly" are commonly defined in outer scopes. 531 # Explicitly forwarding them in forward_variables_from() works around this 532 # nuance. See //build/docs/writing_gn_templates.md#using-forward_variables_from 533 TESTONLY_AND_VISIBILITY = [ 534 "testonly", 535 "visibility", 536 ] 537 538 # Sets default dependencies for static_library and source_set targets. 539 # 540 # Variables 541 # use_libcxx_modules: If true, libc++'s modules are added to deps. 542 # This is true by default. 543 foreach(_target_type, 544 [ 545 "source_set", 546 "static_library", 547 ]) { 548 template(_target_type) { 549 target(_target_type, target_name) { 550 forward_variables_from(invoker, 551 "*", 552 TESTONLY_AND_VISIBILITY + [ "use_libcxx_modules" ]) 553 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 554 if (!defined(inputs)) { 555 inputs = [] 556 } 557 if (!defined(deps)) { 558 deps = [] 559 } 560 561 if (false) { # Mozilla 562 if (is_clang && (!defined(invoker.use_libcxx_modules) || 563 invoker.use_libcxx_modules)) { 564 # This is necessary for Clang modules builds. 565 deps += [ 566 "//buildtools/third_party/libc++:std", 567 "//buildtools/third_party/libc++:std_config", 568 "//buildtools/third_party/libc++:std_core", 569 "//buildtools/third_party/libc++:std_ctype_h", 570 "//buildtools/third_party/libc++:std_errno_h", 571 "//buildtools/third_party/libc++:std_fenv_h", 572 "//buildtools/third_party/libc++:std_float_h", 573 "//buildtools/third_party/libc++:std_inttypes_h", 574 "//buildtools/third_party/libc++:std_math_h", 575 "//buildtools/third_party/libc++:std_private_mbstate_t", 576 "//buildtools/third_party/libc++:std_string_h", 577 "//buildtools/third_party/libc++:std_uchar_h", 578 "//buildtools/third_party/libc++:std_wctype_h", 579 ] 580 } 581 } 582 583 # Consumed by the unsafe-buffers plugin during compile. 584 # 585 # TODO(crbug.com/326584510): Reclient doesn't respect this variable, see 586 # rbe_bug_326584510_missing_inputs in //build/config/clang/clang.gni 587 _uses_cflags = false 588 if (defined(sources)) { 589 foreach(f, sources) { 590 if (string_replace(f + ".END", ".cc.END", "") != f + ".END" || 591 string_replace(f + ".END", ".c.END", "") != f + ".END" || 592 string_replace(f + ".END", ".mm.END", "") != f + ".END" || 593 string_replace(f + ".END", ".m.END", "") != f + ".END") { 594 _uses_cflags = true 595 } 596 } 597 } 598 if (_uses_cflags && clang_unsafe_buffers_paths != "") { 599 inputs += [ clang_unsafe_buffers_paths ] 600 } 601 } 602 } 603 } 604 605 # Sets default dependencies for executable and shared_library targets. 606 # 607 # Variables 608 # no_default_deps: If true, no standard dependencies will be added. 609 # Targets that set this usually also want to remove 610 # "//chromium/build/config/compiler:runtime_library" from configs (to remove 611 # its subconfig "//chromium/build/config/c++:runtime_library"). 612 # use_libcxx_modules: If true, libc++'s modules are added to deps. 613 # This is true by default. 614 foreach(_target_type, 615 [ 616 "executable", 617 "loadable_module", 618 "shared_library", 619 ]) { 620 template(_target_type) { 621 # Alias "target_name" because it is clobbered by forward_variables_from(). 622 _target_name = target_name 623 target(_target_type, _target_name) { 624 forward_variables_from(invoker, 625 "*", 626 TESTONLY_AND_VISIBILITY + [ 627 "no_default_deps", 628 "use_libcxx_modules", 629 ]) 630 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 631 if (!defined(inputs)) { 632 inputs = [] 633 } 634 635 # Consumed by the unsafe-buffers plugin during compile. 636 # 637 # TODO(crbug.com/326584510): Reclient doesn't respect this variable, see 638 # rbe_bug_326584510_missing_inputs in //build/config/clang/clang.gni 639 _uses_cflags = false 640 if (defined(sources)) { 641 foreach(f, sources) { 642 if (string_replace(f + ".END", ".cc.END", "") != f + ".END" || 643 string_replace(f + ".END", ".c.END", "") != f + ".END" || 644 string_replace(f + ".END", ".mm.END", "") != f + ".END" || 645 string_replace(f + ".END", ".m.END", "") != f + ".END") { 646 _uses_cflags = true 647 } 648 } 649 } 650 if (_uses_cflags && clang_unsafe_buffers_paths != "") { 651 inputs += [ clang_unsafe_buffers_paths ] 652 } 653 654 if (!defined(deps)) { 655 deps = [] 656 } 657 if (false) { # Mozilla 658 if (!defined(invoker.no_default_deps) || !invoker.no_default_deps) { 659 # This pulls in one of: 660 # //build/config:executable_deps 661 # //build/config:loadable_module_deps 662 # //build/config:shared_library_deps 663 # (This explicit list is so that grepping for these configs finds where 664 # they are used.) 665 deps += [ "//chromium/build/config:${_target_type}_deps" ] 666 } 667 668 if (is_clang && (!defined(invoker.use_libcxx_modules) || 669 invoker.use_libcxx_modules)) { 670 # These are necessary for Clang modules builds. 671 deps += [ 672 "//buildtools/third_party/libc++:_Builtin_limits", 673 "//buildtools/third_party/libc++:_Builtin_stdarg", 674 "//buildtools/third_party/libc++:_Builtin_stddef", 675 "//buildtools/third_party/libc++:std", 676 "//buildtools/third_party/libc++:std_config", 677 "//buildtools/third_party/libc++:std_core", 678 "//buildtools/third_party/libc++:std_ctype_h", 679 "//buildtools/third_party/libc++:std_errno_h", 680 "//buildtools/third_party/libc++:std_fenv_h", 681 "//buildtools/third_party/libc++:std_float_h", 682 "//buildtools/third_party/libc++:std_inttypes_h", 683 "//buildtools/third_party/libc++:std_math_h", 684 "//buildtools/third_party/libc++:std_private_mbstate_t", 685 "//buildtools/third_party/libc++:std_string_h", 686 "//buildtools/third_party/libc++:std_uchar_h", 687 "//buildtools/third_party/libc++:std_wctype_h", 688 ] 689 } 690 } 691 692 # On Android, write shared library output file to metadata. We will use 693 # this information to, for instance, collect all shared libraries that 694 # should be packaged into an APK. 695 if (!defined(invoker.metadata) && (is_android || is_robolectric) && 696 (_target_type == "shared_library" || 697 _target_type == "loadable_module")) { 698 _output_name = _target_name 699 if (defined(invoker.output_name)) { 700 _output_name = invoker.output_name 701 } 702 703 # Remove 'lib' prefix from output name if it exists. 704 _magic_prefix = "$0x01$0x01" 705 _output_name = string_replace("${_magic_prefix}${_output_name}", 706 "${_magic_prefix}lib", 707 _magic_prefix, 708 1) 709 _output_name = string_replace(_output_name, _magic_prefix, "", 1) 710 711 if (defined(output_extension)) { 712 _shlib_extension = ".$output_extension" 713 } else { 714 _shlib_extension = ".so" 715 } 716 717 metadata = { 718 shared_libraries = 719 [ "$root_out_dir/lib${_output_name}${_shlib_extension}" ] 720 } 721 } 722 } 723 } 724 } 725 726 # ============================================================================== 727 # COMPONENT SETUP 728 # ============================================================================== 729 730 # Defines a component, which equates to a shared_library when 731 # is_component_build == true and a static_library otherwise. 732 # 733 # Use static libraries for the static build rather than source sets because 734 # many of of our test binaries link many large dependencies but often don't 735 # use large portions of them. The static libraries are much more efficient to 736 # link in this situation since only the necessary object files are linked. 737 # 738 # The invoker can override the type of the target in the non-component-build 739 # case by setting static_component_type to either "source_set" or 740 # "static_library". If unset, the default will be used. 741 template("component") { 742 if (is_component_build) { 743 _component_mode = "shared_library" 744 745 # Generate a unique output_name for a shared library if not set by invoker. 746 if (!defined(invoker.output_name)) { 747 _output_name = get_label_info(":$target_name", "label_no_toolchain") 748 _output_name = 749 string_replace(_output_name, "$target_name:$target_name", target_name) 750 _output_name = string_replace(_output_name, "//", "") 751 _output_name = string_replace(_output_name, "/", "_") 752 _output_name = string_replace(_output_name, ":", "_") 753 } 754 } else if (defined(invoker.static_component_type)) { 755 assert(invoker.static_component_type == "static_library" || 756 invoker.static_component_type == "source_set") 757 _component_mode = invoker.static_component_type 758 } else if (!defined(invoker.sources) || invoker.sources == []) { 759 # When there are no sources defined, use a source set to avoid creating 760 # an empty static library (which generally don't work). 761 _component_mode = "source_set" 762 } else { 763 _component_mode = "static_library" 764 } 765 target(_component_mode, target_name) { 766 if (defined(_output_name)) { 767 output_name = _output_name 768 } 769 if (is_component_build && is_android) { 770 # By appending .cr, we prevent name collisions with libraries already 771 # loaded by the Android zygote. 772 output_extension = "cr.so" 773 } 774 forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) 775 forward_variables_from(invoker, "*", TESTONLY_AND_VISIBILITY) 776 } 777 } 778 779 # Component defaults 780 # Set a variable since we also want to make this available 781 # to mixed_component.gni 782 if (is_component_build) { 783 default_component_configs = default_shared_library_configs 784 if (is_android) { 785 default_component_configs -= 786 [ "//chromium/build/config/android:hide_all_but_jni_onload" ] 787 } 788 if (is_win) { 789 # We don't want component dlls to statically load OS dlls that aren't 790 # loaded normally. 791 default_component_configs += [ "//chromium/build/config/win:delayloads" ] 792 } 793 } else { 794 default_component_configs = default_compiler_configs 795 } 796 797 set_defaults("component") { 798 configs = default_component_configs 799 }