blob: 8480a760ca361a7458241c4e31e176b1659c4fd9 [file] [log] [blame] [edit]
# 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
#
# * library_name
# - Required: The name of the FIDL library.
# - Type: string
#
# * fidl_gen_dir
# - Required: The directory under which bindings should be generated.
# - Type: path
#
# * fidl_ir_json
# - Required: The path to the associated FIDL IR JSON file.
# - Type: path
#
# * fidl_ir_target
# - Required: The label of the target that generates the FIDL IR JSON file.
# - Type: label
#
# * testonly, visibility, public_deps
# - Optional: Usual GN meanings.
#
template("fidl_go") {
assert(current_toolchain == go_toolchain,
"This template can only be used in the Go toolchain $go_toolchain.")
assert(defined(invoker.library_name),
"fidl_go(\"$target_name\") must define `library_name`")
assert(defined(invoker.fidl_gen_dir),
"fidl_go(\"$target_name\") must define `fidl_gen_dir`")
assert(defined(invoker.fidl_ir_json),
"fidl_go(\"$target_name\") must define `fidl_ir_json`")
assert(defined(invoker.fidl_ir_target),
"fidl_go(\"$target_name\") must define `fidl_ir_target`")
main_target = target_name
generation_target = "${target_name}_generate"
forward_variables_from(invoker,
[
"fidl_gen_dir",
"library_name",
])
library_dir = "$fidl_gen_dir/$library_name.fidl"
impl_filename = "$library_dir/impl.go"
pkg_name_filename = "$library_dir/pkg_name"
compiled_action(generation_target) {
forward_variables_from(invoker,
[
"testonly",
"fidl_ir_target",
"fidl_ir_json",
])
visibility = [
":*",
"//tools/fidl/fidlgen_go:*",
]
tool = "//tools/fidl/fidlgen_go"
inputs = [ fidl_ir_json ]
outputs = [
impl_filename,
pkg_name_filename,
]
args = [
"--json",
rebase_path(fidl_ir_json, root_build_dir),
"--output-impl",
rebase_path(impl_filename, root_build_dir),
"--output-pkg-name",
rebase_path(pkg_name_filename, root_build_dir),
"--output-root-for-ide",
rebase_path("$root_gen_dir/fidl_for_ide", root_build_dir),
]
deps = [ fidl_ir_target ]
metadata = {
generated_sources = rebase_path(outputs, root_build_dir)
}
}
go_library(main_target) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
name_file = pkg_name_filename
source_dir = library_dir
sources = [ "impl.go" ]
non_go_deps = [ ":$generation_target" ]
if (defined(invoker.public_deps)) {
deps = []
foreach(dep, invoker.public_deps) {
deps += [ get_label_info(dep, "label_no_toolchain") + "_go" ]
}
}
}
}