blob: 581443df742e4a9a09394343612c9f5b5ee15d13 [file] [log] [blame]
# Copyright 2018 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/config/clang/clang.gni")
import("//build/toolchain/goma.gni")
_zircon_variants = []
foreach(selector, select_variant) {
if (selector == "$selector") {
_zircon_variants += [ selector ]
}
}
declare_args() {
# [Zircon GN build arguments](../../../zircon/docs/gen/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`](../../../zircon/docs/gen/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 = {
}
# 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
}
declare_args() {
# [Zircon GN build arguments](../../../zircon/docs/gen/build_arguments.md).
# The default passes through GOMA 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_goma = use_goma
goma_dir = goma_dir
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 = clang_prefix
}
variants = _zircon_variants
default_deps = [ ":legacy-$target_cpu" ]
enable_kernel_debugging_features = zircon_enable_kernel_debugging_features
enable_netsvc_debugging_features = zircon_enable_netsvc_debugging_features
forward_variables_from(zircon_extra_args, "*")
}
}
# This is $root_build_dir in the Zircon GN build.
# **NOTE!** This is not a subdirectory of $root_build_dir because that
# makes GN insist that it understand where all files in there come from.
# We instead require that users (or `fx build`) run ninja in
# $zircon_root_build_dir before running ninja in $root_build_dir.
zircon_root_build_dir = "${root_build_dir}.zircon"
# 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.
exec_script(
"//buildtools/gn",
[
"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_args = { ... } to replace the defaults above.$0x0a" +
"forward_variables_from($zircon_args, \"*\")",
"--export-compile-commands=default",
rebase_path(zircon_root_build_dir, root_build_dir),
])
exec_script("//build/zircon/populate_zircon_public.py",
[ rebase_path("$zircon_root_build_dir/legacy_dirs.json") ],
"",
[ "$zircon_root_build_dir/legacy_dirs.json" ])
}
# The top-level `tools` Ninja target in Zircon puts the tool binaries here.
zircon_tools_dir = "$zircon_root_build_dir/tools"
# The `gn gen` stage of the Zircon GN build writes these files.
# See //build/zircon/template.gn for how they're used.
zircon_legacy_targets =
read_file("$zircon_root_build_dir/legacy_targets-$target_cpu.json", "json")
# See //zircon/public/sysroot/BUILD.gn and //build/config/fuchsia/BUILD.gn.
zircon_legacy_sysroot =
read_file("$zircon_root_build_dir/legacy_sysroot-$target_cpu.json", "json")
# The `gn gen` stage of the Zircon GN build writes this file.
# It's a list of {name=... path=... type=...} scopes.
zircon_images = read_file("$zircon_root_build_dir/legacy_images.json", "json")
foreach(image, zircon_images) {
if (image.name == "kernel" && image.type == "zbi" &&
image.cpu == target_cpu) {
zircon_kernel_zbi = "$zircon_root_build_dir/${image.path}"
}
}
# Template for running a Zircon host tool as part of the build.
# This is a thin wrapper to define an `action()` target.
#
# Parameters
#
# tool (required)
# [string] The name of the tool, like "mkbootfs".
#
# args (required)
# [list of strings] The arguments to pass the tool.
# The tool runs with `root_build_dir` as its current directory,
# so any file names should be made either absolute or relative
# to `root_build_dir` using `rebase_path()`.
#
# All other parameters are exactly as for `action()`, except
# that `script` is replaced with `tool`.
#
template("zircon_tool_action") {
assert(defined(invoker.tool), "zircon_tool_action() requires `tool`")
assert(defined(invoker.args), "zircon_tool_action() requires `args`")
_tool = "$zircon_tools_dir/${invoker.tool}"
action(target_name) {
inputs = []
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
forward_variables_from(invoker,
"*",
[
"args",
"script",
"tool",
"testonly",
"visibility",
])
script = "//build/gn_run_binary.sh"
inputs += [ _tool ]
args = [
clang_prefix,
rebase_path(_tool, root_build_dir),
] + invoker.args
}
}
# Produce a manifest of binaries from the Zircon build.
#
# This is meant to be used with a package() target that does:
# deps = [ this_target ]
# extras = get_target_outputs(this_target)
#
# Parameters
#
# manifest
# - Required: Which Zircon manifest to draw from.
# - Type: "image" or "tests"
#
# patterns
# - Required: List of filename patterns to match in the manifest.
# These are shell filename patterns that match the whole target path
# with no leading slash: "bin/foo" or "bin/*" or "*" all match "bin/foo".
# - Type: list(string)
#
template("zircon_extras_manifest") {
action(target_name) {
forward_variables_from(invoker,
[
"visibility",
"testonly",
])
foreach(image, zircon_images) {
if (image.type == "manifest" &&
image.name == "legacy-${invoker.manifest}-$target_cpu") {
sources = [
"$zircon_root_build_dir/${image.path}",
]
}
}
outputs = [
"$target_gen_dir/$target_name.manifest",
]
script = "//build/images/manifest.py"
args = [ "--output=" + rebase_path(outputs[0], root_build_dir) ]
foreach(pattern, invoker.patterns) {
args += [ "--include=$pattern" ]
}
foreach(manifest, sources) {
args += [
"--cwd=" + rebase_path(get_path_info(manifest, "dir"), root_build_dir),
"--manifest=" + rebase_path(manifest, root_build_dir),
]
}
}
}