| # Copyright 2020 The Fuchsia Authors | |
| # | |
| # Use of this source code is governed by a MIT-style | |
| # license that can be found in the LICENSE file or at | |
| # https://opensource.org/licenses/MIT | |
| import("//build/zircon/c_utils.gni") | |
| import("//build/zircon/migrated_targets.gni") | |
| _is_phys = toolchain_environment == "kernel.phys" | |
| phys_toolchain = "//zircon/kernel/phys:kernel.phys_$current_cpu" | |
| # Build an executable for the phys environment. | |
| # | |
| # This defines one public target whose output is the raw binary image. | |
| # The target is used like executable(), but deps on this target from | |
| # other environments transparently redirect to the phys environment, and | |
| # a custom linker script is always required. There are also implicit | |
| # deps to supply the phys entry point code that calls the C++ PhysMain | |
| # via the "main.h" API. | |
| # | |
| # Parameters | |
| # | |
| # * output_extension | |
| # - Optional: See executable(), but defaults to "bin". | |
| # - Type: string | |
| # - Default: "bin" | |
| # | |
| # * images_metadata | |
| # - Optional: This can override keys in the `images` metadata entry. | |
| # - Type: scope | |
| # - Default: {} | |
| # | |
| # * release_output | |
| # - Optional: Whether to release this artifact, it will appear in the build | |
| # api 'exported_files' if set to true | |
| # - Type: boolean | |
| # - Default: false | |
| # | |
| # * emulator_support_aib | |
| # - Optional: If true, will generate an `emulator_support_aib_input` metadata entry and barrier | |
| # making this image findable as a QEMU Kernel by `assembled_system`. | |
| # - Type: boolean | |
| # - Default: false | |
| # | |
| # See executable() for other parameters. | |
| # | |
| template("phys_executable") { | |
| if (!_is_phys) { | |
| group(target_name) { | |
| forward_variables_from(invoker, | |
| [ | |
| "testonly", | |
| "visibility", | |
| ]) | |
| public_deps = [ ":$target_name($phys_toolchain)" ] | |
| } | |
| not_needed(invoker, "*") | |
| } else { | |
| image_target = target_name | |
| executable_target = "_phys_executable.$target_name.executable" | |
| # This is the actual linking target. It creates an ELF file that acts | |
| # as the debug file but is not used at runtime. | |
| executable(executable_target) { | |
| visibility = [ ":*" ] | |
| deps = [] | |
| inputs = [] | |
| ldflags = [] | |
| forward_variables_from(invoker, | |
| "*", | |
| [ | |
| "images_metadata", | |
| "metadata", | |
| "output_dir", | |
| "output_extension", | |
| "target_name", | |
| "visibility", | |
| "release_output", | |
| "emulator_support_aib", | |
| ]) | |
| deps += [ "//zircon/kernel/phys:phys_executable.deps" ] | |
| inputs += [ "//zircon/kernel/phys/phys.ld" ] | |
| ldflags += [ "-Wl,-T," + rebase_path(inputs[0], root_build_dir) ] | |
| } | |
| # This is the main target of the template, a raw binary load image file. | |
| image_binary(image_target) { | |
| forward_variables_from(invoker, | |
| [ | |
| "output_dir", | |
| "output_extension", | |
| "output_name", | |
| "testonly", | |
| "visibility", | |
| "release_output", | |
| ]) | |
| if (defined(visibility)) { | |
| # Make sure it's visible to the environment_redirect() target above. | |
| visibility += [ ":$image_target" ] | |
| } | |
| deps = [ ":$executable_target" ] | |
| if (!defined(output_dir)) { | |
| output_dir = root_out_dir | |
| } | |
| if (!defined(output_name)) { | |
| output_name = target_name | |
| } | |
| if (!defined(output_extension)) { | |
| output_extension = "bin" | |
| } | |
| output_path = "$output_dir/$output_name.$output_extension" | |
| rebased_output_path = rebase_path(output_path, root_build_dir) | |
| metadata = { | |
| images = [] | |
| if (defined(invoker.metadata)) { | |
| forward_variables_from(invoker.metadata, "*") | |
| } | |
| # For the //:images build_api_module(). | |
| images += [ | |
| { | |
| name = target_name | |
| label = get_label_info(":$target_name", "label_with_toolchain") | |
| cpu = current_cpu | |
| # Botanist needs this exact value for images used as QEMU kernels. | |
| type = "kernel" | |
| # The caller can override those values and/or add others. | |
| if (defined(invoker.images_metadata)) { | |
| forward_variables_from(invoker.images_metadata, "*") | |
| } | |
| # The caller can't override `path` since that would | |
| # not refer to this target's output any more. | |
| path = rebased_output_path | |
| }, | |
| ] | |
| if (defined(release_output) && release_output) { | |
| exported_files = [ | |
| { | |
| name = target_name | |
| path = rebased_output_path | |
| }, | |
| ] | |
| } | |
| if (defined(invoker.emulator_support_aib) && | |
| invoker.emulator_support_aib) { | |
| emulator_support_aib_input_barrier = [] | |
| emulator_support_aib_input = [ | |
| { | |
| label = get_label_info(":$target_name", "label_with_toolchain") | |
| path = rebased_output_path | |
| }, | |
| ] | |
| } | |
| } | |
| } | |
| } | |
| } | |
| if (_is_phys) { | |
| set_defaults("phys_executable") { | |
| configs = default_executable_configs | |
| } | |
| } |