-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBUILD.gn
475 lines (432 loc) · 14.1 KB
/
BUILD.gn
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
# Copyright 2024 Mist Tecnologia LTDA. All rights reserved.
# Copyright 2019 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/compiled_action.gni")
import("//build/config/build_api_module.gni")
import("//build/config/compiler.gni")
import("//build/rust/config.gni")
import("//build/testing/validated_test_types_group.gni")
import("//build/toolchain/zircon/clang.gni")
import("//build/zbi/zbi.gni")
declare_args() {
# Host-only tests. These cannot have any dependency on an assembled platform
# image, or the compiled OS itself, not even for their host_test_data().
#
# These will be added to the build using the host toolchain.
host_test_labels = []
# If you add labels to this variable, these will be included in the 'host'
# artifact set, which represents an additional set of host-only software that
# is produced by the build.
#
# These will be added to the build using the host toolchain.
host_labels = []
# Platform builders can add targets to this list so that they get built with
# the //:default target
additional_default_targets = []
# These labels are added as dependencies of '//:default' transitively via
# '//:build_only'. These are used to add targets that need to be built
# but aren't part of any product, board, etc.
#
# These also serve as an alternative to '//:default' for sub-builds that
# only want to build and define a small subset of the tree.
build_only_labels = []
}
if (host_os == "mac") {
import("//build/config/mac/mac_sdk.gni")
}
assert(
current_toolchain == default_toolchain,
"The root build file (//BUILD.gn) can only be processed in the `default_toolchain`.")
###
### fx integration.
###
# Write a file that can be sourced by `fx`. This file is produced
# by `gn gen` and is not known to Ninja at all, so it has nothing to
# do with the build itself. Its sole purpose is to leave bread
# crumbs about the settings `gn gen` used for `fx` to use later.
_relative_build_dir = rebase_path(root_build_dir, "//", "//")
_host_out_dir = rebase_path(host_out_dir, root_build_dir)
_fx_config_lines = [
"# Generated by `gn gen`.",
"FUCHSIA_BUILD_DIR='${_relative_build_dir}'",
"FUCHSIA_ARCH='${target_cpu}'",
"FUCHSIA_ZBI_COMPRESSION=zstd",
"HOST_OUT_DIR='${_host_out_dir}'",
]
write_file("$root_build_dir/fx.config", _fx_config_lines)
generated_file("default_toolchain_name.txt") {
outputs = [ "$root_build_dir/default_toolchain_name.txt" ]
contents = default_toolchain
}
###
### Build API modules.
###
# This is the top-level build API module that just lists all the others.
# Each element of the list is the simple name of the API module; the
# module's contents are found at "$root_build_dir/$target_name.json".
#
# Type: list(string)
#
build_api_module("api") {
testonly = true
data_keys = [ "build_api_modules" ]
deps = [
":args",
":tool_paths",
]
}
# This target is used to generate, at `gn gen` time a file
# that is exclusively used by //build/api/client.py.
# NOTE: nothing should depend on this target.
generated_file("build_api_client_info") {
deps = [ "//:api" ]
outputs = [ "$root_build_dir/build_api_client_info" ]
data_keys = [ "build_api_client_info" ]
walk_keys = [ "build_api_client_info_barrier" ]
testonly = true
visibility = [] # Empty on purpose
}
# TODO(crbug.com/gn/132): Remove when GN emits the equivalent information
# itself.
#
# in file: "$root_build_dir/args.json"
#
# This just regurgitates the build arguments specified to `gn gen`. This is
# the exact JSON representation of the settings in "$root_build_dir/args.gn".
# It does not include build arguments left to their default values. So to
# reproduce the settings of this build, one could put in `args.gn`:
# ```
# forward_variables_from(read_file("args.json", "json"), "*")
# ```
# Type: scope
#
build_api_module("args") {
contents = read_file("$root_build_dir/args.gn", "scope")
}
# Tests in the build.
#
# Below, the "testing root" refers to $root_build_dir on host, and the full
# filesystem path from the root on device.
#
# This rule outputs the tests.json file in the build directory,
# which is aggregated at test time.
#
# The format is documented at
# https://fuchsia.dev/fuchsia-src/reference/testing/tests-json-format
#
# Type: list(scope)
#
# * name
# - Required: Name of test.
# - Type: string
#
# * label
# - Required: GN label associated with the test
# - Type: label_with_toolchain
#
# * path
# - Required: Path to the test's executable.
# - Type: path relative to the testing root.
#
# * cpu, os
# - Required: cpu and os values, respectively, for which this test is
# intended. Defaults to $current_cpu and $current_os if not manually
# specified.
# - Type: string
#
# * disabled
# - Optional: a free-form string indicating a reason for the test being
# disabled.
# - Type: string
#
# * runtime_deps
# - Optional: a JSON file containing a list of root_build_dir-relative
# paths defining ascribed runtime dependencies of the test. These
# dependencies are aggregated via the metadata graph of the associated
# test target under a data key of "test_runtime_deps.
# - Type: path relative to root_build_dir
#
# * isolated
# - Optional: whether the test needs to be run in isolation to other tests.
# - Type: bool
#
# * timeout_secs
# - Optional: the timeout in seconds for the test.
# - Type: int
#
generated_file("tests_from_metadata") {
testonly = true
data_keys = [ "tests" ]
walk_keys = [ "tests_barrier" ]
outputs = [ "${root_build_dir}/tests_from_metadata.json" ]
output_conversion = "json"
deps = [
# Pull in tests from host_labels. This is deprecated, and tests should be
# in //:host_tests instead.
"//:host",
# Pull in tests from the non-device type-specific test groups.
"//:host_tests",
]
}
# Tools provided by the build or as prebuilts, to be used outside the build.
#
# Type: list(scope)
#
# * name
# - Required: Name of a host tool.
# - Type: string
#
# * label
# - Required: GN label associated with the tool.
# - Type: label_with_toolchain
#
# * path
# - Required: Path to the tool's executable for the build host.
# - Type: path relative to $root_build_dir
#
# * cpu, os
# - Required: $current_cpu and $current_os values, respectively, for
# which this tool is intended.
# - Type: string
#
# * runtime_files
# - Optional: Path to files that are also required for the tool to function
# (must also be built by `label`).
# - Type: path relative to $root_build_dir
build_api_module("tool_paths") {
testonly = true
data_keys = [ "tool_paths" ]
walk_keys = [ "tool_barrier" ]
# Disable automatic sorting and grouping to ensure comments are associated
# with only the intended lines.
#
# NOSORT
deps = [
# Pull in tools from host_labels.
":host",
"//build/rust:tool_paths.llvm-profdata-rust($host_toolchain)",
":tool_paths.llvm-tools",
":tool_paths.metadata",
"//third_party/cobalt/src/bin/config_change_validator/src:bin($host_toolchain)",
"//third_party/cobalt/src/bin/config_parser/src:bin($host_toolchain)",
"//tools/fidl:fidl-lint($host_toolchain)",
"//tools/fidl:fidlfmt($host_toolchain)",
"//tools/fidl/fidlc:host($host_toolchain)",
"//zircon/third_party/uapp/mkfs-msdosfs($host_toolchain)",
"//zircon/tools/lz4($host_toolchain)",
"//zircon/tools/zbi($host_toolchain)",
"//zircon/tools/zither($host_toolchain)",
]
}
group("tool_paths.metadata") {
visibility = [ ":tool_paths" ]
prebuilt_tools = [
"$rustc_prefix/bin/cargo",
"$rustc_prefix/bin/rustc",
"$rustc_prefix/bin/rustdoc",
"$rustc_prefix/bin/rustfmt",
"//prebuilt/third_party/clang/$host_platform/share/clang/clang-format-diff.py",
"//prebuilt/third_party/clang/$host_platform/share/clang/clang-tidy-diff.py",
"//prebuilt/third_party/gn/$host_platform/gn",
"//prebuilt/third_party/go/$host_platform/bin/go",
"//prebuilt/third_party/go/$host_platform/bin/gofmt",
"//prebuilt/third_party/ninja/$host_platform/ninja",
"//prebuilt/third_party/python3/$host_platform/bin/python3",
"//prebuilt/tools/shac/shac",
]
renamed_prebuilt_tools = [
# Rename prebuilt buildstats to avoid conflict with the buildstats go_binary
# when they are both included in the build graph.
{
name = "buildstats_prebuilt"
path = "//prebuilt/tools/buildstats/$host_platform/buildstats"
},
# Rename prebuilt ninjatrace to avoid conflict with the ninjatrace go_binary
# when they are both included in the build graph.
{
name = "ninjatrace_prebuilt"
path = "//prebuilt/tools/ninjatrace/$host_platform/ninjatrace"
},
]
metadata = {
tool_paths = []
foreach(tool, prebuilt_tools) {
tool_paths += [
{
cpu = host_cpu
label = get_label_info(":$target_name", "label_with_toolchain")
name = get_path_info(tool, "name")
os = host_os
path = rebase_path(tool, root_build_dir)
},
]
}
foreach(renamed_tool, renamed_prebuilt_tools) {
tool_paths += [
{
cpu = host_cpu
label = get_label_info(":$target_name", "label_with_toolchain")
name = renamed_tool.name
os = host_os
path = rebase_path(renamed_tool.path, root_build_dir)
},
]
}
# Add SSH prebuilts to the tool paths. We need both architectures regardless
# of the host architectures since it's used on test bots that may be running
# ARM64 (even if we built on x64).
foreach(arch,
[
"arm64",
"x64",
]) {
tool_paths += [
{
cpu = arch
label = get_label_info(
"//prebuilt/third_party/openssh-portable/linux-${arch}/bin/ssh",
"label_with_toolchain")
name = get_path_info(
"//prebuilt/third_party/openssh-portable/linux-${arch}/bin/ssh",
"name")
os = "linux"
path = rebase_path(
"//prebuilt/third_party/openssh-portable/linux-${arch}/bin/ssh",
root_build_dir)
},
]
}
}
}
group("tool_paths.llvm-tools") {
visibility = [ ":tool_paths" ]
_llvm_tools = [
"clang",
"clang++",
"clang-doc",
"clang-format",
"clang-include-fixer",
"clang-refactor",
"clang-tidy",
"clangd",
"llvm-cov",
"llvm-cxxfilt",
"llvm-dwp",
"llvm-objcopy",
"llvm-profdata",
"llvm-readelf",
"llvm-size",
"llvm-strip",
"llvm-symbolizer",
"llvm-xray",
"sancov",
]
metadata = {
tool_paths = []
foreach(tool, _llvm_tools) {
tool_paths += [
{
cpu = host_cpu
label = get_label_info(":$target_name", "label_with_toolchain")
name = tool
os = host_os
path = rebase_path("$clang_tool_dir/$tool", root_build_dir)
},
]
}
# Add the arm64 version of llvm-profdata to tool_paths for use by the arm64
# coverage builder.
if (target_cpu == "arm64" && host_platform == "linux-x64" && is_coverage) {
tool_paths += [
{
cpu = target_cpu
label = get_label_info(":$target_name", "label_no_toolchain") +
"($host_arm64_toolchain)"
name = "llvm-profdata"
os = host_os
path = rebase_path(
"//prebuilt/third_party/clang/linux-arm64/bin/llvm-profdata",
root_build_dir)
},
]
}
}
}
###
### Top-level targets.
###
group("default") {
testonly = true
deps = [
"//:build_only",
"//:host",
]
# Add any additional targets from the product.
deps += additional_default_targets
}
###
# The build-only group. These are additional targets to add to the build but
# are not part of a product, board, or host tools. This group also serves as
# an alternative to '//:default' when performing sub-builds.
group("build_only") {
testonly = true
deps = build_only_labels
}
# Host-only tests. These cannot have any dependency on an assembled platform
# image, or the compiled OS itself, not even for their host_test_data().
validated_test_types_group("host_tests") {
testonly = true
visibility = [ ":*" ]
allowed_test_types = [ "host_only" ]
deps = []
foreach(label, host_test_labels) {
# Strip any toolchain that is provided, and replace with the host toolchain.
full_label = get_label_info(label, "label_no_toolchain")
deps += [ "$full_label($host_toolchain)" ]
}
}
###
# GN-Argument configured groups for host binaries and tools
#
group("host") {
# TODO(https://fxbug.dev/42160904) investigate removing testonly here
testonly = true
public_deps = [
# Static analysis tools used by shac should always be built so that
# `fx format-code` and other static analysis entrypoints can be run on any
# build configuration.
"//bundles/tools/shac:shac_tools",
# Host tests for //build/api/client
"//build/api:tests",
# Tools & tests added by the developer
":developer_host_tools",
]
}
# WARNING: Known to infrastructure
#
# This group creates a single ninja build target that can create all targets
# specified by `host_labels` with `fx build :developer_host_tools`
group("developer_host_tools") {
testonly = true
public_deps = []
foreach(label, host_labels) {
# Strip any toolchain that is provided, and replace with the host toolchain.
full_label = get_label_info(label, "label_no_toolchain")
public_deps += [ "$full_label($host_toolchain)" ]
}
}
# A GN pool matching the special Ninja 'console' pool. Any action() that
# uses this pool will be able to send its stdout/stderr directly to the
# output terminal, instead of being buffered by Ninja until the command
# completes.
#
# This is very useful for long-running commands, e.g. bazel build invocations
# that can take several dozen seconds to complete, or any other command that
# prints a _lot_ of output, because our infra bots will timeout if Ninja tries
# to print too much data at once after command completion for some undetermined
# reason.
#
pool("console") {
depth = 1
}