blob: b096239c7f243ca90fdb1eaafe13e96d9fcb64d1 [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("$zx/public/gn/build_api_module.gni")
import("$zx/public/gn/config/standard.gni")
import("$zx/public/gn/copied_files_dir.gni")
import("$zx/public/gn/prebuilt.gni")
import("$zx/public/gn/test/zbi_test.gni")
import("$zx/public/gn/toolchain/c_utils.gni")
import("$zx/public/gn/toolchain/environment_redirect.gni")
import("$zx/public/gn/zbi.gni")
declare_args() {
# Defines the `//:default` target: what `ninja` with no arguments does.
# TODO(fxbug.dev/3156): This must be set by the controlling Fuchsia GN build.
default_deps = false
}
assert(default_deps != false,
"TODO(fxbug.dev/3156): Zircon build must be driven by Fuchsia build")
###
### 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".
#
# TODO(fxbug.dev/3156): Note this does not include build_api_module() uses meant
# just for legacy build integration. We don't consider those to be actual
# build API modules; using build_api_module() is just a convenience for
# creating them. Importantly, they are not part of the API contract with
# consumers of the overall build. They're purely implementation details of
# the temporary Frankenbuild arrangement.
#
# Type: list(string)
build_api_module("api") {
testonly = true
data_keys = [ "build_api_modules" ]
deps = [
":args",
":binaries",
":generated_sources",
":tests",
":zbi_tests",
]
}
# See //:args in the fuchsia build for a description.
build_api_module("args") {
contents = read_file("$root_build_dir/args.gn", "scope")
}
# This describes all the binaries linked by the build.
#
# This enumerates each linked binary (executable, shared library, or
# loadable/"plug-in" module) used by the build, or produced by the build.
#
# This includes host tools, kernels, boot loaders, drivers, as well as
# normal executables. This also includes prebuilt toolchain runtime
# libraries that end up in image files. It does not yet include any
# non-native binary formats.
#
# For non-prebuilts, this is meant to reach the entire dependency graph
# of all binaries that the build would ever produce. Not every binary
# described is necessary actually produced by any given Ninja run. Either
# the $debug or the $dist file for any individual binary can be passed to
# Ninja as a specific target argument to ensure it's built and
# up to date before making use of that binary. Like all build_api_module()
# targets, the top-level "binaries" target serves as a Ninja target to
# request that every binary described be built.
#
# Note that in certain cases, the paths in `debug` and `dist` will
# point out of the build tree, and thus cannot be used as Ninja targets.
# This happens for prebuilts or binaries produced by the Zircon build.
#
# Type: list(scope)
#
# cpu
# Required: CPU architecture the binary is for, e.g. "arm64" or "x64".
# Type: string
#
# os
# Required: OS the binary is for, e.g. "fuchsia", "linux", or "mac".
# Type: string
#
# environment
# Required: The ${toolchain.environment} name of what specific
# execution this was built for, e.g. "user", "host", "guest". The
# tuple of ($cpu, $os, $environment) should indicate what hardware and
# software environment this binary is compatible with.
# Type: string
#
# label
# Required: The GN label of the binary target.
# Type: label_with_toolchain
#
# type
# Required: The type of binary.
# Type: "executable" or "shared_library" or "loadable_module"
#
# debug
# Required: Path to where the unstripped or separate debug file is
# found, relative to $root_build_dir. If $dist is omitted, this
# is also the file that is used at runtime.
# Type: path relative to $root_build_dir
#
# dist
# Optional: Path to where the stripped binary for deployment/execution is
# found, relative to $root_build_dir. This binary may be required for
# some debugging tasks if $debug is a separate debug file rather than
# an unstripped file. It should exactly match the binary that will be
# seen on devices or run directly on hosts.
# Type: path relative to $root_build_dir
#
# elf_build_id
# Optional: Path to a file containing the lowercase ASCII hexadecimal
# representation of the ELF build ID in this binary. This is omitted
# for OS environments that don't use ELF. For an ELF binary that
# doesn't have a build ID note, this key will be present but point to
# an empty file.
# Type: path relative to $root_build_dir
#
# breakpad
# Optional: Path to the breakpad symbol file for the debug binary. This
# will only be present if $output_breakpad_syms was set.
# Type: path relative to $root_build_dir
build_api_module("binaries") {
testonly = true
deps = [ ":everything" ]
data_keys = [ "binaries" ]
}
# This describes all the generated source files in the build.
#
# The intent is that telling Ninja to build all these individual files
# will be the minimal work sufficient for source code analysis of all
# the files described in the compilation database to be viable.
#
# Type: list(path relative to $root_build_dir)
#
build_api_module("generated_sources") {
testonly = true
deps = [ ":everything" ]
data_keys = [ "generated_sources" ]
}
# 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.
#
# 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: $current_cpu and $current_os values, respectively, for
# which this test is intended.
# - 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
#
build_api_module("tests") {
testonly = true
data_keys = [ "tests" ]
deps = default_deps
}
# This tells the infra recipes how to run ZBI tests, defined with zbi_test(),
# which is a class of tests that are 'run' by booting an associated ZBI and
# listening on serial for a particular string indicating success.
#
# The schema produced here matches //:images with the addition of the
# `success_string` key.
#
# Type: list(scope)
#
# * cpu
# - Required: CPU architecture the image is for, e.g. "arm64" or "x64".
# - Type: string
#
# * name
# - Required: The primary way that this ZBI is known to consumers.
# Note that the name need not be unique within the images list.
# The tuple of ($name, $cpu) should be unique.
# - Type: string
#
# * label
# - Required: The GN label of the image target.
# - Type: label_with_toolchain
#
# * path
# - Required: Path to where the file is found, relative to $root_build_dir.
# This is also the argument to Ninja that ensures this image will be built.
# - Type: path relative to $root_build_dir
#
# * bootserver_netboot
# - Required: bootserver commandline option for booting the ZBI.
# - Type: string
#
# * success_string
# - Required: The string that the ZBI test outputs to indicate success.
# - Type: string
#
# * device_types
# - Required: The list of device types that this test should be run on.
# //build/testing/platforms.gni lists the allowed values; others will
# be ignored.
# - Type: list(string)
#
# * qemu_kernel_label
# - Optional: Label appearing in $label of an //:images entry.
# That image should be used in place of the usual `qemu-kernel` image.
# - Type: label_with_toolchain
#
# * timeout
# - Optional: Timeout for running the test, in seconds.
# - Type: seconds
#
build_api_module("zbi_tests") {
testonly = true
data_keys = [ "zbi_tests" ]
deps = [ ":everything" ]
}
###
### Top-level targets.
###
# This is used in the top-level build_api_module() deps to reach "everything".
# Note that "all" is a magical target name to Ninja, hence this name instead.
group("everything") {
testonly = true
deps = default_deps
}
# This is the default target that Ninja builds when given no target arguments.
group("default") {
testonly = true
deps = default_deps
}
###
### TODO(fxbug.dev/3156): Temporary hacks for integrating with the legacy Fuchsia
### GN build.
###
if (current_toolchain == default_toolchain) {
build_api_module("legacy_dirs") {
testonly = true
data_keys = [ "legacy_dirs" ]
walk_keys = [ "legacy_barrier" ]
deps = []
foreach(cpu, standard_fuchsia_cpus) {
deps += [ ":legacy-$cpu" ]
}
}
foreach(cpu, standard_fuchsia_cpus) {
group("legacy-$cpu") {
testonly = true
deps = [
":legacy-aux-$cpu",
":legacy-deps-$cpu",
":legacy-tests-$cpu",
]
}
build_api_module("legacy_sysroot-$cpu") {
testonly = true
data_keys = [ "legacy_sysroot" ]
walk_keys = [ "legacy_barrier" ]
deps = [ ":all-ulib-$cpu" ]
}
}
}
foreach(cpu, standard_fuchsia_cpus) {
if (current_toolchain == default_toolchain) {
zbi_input("legacy-tests-$cpu") {
output_dir = root_build_dir
testonly = true
cpu = cpu
deps = [ ":legacy-tests-deps-$cpu" ]
}
# The legacy Fuchsia GN build needs to consume a manifest of libraries
# built for ASan (and all the libraries themselves). When the main
# build is ASan, it needs to find the non-ASan libraries here too.
manifest_file("legacy-aux-$cpu") {
testonly = true
deps = [
":all-ulib-$cpu",
":instrumented-ulib-$cpu",
# Include the tests so their libraries are in the aux manifest
# when individual binaries are drawn from the tests manifest.
":legacy-tests-deps-$cpu",
]
metadata = {
# This prevents build_api_module("legacy-$cpu") from visiting the
# ASan incarnations of all the libraries. The legacy build wants
# only the manifest of ASan shared libraries. It wants the targets
# themselves only from the primary build.
legacy_barrier = []
}
}
}
environment_redirect("legacy-deps-$cpu") {
visibility = [ ":*" ]
testonly = true
environment_label = "$zx/public/gn/toolchain:user"
cpu = cpu
deps = [ "$zx/kernel" ]
metadata = {
legacy_barrier = []
}
}
environment_redirect("legacy-tests-deps-$cpu") {
visibility = [ ":*" ]
testonly = true
environment_label = "$zx/public/gn/toolchain:user"
cpu = cpu
direct = true
deps = [ "$zx/system/utest" ]
}
environment_redirect("all-ulib-$cpu") {
testonly = true
cpu = cpu
environment_label = "$zx/public/gn/toolchain:user"
shlib = true
exclude_variant_tags = [ "instrumented" ]
deps = [ "$zx/system/ulib" ]
}
environment_redirect("instrumented-ulib-$cpu") {
testonly = true
cpu = cpu
environment_label = "$zx/public/gn/toolchain:user"
deps = [ ":instrumented-ulib-redirect" ]
}
}
if (toolchain.environment == "user") {
instrumented_variants = []
foreach(selector, toolchain.variant_selectors) {
if (selector.tags + [ "instrumented" ] - [ "instrumented" ] !=
selector.tags) {
instrumented_variants += [ selector.variant ]
instrumented_variants -= [ selector.variant ]
instrumented_variants += [ selector.variant ]
}
}
group("instrumented-ulib-redirect") {
testonly = true
visibility = [ ":*" ]
deps = []
foreach(variant, instrumented_variants) {
deps += [ ":instrumented-ulib-redirect.$variant" ]
}
}
foreach(variant, instrumented_variants) {
environment_redirect("instrumented-ulib-redirect.$variant") {
testonly = true
visibility = [ ":instrumented-ulib-redirect" ]
variant = variant
# NOTE: Order of deps items is important.
deps = [ "$zx/system/ulib" ]
foreach(dep, toolchain.implicit_deps) {
if (dep == "$dep") {
deps += [ dep ]
} else {
deps += dep.add
}
}
}
}
}
build_api_module("legacy_images") {
testonly = true
data_keys = [ "images" ]
deps = [ ":zbi_tests" ]
foreach(cpu, standard_fuchsia_cpus) {
deps += [ ":legacy-$cpu" ]
}
}
# This target complements legacy_images in that it lists the various elements
# that end up in images.
foreach(cpu, standard_fuchsia_cpus) {
build_api_module("legacy_unification-$cpu") {
testonly = true
data_keys = [ "zx_manifest" ]
deps = [ ":legacy-$cpu" ]
# Add the dependencies of legacy-aux directly, as that target sets a barrier
# that's not desirable here.
deps += [
":all-ulib-$cpu",
":instrumented-ulib-$cpu",
":legacy-tests-deps-$cpu",
]
}
}