| # 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/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 |
| |
| # Defines the `//:default` target: what `ninja` with no arguments does. |
| default_deps = [ |
| ":ids", |
| ":images", |
| ":tools", |
| ] |
| |
| # Whether to include various features (non-shipping, insecure, etc.) in the |
| # kernel build. |
| enable_kernel_debugging_features = false |
| } |
| |
| # 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. |
| |
| legacy_deps = [ |
| ":legacy-host_tests", |
| ":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", |
| |
| # Separately listed because they're not reached by any dependencies. |
| "$zx/system/fidl/fuchsia-debugdata", |
| "$zx/system/fidl/fuchsia-inspect", |
| "$zx/system/fidl/fuchsia-tracelink", |
| ] |
| legacy_cpu_deps = [ |
| ":ids", |
| ":legacy-deps", |
| ":legacy-fdio", |
| ":legacy-tests", |
| ":all-ulib", |
| ] |
| |
| build_api_module("legacy_dirs") { |
| testonly = true |
| data_keys = [ "legacy_dirs" ] |
| deps = legacy_deps |
| foreach(cpu, standard_fuchsia_cpus) { |
| foreach(dep, legacy_cpu_deps) { |
| deps += [ "$dep-$cpu" ] |
| } |
| } |
| } |
| |
| foreach(cpu, standard_fuchsia_cpus) { |
| build_api_module("legacy-$cpu") { |
| testonly = true |
| data_keys = [ "legacy_targets" ] |
| walk_keys = [ "legacy_barrier" ] |
| deps = legacy_deps + [ ":legacy-image-$cpu" ] |
| foreach(dep, legacy_cpu_deps) { |
| deps += [ "$dep-$cpu" ] |
| } |
| } |
| |
| build_api_module("legacy_sysroot-$cpu") { |
| testonly = true |
| data_keys = [ "legacy_sysroot" ] |
| walk_keys = [ "legacy_barrier" ] |
| deps = legacy_deps |
| foreach(dep, legacy_cpu_deps) { |
| deps += [ "$dep-$cpu" ] |
| } |
| } |
| |
| environment_redirect("all-ulib-$cpu") { |
| testonly = true |
| cpu = cpu |
| environment_label = "$zx/public/gn/toolchain:user" |
| deps = [ |
| "$zx/system/ulib", |
| ] |
| } |
| |
| # This lists just the one file to link against to get fdio. |
| build_api_module("legacy-fdio-$cpu") { |
| data_keys = [ "link_output" ] |
| walk_keys = [ "link_barrier" ] |
| deps = [ |
| ":legacy-fdio-redirect-$cpu", |
| ] |
| } |
| } |
| } |
| |
| group("default") { |
| testonly = true |
| deps = default_deps |
| } |
| |
| 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_input("legacy-image-$cpu") { |
| output_dir = root_build_dir |
| testonly = true |
| cpu = cpu |
| deps = [ |
| ":asan-manifest-$cpu", |
| ":legacy-deps-$cpu", |
| ] |
| metadata = { |
| # legacy-$cpu depends on this to get all these deps built. |
| # But they shouldn't contribute metadata to the build_api_module(). |
| legacy_barrier = [] |
| } |
| } |
| |
| 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). |
| zbi_input("asan-manifest-$cpu") { |
| testonly = true |
| deps = [ |
| ":asan-libs-$cpu", |
| ] |
| metadata = { |
| # //build/images/manifest.gni finds this by name and cpu. |
| images = [ |
| { |
| cpu = cpu |
| type = "manifest" |
| name = "asan-libs" |
| path = rebase_path("$target_gen_dir/$target_name.manifest", |
| root_build_dir) |
| }, |
| ] |
| |
| # 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("asan-libs-$cpu") { |
| testonly = true |
| cpu = cpu |
| environment_label = "$zx/public/gn/toolchain:user" |
| variant = "asan" |
| deps = [ |
| "$zx/system/core/devmgr:driver_deps.asan", |
| "$zx/system/ulib", |
| ] |
| } |
| |
| 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/system/ulib", |
| "$zx/third_party/uapp", |
| ] |
| } |
| |
| environment_redirect("legacy-fdio-redirect-$cpu") { |
| visibility = [ ":legacy-fdio-$cpu" ] |
| environment_label = "$zx/public/gn/toolchain:user" |
| cpu = cpu |
| shlib = true |
| deps = [ |
| "$zx/system/ulib/fdio", |
| ] |
| } |
| |
| 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 = [ |
| "$zx/bootloader", |
| "$zx/kernel", |
| "$zx/system/core", |
| "$zx/system/dev", |
| "$zx/system/uapp", |
| "$zx/third_party/uapp", |
| ] |
| 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. |
| build_api_module("legacy_images") { |
| testonly = true |
| data_keys = [ "images" ] |
| deps = [ |
| ":tools", |
| ] |
| foreach(cpu, standard_fuchsia_cpus) { |
| deps += [ |
| ":asan-manifest-$cpu", |
| ":legacy-$cpu", |
| ":legacy-image-$cpu", |
| ] |
| } |
| } |
| |
| # 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 = [ |
| ":default", |
| ] |
| data_keys = [ "generated_sources" ] |
| } |
| |
| # 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" ] |
| } |
| } |