blob: 7a9ea8451cd02c7ac1b5d5c048645d45b1582d53 [file] [log] [blame]
# 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 Go bindings for a FIDL library.
#
# Parameters (see //build/fidl/fidl.gni for descriptions):
#
# name
# public_deps
# testonly
# visibility
#
template("fidl_go") {
assert(current_toolchain == go_toolchain,
"This template can only be used in the Go toolchain $go_toolchain.")
not_needed(invoker, [ "sdk_category" ])
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(":bogus($fidl_toolchain)", "target_gen_dir")
json_representation = "$fidl_target_gen_dir/$target_name.fidl.json"
json_representation_target = ":${target_name}($fidl_toolchain)"
library_dir = "$fidl_target_gen_dir/$target_name/$library_name.fidl"
impl_filename = "$library_dir/impl.go"
pkg_name_filename = "$library_dir/pkg_name"
compiled_action(generation_target_name) {
forward_variables_from(invoker, [ "testonly" ])
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 = [ json_representation_target ]
metadata = {
generated_sources = rebase_path(outputs, root_build_dir)
}
}
go_library(target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
name_file = pkg_name_filename
source_dir = library_dir
sources = [ "impl.go" ]
non_go_deps = [ ":$generation_target_name" ]
if (defined(invoker.public_deps)) {
deps = invoker.public_deps
}
}
}