| # Copyright 2020 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/compiled_action.gni") |
| import("//build/fidl/toolchain.gni") |
| |
| # Declares a Measure Tape. |
| # |
| # This target generates an HLCPP measuring tape for one or multiple target types. |
| # |
| # Parameters |
| # |
| # target_bindings (required) |
| # The binding for which to create the measure tape. Both `hlcpp` and `rust` |
| # are supported. |
| # |
| # fidls (required) |
| # A list of GN depedencies. All those depedencies must be `fidl` targets. |
| # |
| # target_type (required) |
| # The fully qualified FIDL type for which to generate a measuring tape. |
| template("measure_tape") { |
| assert(defined(invoker.target_binding)) |
| assert(defined(invoker.fidls)) |
| assert(defined(invoker.target_type)) |
| |
| # targets |
| name = target_name |
| fidl_targets = invoker.fidls |
| gen_target_name = "${target_name}_gen" |
| |
| out_cc = "${target_gen_dir}/measure_tape/hlcpp/${target_name}.cc" |
| out_h = "${target_gen_dir}/measure_tape/hlcpp/${target_name}.h" |
| out_rs_root = "${target_gen_dir}/${target_name}/rust" |
| out_rs = "${out_rs_root}/src/lib.rs" |
| |
| # arguments for code generation tool |
| gen_args = [ |
| "--target-binding", |
| invoker.target_binding, |
| "--target-type", |
| invoker.target_type, |
| "--out-cc", |
| rebase_path(out_cc), |
| "--out-h", |
| rebase_path(out_h), |
| "--out-rs", |
| rebase_path(out_rs), |
| "--h-include-path", |
| "measure_tape/hlcpp/${target_name}.h", |
| ] |
| foreach(fidl, invoker.fidls) { |
| fidl_target = |
| get_label_info(fidl, "label_no_toolchain") + "($fidl_toolchain)" |
| json_file = get_label_info(fidl_target, "target_gen_dir") + "/" + |
| get_label_info(fidl_target, "name") + ".fidl.json" |
| gen_args += [ |
| "--json", |
| rebase_path(json_file, root_build_dir), |
| ] |
| } |
| |
| if (invoker.target_binding == "hlcpp") { |
| config_target_name = "${target_name}_config" |
| |
| # source set configuration to support `#include <...>` |
| config(config_target_name) { |
| include_dirs = [ target_gen_dir ] |
| } |
| |
| # source set consisting of the two generated files |
| source_set(name) { |
| forward_variables_from(invoker, |
| [ |
| "defines", |
| "testonly", |
| "visibility", |
| ]) |
| sources = [ |
| out_cc, |
| out_h, |
| ] |
| deps = [ ":$gen_target_name" ] |
| public_deps = fidl_targets |
| public_configs = [ ":$config_target_name" ] |
| } |
| |
| generated_outputs = [ |
| out_cc, |
| out_h, |
| ] |
| } else if (invoker.target_binding == "rust") { |
| import("//build/rust/rustc_library.gni") |
| |
| rustc_library(name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| deps = [ |
| "//src/lib/fidl/rust/fidl", |
| "//src/lib/zircon/rust:fuchsia-zircon", |
| ] |
| foreach(fidl_target, fidl_targets) { |
| label = get_label_info(fidl_target, "label_no_toolchain") |
| deps += [ "${label}-rustc" ] |
| } |
| non_rust_deps = [ ":$gen_target_name" ] |
| source_root = rebase_path(out_rs) |
| sources = [ rebase_path(out_rs) ] |
| } |
| |
| generated_outputs = [ out_rs ] |
| } |
| |
| # code generation |
| compiled_action(gen_target_name) { |
| tool = "//tools/fidl/measure-tape/src:measure-tape" |
| |
| args = gen_args |
| outputs = generated_outputs |
| deps = fidl_targets |
| forward_variables_from(invoker, [ "testonly" ]) |
| } |
| } |