| # 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/images/args.gni") | |
| import("//build/testing/platforms.gni") | |
| import("//build/toolchain/ccache.gni") | |
| import("//build/toolchain/goma.gni") | |
| import("//zircon/public/gn/build_api_module.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 = [] | |
| # A file in integration containing historical test duration data for this | |
| # build configuration. This file is used by infra to efficiently schedule | |
| # tests. "default.json" is a dummy file that contains no real duration data, | |
| # and causes infra to schedule tests as if each one has the same duration. | |
| test_durations_file = "//integration/infra/test_durations/default.json" | |
| # 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 | |
| # netsvc build. | |
| 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 = "" | |
| # Compilation 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", | |
| "//:legacy_host_targets-$host_os-$host_cpu", | |
| "//:legacy_unification-$target_cpu", | |
| "//tools:all-hosts", | |
| ] + zircon_extra_deps | |
| enable_netsvc_debugging_features = zircon_enable_netsvc_debugging_features | |
| forward_variables_from(zircon_extra_args, "*") | |
| } | |
| } | |
| ### | |
| ### Zircon build integration. | |
| ### | |
| # The Zircon GN is completely a puppet of this build. This gen runs that gen. | |
| # See also :zircon below. | |
| 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", | |
| "//build/unification/zircon_library_forward.gn", | |
| "//build/unification/zircon_library_mappings.json", | |
| "//build/zircon/lib_template.gn", | |
| "//build/zircon/tool_template.gn", | |
| ]) | |
| } | |
| ### | |
| ### 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_BOARD_NAME=${board_name}", | |
| "FUCHSIA_ZBI_COMPRESSION=$zbi_compression", | |
| "HOST_OUT_DIR='${_host_out_dir}'", | |
| ] | |
| write_file("$root_build_dir/fx.config", _fx_config_lines) | |
| ### | |
| ### 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 = [ | |
| ":binaries", | |
| ":fuzzers", | |
| ":images", | |
| ":platforms", | |
| ":prebuilt_packages", | |
| ":tests", | |
| ":tool_paths", | |
| ":zbi_tests", | |
| ":zircon", | |
| ] | |
| } | |
| # This describes where to find all prebuilt packages and optionally where to | |
| # find the debug information for those packages. | |
| # | |
| # If debug information is present then `binaries` will point to another json | |
| # file which is almost a subset of the format seen at //zircon:binaries except | |
| # that `elf_build_id` is not a file pointer but instead the actual build ID. | |
| # This binary only has the `cpu`, `debug`, `os` and modified `elf_build_id` | |
| # fields. All fields but `elf_build_id` have the same meaning as in | |
| # //zircon:binaries except for `elf_build_id` which has the discussed meaning. | |
| # | |
| # The actual prebuilt_packages api module has the following schema: | |
| # | |
| # Type: list(scope) | |
| # | |
| # archive | |
| # Required: The path to the prebuilt fuchsia package. This is always a | |
| # far file. | |
| # | |
| # binaries | |
| # Optional: The path to the json file which has the format described | |
| # above. | |
| # | |
| # debug_archive | |
| # Optional: The path the the archive of debug binaries from which | |
| # `binaries` was generated. | |
| build_api_module("prebuilt_packages") { | |
| testonly = true | |
| data_keys = [ "prebuilt_packages" ] | |
| deps = [ | |
| "//build/images:packages", | |
| "//sdk", | |
| ] | |
| } | |
| # See //zircon:binaries for a description and schema definition. | |
| # | |
| build_api_module("binaries") { | |
| testonly = true | |
| data_keys = [ "binaries" ] | |
| deps = [ | |
| ":binaries.zircon", | |
| "//build/images:packages", | |
| "//sdk", | |
| ] | |
| } | |
| group("binaries.zircon") { | |
| visibility = [ ":binaries" ] | |
| metadata = { | |
| # This uses exec_script instead of read_file because the labels and paths | |
| # need to be rebased to be valid in the Fuchsia build. Doing this in GN | |
| # using a foreach loop takes 3 seconds, but the script takes 100ms. This | |
| # should go away when the build is unified. | |
| binaries = | |
| exec_script("//build/zircon/read_zircon_binaries.py", | |
| [ | |
| "--binaries-json", | |
| rebase_path("$zircon_root_build_dir/binaries.json"), | |
| "--root-build-dir", | |
| rebase_path(root_build_dir), | |
| "--zircon-root-build-dir", | |
| rebase_path(zircon_root_build_dir), | |
| ], | |
| "json") | |
| } | |
| } | |
| # Describes the "fuzzers" in the build. | |
| # | |
| # See //build/fuzzing/fuzzer.gni for more details. | |
| # | |
| # | |
| # Type: list(scope) | |
| # | |
| # fuzzers_package | |
| # Required: Name of a package containing fuzzers. | |
| # Type: string | |
| # | |
| # fuzzers | |
| # Required: The fuzzer binaries included in the associated package. | |
| # Type: list of labels | |
| # | |
| # fuzz_host | |
| # Required: Indicates whether the associated fuzzer binaries were built for | |
| # the host. | |
| # Type: boolean | |
| # | |
| build_api_module("fuzzers") { | |
| testonly = true | |
| data_keys = [ "fuzz_spec" ] | |
| deps = [ "//build/images:packages" ] | |
| } | |
| # This describes all the "image" files the build can produce. | |
| # | |
| # See //zircon:images for a description and partial schema definition. Fields | |
| # additionally found in this build API module include | |
| # | |
| # bootserver_pave, bootserver_pave_zedboot, bootserver_netboot | |
| # Optional: flag names under which the associated image should be passed to | |
| # the bootserver when paving, paving zedboot, or netbooting, respectively. | |
| # Type: list(string) | |
| # | |
| build_api_module("images") { | |
| testonly = true | |
| data_keys = [ "images" ] | |
| deps = [ | |
| # XXX(46415): as the build is specialized by board (bootfs_only) | |
| # for bringup, it is not possible for this to be complete. As this | |
| # is used in the formation of the build API with infrastructure, | |
| # and infrastructure assumes that the board configuration modulates | |
| # the definition of `zircon-a` between bringup/non-bringup, we can | |
| # not in fact have a complete description. See the associated | |
| # conditional at this group also. | |
| "build/images", | |
| # TODO(fxbug.dev/9708): have this target roll up to a build API module of | |
| # archives. | |
| "build/images:archives", | |
| ] | |
| } | |
| # Describes the platforms available for testing. | |
| # | |
| # TODO(fxbug.dev/10429): the fuchsia platform should not know about such things. | |
| # | |
| # Type: list(scope) | |
| # | |
| build_api_module("platforms") { | |
| testonly = true | |
| contents = [] | |
| foreach(platform, test_platforms) { | |
| if (!defined(platform.cpu) || platform.cpu == current_cpu) { | |
| contents += [ platform ] | |
| } | |
| } | |
| } | |
| # See //zircon:tests for a description and schema definition. | |
| # | |
| build_api_module("tests") { | |
| testonly = true | |
| data_keys = [ "tests" ] | |
| deps = [ | |
| "//build:tests", | |
| "//build/images:packages", | |
| "//sdk", | |
| ] | |
| } | |
| # test_durations.json contains historical test durations data to be used for | |
| # scheduling tests. | |
| # | |
| # It contains a list of JSON objects with the following fields: | |
| # | |
| # name | |
| # Required: The name of the test. For Fuchsia tests, this will correspond to | |
| # the test package URL; for host-side tests, the installation path. | |
| # Type: string | |
| # | |
| # median_duration_ms | |
| # Required: The median historical duration for this test over some period of | |
| # time, in milliseconds. | |
| # Type: int | |
| # | |
| build_api_module("test_durations") { | |
| testonly = true | |
| contents = read_file(test_durations_file, "json") | |
| } | |
| # See //zircon:tool_paths for a description and schema definition. | |
| # | |
| build_api_module("tool_paths") { | |
| testonly = true | |
| data_keys = [ "tool_paths" ] | |
| walk_keys = [ "tool_barrier" ] | |
| deps = [ | |
| ":tool_paths.metadata", | |
| ":tool_paths.zircon", | |
| "//build/images:packages", | |
| "//build/unification/tools", | |
| ] | |
| } | |
| group("tool_paths.metadata") { | |
| visibility = [ ":tool_paths" ] | |
| prebuilt_tools = [ | |
| "//prebuilt/sdk/bazel/bazel", | |
| "//prebuilt/third_party/rust/$host_platform/bin/cargo", | |
| "//prebuilt/third_party/rust/$host_platform/bin/rustc", | |
| "//prebuilt/third_party/rust/$host_platform/bin/rustdoc", | |
| "//prebuilt/third_party/rust/$host_platform/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/go/$host_platform/bin/go", | |
| "//prebuilt/third_party/go/$host_platform/bin/gofmt", | |
| "//prebuilt/third_party/dart/$host_platform/bin/dartfmt", | |
| "//prebuilt/third_party/yapf/yapf", | |
| "//prebuilt/third_party/dart/$host_platform/bin/dart", | |
| ] | |
| 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) | |
| }, | |
| ] | |
| } | |
| } | |
| } | |
| 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) | |
| label = string_replace(label, "//", "//zircon/") | |
| }, | |
| ] | |
| } | |
| } | |
| } | |
| # This describes all the "ZBI tests" the build can produce. | |
| # | |
| # See //zircon:zbi_tests for a description and a schema definition. | |
| # | |
| build_api_module("zbi_tests") { | |
| testonly = true | |
| data_keys = [ "zbi_tests" ] | |
| deps = [ | |
| ":zbi_tests.zircon", | |
| "build/images", | |
| ] | |
| } | |
| group("zbi_tests.zircon") { | |
| visibility = [ ":zbi_tests" ] | |
| zircon_entries = read_file("$zircon_root_build_dir/zbi_tests.json", "json") | |
| metadata = { | |
| zbi_tests = [] | |
| foreach(zbi_test, zircon_entries) { | |
| zbi_tests += [ | |
| { | |
| forward_variables_from(zbi_test, "*") | |
| path = rebase_path(path, root_build_dir, zircon_root_build_dir) | |
| label = string_replace(label, "//", "//zircon/") | |
| }, | |
| ] | |
| } | |
| } | |
| } | |
| # Describes how to invoke Njnja for the Zircon build. | |
| # | |
| # These instructions are a prerequisite for this build. | |
| # | |
| # Type: scope | |
| # | |
| # dir | |
| # Required: the zircon build directory root. | |
| # Type: path relative to $root_build_dir | |
| # | |
| # targets | |
| # Required: the ninja targets to execute. | |
| # Type: list of ninja targets | |
| # | |
| build_api_module("zircon") { | |
| testonly = true | |
| contents = { | |
| dir = rebase_path(zircon_root_build_dir, root_build_dir) | |
| targets = [ "default" ] | |
| } | |
| } | |
| ### | |
| ### Top-level targets. | |
| ### | |
| group("default") { | |
| testonly = true | |
| deps = [ | |
| "//build:tests", | |
| "//build/images:packages", | |
| "//build/unification", | |
| "//sdk", | |
| ] | |
| # SDK-only builds must not attempt to build images. | |
| if (bootfs_only || base_package_labels + cache_package_labels + | |
| universe_package_labels != []) { | |
| deps += [ "//build/images:default-images" ] | |
| } | |
| } | |
| # 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 | |
| testonly = true | |
| visibility = [ "//build/images:universe_packages" ] | |
| public_deps = universe_package_labels | |
| } | |
| group("recovery_image") { | |
| # TODO(fxbug.dev/37792): Investigate use of testonly here. | |
| testonly = true | |
| deps = [ "build/images/recovery" ] | |
| } | |
| group("breakpad_symbols") { | |
| testonly = true | |
| public_deps = [ "//build/gn:breakpad_symbols" ] | |
| } | |
| group("package_archive") { | |
| testonly = true | |
| public_deps = [ "//build/gn:package_archive" ] | |
| } |