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