| # Copyright 2022 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/bind/bind.gni") |
| |
| # Generates a driver bind library 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 |
| # - Optional: Usual GN meanings. |
| # |
| template("fidl_bind_library") { |
| assert(defined(invoker.library_name), |
| "fidl_bind_library(\"$target_name\") must define `library_name`") |
| assert(defined(invoker.fidl_gen_dir), |
| "fidl_bind_library(\"$target_name\") must define `fidl_gen_dir`") |
| assert(defined(invoker.fidl_ir_json), |
| "fidl_bind_library(\"$target_name\") must define `fidl_ir_json`") |
| assert(defined(invoker.fidl_ir_target), |
| "fidl_bind_library(\"$target_name\") must define `fidl_ir_target`") |
| |
| generation_target = "${target_name}_generate" |
| |
| forward_variables_from(invoker, |
| [ |
| "fidl_gen_dir", |
| "library_name", |
| ]) |
| bind_library_file_name = "${library_name}.bind" |
| generated_bind_library = "$fidl_gen_dir/$bind_library_file_name" |
| |
| if (current_toolchain == fidl_toolchain) { |
| compiled_action(generation_target) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "fidl_ir_json", |
| "fidl_ir_target", |
| ]) |
| visibility = [ ":*" ] |
| |
| tool = "//tools/bindc:bin" |
| tool_output_name = "bindc" |
| |
| inputs = [ fidl_ir_json ] |
| |
| outputs = [ generated_bind_library ] |
| |
| deps = [ fidl_ir_target ] |
| |
| args = [ |
| "generate-bind", |
| "--output", |
| rebase_path("${generated_bind_library}", root_build_dir), |
| rebase_path(fidl_ir_json, root_build_dir), |
| ] |
| |
| metadata = { |
| generated_sources = rebase_path(outputs, root_build_dir) |
| } |
| } |
| not_needed(invoker, [ "visibility" ]) |
| } else { |
| not_needed(invoker, |
| [ |
| "fidl_ir_json", |
| "fidl_ir_target", |
| ]) |
| |
| bind_library(target_name) { |
| forward_variables_from(invoker, |
| [ |
| "testonly", |
| "visibility", |
| ]) |
| |
| source_dep = ":$generation_target($fidl_toolchain)" |
| source = generated_bind_library |
| name = library_name |
| } |
| } |
| } |