blob: 560e83a30135cc65f47bfb628a9c877455e7d44b [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/rust/toolchain.gni")
# Generates some Rust 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_rust") {
assert(current_toolchain == rust_toolchain,
"This template can only be used in $rust_toolchain.")
not_needed(invoker, [ "sources" ])
main_target_name = target_name
generation_target_name = "${target_name}_rust_generate"
library_name = target_name
if (defined(invoker.name)) {
library_name = invoker.name
}
underscore_name = "fidl_" + string_replace(library_name, ".", "_")
fidl_target_gen_dir =
get_label_info(":bogus($fidl_toolchain)", "target_gen_dir")
filename = "$fidl_target_gen_dir/$underscore_name.rs"
json_representation = "$fidl_target_gen_dir/$target_name.fidl.json"
compiled_action(generation_target_name) {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ ":*" ]
tool = "//tools/fidl/fidlgen_rust"
inputs = [ json_representation ]
outputs = [ filename ]
args = [
"--json",
rebase_path(json_representation, root_build_dir),
"--output-filename",
rebase_path(filename, root_build_dir),
"--rustfmt",
rebase_path("//prebuilt/third_party/rust/$host_platform/bin/rustfmt"),
]
deps = [ ":$main_target_name($fidl_toolchain)" ]
}
group(main_target_name) {
forward_variables_from(invoker,
[
"public_deps",
"testonly",
"visibility",
])
deps = [ ":$generation_target_name" ]
if (defined(invoker.deps)) {
deps += invoker.deps
}
}
}