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