blob: 30f6fa38b0ed9028332de44f0ec2bc71e52ff0ee [file] [log] [blame]
# 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/board.gni")
import("//build/config/fuchsia/zbi.gni")
import("//build/config/fuchsia/zircon.gni")
import("//build/testing/platforms.gni")
import("//build/toolchain/ccache.gni")
import("//build/toolchain/goma.gni")
declare_args() {
# If you add package labels to this variable, the packages will be included in
# the 'base' package set, which represents the set of packages that are part
# of an OTA. These pacakages are updated as an atomic unit during an OTA
# process and are immutable and are a superset of the TCB (Trusted Computing
# Base) for a product. These packages are never evicted by the system.
base_package_labels = []
# If you add package labels to this variable, the packages will be included
# in the 'cache' package set, which represents an additional set of software
# that is made available on disk immediately after paving and in factory
# flows. These packages are not updated with an OTA, but instead are updated
# ephemerally. This cache of software can be evicted by the system if storage
# pressure arises or other policies indicate.
cache_package_labels = []
# If you add package labels to this variable, the packages will be included
# in the 'universe' package set, which represents all software that is
# produced that is to be published to a package repository or to the SDK by
# the build. The build system ensures that the universe package set includes
# the base and cache package sets, which means you do not need to redundantly
# include those labels in this variable.
universe_package_labels = []
# [Zircon GN build arguments](/docs/gen/zircon_build_arguments.md).
# This is included in the default value of [`zircon_args`](#zircon_args) so
# you can set this to add things there without wiping out the defaults.
# When you set `zircon_args` directly, then this has no effect at all.
# Arguments you set here override any arguments in the default
# `zircon_args`. There is no way to append to a value from the defaults.
# Note that for just setting simple (string-only) values in Zircon GN's
# [`variants`](/docs/gen/zircon_build_arguments.md#variants), the
# default [`zircon_args`](#zircon_args) uses a `variants` value derived from
# [`select_variant`](#select_variant) so for simple cases there is no need
# to explicitly set Zircon's `variants` here.
zircon_extra_args = {
}
# Additional Zircon GN labels to include in the Zircon build.
zircon_extra_deps = []
# Whether to include various features (non-shipping, insecure, etc.) in the
# kernel or netsvc builds.
zircon_enable_kernel_debugging_features = false
zircon_enable_netsvc_debugging_features = false
# Where to emit a tracelog from Zircon's GN run. No trace will be produced if
# given the empty string. Path can be source-absolute or system-absolute.
zircon_tracelog = ""
# Compliation database filter. Gets passed to --export_compile_commands=<filter>.
zircon_compdb_filter = "legacy-$target_cpu"
}
zircon_variants = []
foreach(selector, select_variant) {
if (selector == "$selector") {
zircon_variants += [ selector ]
}
}
# Separate block because zircon_* declared above are used in the default.
declare_args() {
# [Zircon GN build arguments](/docs/gen/zircon_build_arguments.md).
# The default passes through GOMA/ccache settings and
# [`select_variant`](#select_variant) shorthand selectors.
# **Only set this if you want to wipe out all the defaults that
# propagate from Fuchsia GN to Zircon GN.** The default value
# folds in [`zircon_extra_args`](#zircon_extra_args), so usually
# it's better to just set `zircon_extra_args` and leave `zircon_args` alone.
# Any individual Zircon build argument set in `zircon_extra_args` will
# silently clobber the default value shown here.
zircon_args = {
use_ccache = use_ccache
use_goma = use_goma
goma_dir = rebase_path(goma_dir)
zbi_compression = zbi_compression
if (clang_prefix != default_clang_prefix) {
# Propagate a custom value to override Zircon's default. But don't
# propagate the default because Zircon has proper incremental build
# dependencies on toolchain updates only if it knows it's using the
# prebuilt.
clang_tool_dir = rebase_path(clang_prefix, "", root_build_dir)
}
variants = zircon_variants
default_deps = [ "//:legacy-$target_cpu" ] + zircon_extra_deps
enable_kernel_debugging_features = zircon_enable_kernel_debugging_features
enable_netsvc_debugging_features = zircon_enable_netsvc_debugging_features
forward_variables_from(zircon_extra_args, "*")
}
}
# The Zircon GN is completely a puppet of this build. This gen runs that gen.
if (current_toolchain == default_toolchain) {
# First run Zircon's `gn gen`. By GN evaluation order this is roughly
# the first thing that happens at all and it's synchronous so after this
# point we can read in files written by this gen step.
gn_cmd = [
"gen",
"-q",
"--root=" + rebase_path("//zircon", root_build_dir),
"--args=# THIS FILE IS CLOBBERED. DO NOT EDIT!$0x0a" +
"# Instead, edit $root_build_dir/args.gn to add$0x0a" +
"# zircon_extra_args = { ... } to override settings below.$0x0a" +
"forward_variables_from($zircon_args, \"*\")",
"--export-compile-commands=$zircon_compdb_filter",
rebase_path(zircon_root_build_dir, root_build_dir),
]
if (zircon_tracelog != "") {
gn_cmd += [ "--tracelog=" + rebase_path(zircon_tracelog, root_build_dir) ]
}
exec_script("//prebuilt/third_party/gn/${host_platform}/gn", gn_cmd)
exec_script("//build/zircon/populate_zircon_public.py",
[ rebase_path("$zircon_root_build_dir/legacy_dirs.json") ],
"",
[ "$zircon_root_build_dir/legacy_dirs.json" ])
# This file indicates what Ninja invocation must be done to build Zircon
# prerequisites before *any* Ninja invocation for this build.
write_file("$root_build_dir/zircon.json",
{
dir = rebase_path(zircon_root_build_dir, root_build_dir)
targets = [ "default" ]
},
"json")
}
# 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, "//", "//")
_fx_config_lines = [
"# Generated by `gn gen`.",
"FUCHSIA_BUILD_DIR='${_relative_build_dir}'",
"FUCHSIA_ARCH='${target_cpu}'",
"FUCHSIA_ZBI_COMPRESSION=$zbi_compression",
]
write_file("$root_build_dir/fx.config", _fx_config_lines)
# Permit dependencies on testonly targets from packages.
testonly = true
group("default") {
deps = [
":build_time_checks",
"//build/images:packages",
"//sdk",
]
if (base_package_labels != [] || cache_package_labels != []) {
deps += [ "//build/images" ]
}
if (universe_package_labels != []) {
deps += [ "//build/images:updates" ]
}
}
group("build_time_checks") {
deps = [
"//tools/fidlgen_llcpp_zircon:validate",
]
}
group("recovery_image") {
deps = [
"build/images/recovery",
]
}
# TODO(joshuaseaton|mcgrathr): Make this a formal build_api_module().
#
# Aggregates metadata about all tests within the build graph to create a
# top-level manifest.
generated_file("tests") {
outputs = [
"$root_build_dir/tests.json",
]
data_keys = [ "test_spec" ]
output_conversion = "json"
deps = [
"//build/images:packages",
"//sdk",
]
}
group("tool_paths.zircon") {
visibility = [ ":tool_paths" ]
zircon_entries = read_file("$zircon_root_build_dir/tool_paths.json", "json")
metadata = {
tool_paths = []
foreach(tool, zircon_entries) {
tool_paths += [
{
forward_variables_from(tool, "*")
path = rebase_path(path, root_build_dir, zircon_root_build_dir)
},
]
}
}
}
# Aggregates metadata about the paths of tools within the build graph.
# See documentation at //zircon:tool_paths for a similar file with
# identical schema.
generated_file("tool_paths") {
outputs = [
"$root_build_dir/tool_paths.json",
]
data_keys = [ "tool_paths" ]
output_conversion = "json"
deps = [
":tool_paths.zircon",
"//build/images:packages",
"//sdk",
]
}
# Aggregates metadata about all fuzz targets within the build graph to create a
# top-level manifest.
generated_file("fuzzers") {
outputs = [
"$root_build_dir/fuzzers.json",
]
data_keys = [ "fuzz_spec" ]
output_conversion = "json"
deps = [
"//build/images:packages",
]
}
group("breakpad_symbols") {
public_deps = [
"//build/gn:breakpad_symbols",
]
}
group("package_archive") {
public_deps = [
"//build/gn:package_archive",
]
}
# Generates a JSON manifest of the platforms available for testing, along with
# their properties.
target_platforms = []
foreach(platform, test_platforms) {
if (!defined(platform.cpu) || platform.cpu == current_cpu) {
target_platforms += [ platform ]
}
}
write_file("$root_build_dir/platforms.json", target_platforms, "json")
# These groups exist at the root of the build so relative labels specified
# through GN args are interpreted as if they were absolute.
group("additional_base_packages") {
testonly = true
visibility = [ "//build/images:base_packages" ]
public_deps = base_package_labels + board_package_labels
}
group("additional_cache_packages") {
testonly = true
visibility = [ "//build/images:cache_packages" ]
public_deps = cache_package_labels
}
group("additional_universe_packages") {
testonly = true
visibility = [ "//build/images:universe_packages" ]
public_deps = universe_package_labels
}