| # 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/compiled_action.gni") |
| import("//build/fidl/toolchain.gni") |
| import("//build/go/go_library.gni") |
| import("//build/go/toolchain.gni") |
| |
| # Generates some Go bindings for a FIDL library. |
| # |
| # The parameters for this template are defined in //build/fidl/fidl.gni. The |
| # relevant parameters in this template are: |
| # - name. |
| |
| template("fidl_go") { |
| assert(current_toolchain == go_toolchain, |
| "This template can only be used in $go_toolchain.") |
| |
| not_needed(invoker, [ "sources" ]) |
| |
| main_target_name = target_name |
| generation_target_name = "${target_name}_go_generate" |
| |
| library_name = target_name |
| if (defined(invoker.name)) { |
| library_name = invoker.name |
| } |
| |
| fidl_target_gen_dir = |
| get_label_info(":$target_name($fidl_toolchain)", "target_gen_dir") |
| library_dir = "$fidl_target_gen_dir/$target_name/$library_name.fidl" |
| impl_filename = "$library_dir/impl.go" |
| pkg_name_filename = "$library_dir/pkg_name" |
| json_representation = "$fidl_target_gen_dir/$target_name.fidl.json" |
| |
| compiled_action(generation_target_name) { |
| visibility = [ |
| ":*", |
| "//tools/fidl/fidlgen_go:*", |
| ] |
| |
| tool = "//tools/fidl/fidlgen_go" |
| |
| inputs = [ json_representation ] |
| |
| outputs = [ |
| impl_filename, |
| pkg_name_filename, |
| ] |
| |
| args = [ |
| "--json", |
| rebase_path(json_representation, root_build_dir), |
| "--output-impl", |
| rebase_path(impl_filename, root_build_dir), |
| "--output-pkg-name", |
| rebase_path(pkg_name_filename, root_build_dir), |
| ] |
| |
| deps = [ ":$main_target_name($fidl_toolchain)" ] |
| |
| forward_variables_from(invoker, [ "testonly" ]) |
| |
| metadata = { |
| generated_sources = rebase_path(outputs, root_build_dir) |
| } |
| } |
| |
| go_library(main_target_name) { |
| name_file = pkg_name_filename |
| |
| source_dir = library_dir |
| |
| sources = [ "impl.go" ] |
| |
| non_go_deps = [ ":$generation_target_name" ] |
| |
| deps = [] |
| if (defined(invoker.deps)) { |
| deps += invoker.deps |
| } |
| if (defined(invoker.public_deps)) { |
| deps += invoker.public_deps |
| } |
| |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| } |
| } |