blob: 502be9ecdf8a6a0f1fa6448c1ee8fb0e91a9c9e7 [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/legacy_pkg.gni") # TODO(BLD-353): temporary hack
import("$zx/public/gn/toolchain/c_utils.gni")
import("$zx/public/gn/toolchain/environment_redirect.gni")
import("$zx/public/gn/zbi.gni")
declare_args() {
# Whether to include all the Zircon tests in the main standalone ZBI.
# TODO(mcgrathr): This will be replaced by a more sophisticated plan for
# what images to build rather than a single "everything" image that needs
# to be pared down.
tests_in_image = true
}
# Build the native host tools intended for developer use.
_tools_targets = [ "tools" ]
foreach(host, standard_build_hosts) {
_tools_targets += [ "tools-${host.os}-${host.cpu}" ]
environment_redirect("tools-${host.os}-${host.cpu}.redirect") {
visibility = [ ":*" ]
testonly = true
environment_label = "$zx/public/gn/toolchain:host"
cpu = host.cpu
os = host.os
deps = [
"$zx/system/host:tools",
]
}
}
group("tools.redirect") {
visibility = [ ":*" ]
testonly = true
public_deps = [
":tools-${host_os}-${host_cpu}",
]
}
if (current_toolchain == default_toolchain) {
# Install the host developer tools for the running host platform in the
# "$root_build_dir/tools/" directory.
foreach(tools_target, _tools_targets) {
tools_rspfile = "$target_gen_dir/${tools_target}.rsp"
generated_file("$tools_target.rsp") {
visibility = [ ":$tools_target" ]
testonly = true
outputs = [
tools_rspfile,
]
deps = [
":$tools_target.redirect",
]
output_conversion = "list lines"
data_keys = [ "tool_executables" ]
}
action(tools_target) {
testonly = true
deps = [
":$tools_target.rsp",
]
script = "$zx/scripts/copy-files"
depfile = "$target_out_dir/$target_name.d"
outputs = [
depfile,
]
sources = [
tools_rspfile,
]
args = [
tools_target,
rebase_path(depfile, root_build_dir),
rebase_path(tools_rspfile, root_build_dir),
]
}
}
# Make ninja aliases for e.g. bootloader that gets all bootloader-$cpu.
top_level_redirects = [
"bootloader",
"kernel",
]
foreach(name, top_level_redirects) {
group(name) {
deps = []
foreach(cpu, standard_fuchsia_cpus) {
deps += [ ":$name-$cpu" ]
}
}
foreach(cpu, standard_fuchsia_cpus) {
environment_redirect("$name-$cpu") {
environment_label = "$zx/public/gn/toolchain:user"
cpu = cpu
deps = [
name,
]
}
}
}
# TODO(BLD-353): Temporary hacks for integrating with the legacy Fuchsia
# GN build.
host_tests_rspfile = "$target_gen_dir/host_tests.rsp"
generated_file("host_tests.rsp") {
testonly = true
visibility = [ ":legacy-host_tests" ]
outputs = [
host_tests_rspfile,
]
deps = [
"system/utest:host",
]
output_conversion = "list lines"
data_keys = [ "link_output" ]
walk_keys = [ "link_barrier" ]
}
action("legacy-host_tests") {
testonly = true
deps = [
":host_tests.rsp",
]
script = "$zx/scripts/copy-files"
depfile = "$target_out_dir/$target_name.d"
outputs = [
depfile,
]
sources = [
host_tests_rspfile,
]
args = [
"host_tests",
rebase_path(depfile, root_build_dir),
rebase_path(host_tests_rspfile, root_build_dir),
]
}
# TODO(BLD-353): Temporary hacks for integrating with the legacy Fuchsia
# GN build.
foreach(cpu, standard_fuchsia_cpus) {
group("legacy-$cpu") {
testonly = true
deps = [
":ids-$cpu",
":legacy-image-$cpu",
":legacy-tests-$cpu",
":tools",
"$zx/system/ulib:asan-manifest-$cpu",
]
}
environment_redirect("all-ulib-$cpu") {
testonly = true
cpu = cpu
environment_label = "$zx/public/gn/toolchain:user"
deps = [
"$zx/system/ulib",
]
}
legacy_pkg("manifest-$cpu") {
testonly = true
data_keys = [ "legacy_pkg_manifest" ]
deps = [
":all-ulib-$cpu",
":legacy-$cpu",
":tools",
# Separately listed because they're reached by dependencies only on x64.
"$zx/system/banjo/ddk-protocol-acpi",
"$zx/system/banjo/ddk-protocol-intelgpucore",
"$zx/system/banjo/ddk-protocol-intelhda-codec",
"$zx/system/banjo/ddk-protocol-intelhda-dsp",
# Separately listed because they're not reached by any dependencies.
"$zx/system/fidl/fuchsia-inspect",
"$zx/system/fidl/fuchsia-tracelink",
]
}
generated_file("boards-$cpu.list") {
testonly = true
outputs = [
"$root_build_dir/export/$target_name",
]
data_keys = [ "legacy_pkg_boards" ]
deps = [
":$cpu",
]
}
}
}
group("default") {
testonly = true
deps = [
":ids",
":images",
":tools",
]
}
group("all-cpu") {
testonly = true
deps = []
foreach(cpu, standard_fuchsia_cpus) {
deps += [
":$cpu",
":core-tests-$cpu",
]
}
}
foreach(cpu, standard_fuchsia_cpus) {
if (current_toolchain == default_toolchain) {
zbi("core-tests-$cpu") {
output_dir = root_build_dir
testonly = true
cpu = cpu
deps = [
":core-tests-$cpu-deps",
]
}
zbi(cpu) {
output_dir = root_build_dir
testonly = true
cpu = cpu
deps = [
":everything-$cpu",
]
# Since this is the top-level target people tend to use by hand
# instead of default when they want only one architecture at a time,
# give them tools as well since that's what they expect.
data_deps = [
":tools",
]
}
zbi("legacy-image-$cpu") {
output_dir = root_build_dir
testonly = true
cpu = cpu
deps = [
":legacy-deps-$cpu",
]
}
zbi_input("legacy-tests-$cpu") {
output_dir = root_build_dir
testonly = true
cpu = cpu
deps = [
":legacy-tests-deps-$cpu",
]
}
}
environment_redirect("core-tests-$cpu-deps") {
visibility = [ ":*" ]
testonly = true
cpu = cpu
environment_label = "$zx/public/gn/toolchain:user"
deps = [
"kernel",
"system/utest:core-tests",
]
assert_no_deps = [
"system/core/*",
"system/dev/*",
]
}
environment_redirect("legacy-deps-$cpu") {
visibility = [ ":*" ]
testonly = true
environment_label = "$zx/public/gn/toolchain:user"
cpu = cpu
deps = [
"$zx/bootloader",
"$zx/kernel",
"$zx/system/core",
"$zx/system/dev",
"$zx/system/uapp",
"$zx/third_party/uapp",
]
}
environment_redirect("legacy-tests-deps-$cpu") {
visibility = [ ":*" ]
testonly = true
environment_label = "$zx/public/gn/toolchain:user"
cpu = cpu
deps = [
"$zx/system/utest",
]
}
environment_redirect("everything-$cpu") {
visibility = [ ":*" ]
testonly = true
environment_label = "$zx/public/gn/toolchain:user"
cpu = cpu
deps = [
":legacy-deps-$cpu",
]
if (tests_in_image) {
deps += [ "$zx/system/utest" ]
}
}
}
# 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 = [
":buildargs",
":images",
]
}
# 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("buildargs.json", "json"), "*")
# ```
# Type: scope
build_api_module("buildargs") {
# The file does not exist at all if `gn gen` is run with no `--args`. But
# read_file() can't handle an optional file and there's no direct way to test
# for file existence from GN.
contents = exec_script("/bin/sh",
[
"-c",
"test ! -e args.gn || cat args.gn",
],
"scope")
}
# This describes all the "image" files the build can produce.
#
# Consumers of the build should look here for the images to be built.
# The $cpu, $name, and $type fields identify the purpose of each image.
# Consumers are expected to ignore extra images they have no use for or
# whose fields they don't understand.
#
# The $path field indicates where the file is found in the build
# directory. The presence of an image in the list means that the build
# *can* produce it, not that the build *will* produce it. Hence,
# consumers should use $path as an explicit argument to Ninja to ensure
# that each needed image gets built.
#
# 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 image is known to consumers.
# Note that the name need not be unique within the images list.
# The tuple of ($name, $type, $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
#
# type
# Required: Type of file, e.g. "zbi". This often corresponds to the
# extension used on the image file name, but not always. For many
# miscellaneous formats, this is just "bin" and the consumer is
# expected to understand what the particular format is for particular
# $name, $cpu combinations. Other types include:
# * "zbi": the ZBI (<zircon/boot/image.h>) format
# * "efi": an EFI executable that an EFI boot loader can load
# * "kernel": some other format loaded by a boot loader or emulator
# * "blk": contents to be written to a storage device or partition
# Type: string
#
build_api_module("images") {
testonly = true
data_keys = [ "images" ]
deps = [
":all-cpu",
]
# TODO(BLD-353): Temporary hacks for integrating with the legacy Fuchsia
# GN build.
foreach(cpu, standard_fuchsia_cpus) {
deps += [ ":legacy-$cpu" ]
}
}
# TODO(TC-303): ids.txt is deprecated and will be removed.
if (current_toolchain == default_toolchain) {
action("ids") {
testonly = true
outputs = [
"$root_build_dir/ids.txt",
]
deps = []
sources = []
foreach(cpu, standard_fuchsia_cpus) {
deps += [ ":ids-$cpu" ]
sources += [ "$root_build_dir/ids-$cpu.txt" ]
}
script = "/usr/bin/sort"
args = [
"-u",
"-o",
] + rebase_path(outputs + sources, root_build_dir)
}
foreach(cpu, standard_fuchsia_cpus) {
environment_redirect("ids-$cpu") {
testonly = true
cpu = cpu
environment_label = "$zx/public/gn/toolchain:user"
deps = [
":$target_name",
]
}
}
} else if (toolchain.environment == "user") {
toolchain_utils_action("ids-$current_cpu") {
testonly = true
deps = [
":elf-$current_cpu.list",
]
outputs = [
"$root_build_dir/ids-$current_cpu.txt",
]
sources = [
"$root_build_dir/elf-$current_cpu.list",
]
depfile = "${outputs[0]}.d"
script = "$zx/scripts/gen-ids-file"
utils = [ "readelf" ]
args = rebase_path(outputs + [ depfile ] + sources, root_build_dir)
}
generated_file("elf-$current_cpu.list") {
testonly = true
visibility = [ ":ids-$current_cpu" ]
outputs = [
"$root_build_dir/elf-$current_cpu.list",
]
deps = [
":$current_cpu($default_toolchain)",
":core-tests-$current_cpu($default_toolchain)",
":tools($default_toolchain)",
]
data_keys = [ "elf_link_output" ]
}
}