| # Copyright 2026 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/rust/rustc_bindgen.gni") | |
| import("kernel_rust_crate.gni") | |
| # Defines a kernel_rust_crate() comprised of bindgen outputs. | |
| # | |
| # Parameters | |
| # | |
| # * crate_name, configs, public_configs, rustflags, deps, public_deps, data_deps | |
| # - Optional: See rustc_library(). | |
| # | |
| # * sources, source_root, inputs | |
| # - Disallowed: These are set to the bindgen outputs. | |
| # | |
| # * non_rust_deps | |
| # - Optional: Dependencies of the rustc_bindgen() subtarget. | |
| # - Type: list(label) | |
| # | |
| # * output_name | |
| # - Disallowed: As a would-be rustc_bindgen() parameter, this is set by the | |
| # template. | |
| # | |
| # See rustc_bindgen() for other parameters. | |
| template("kernel_bindgen_crate") { | |
| main_target = target_name | |
| bindgen_target = "_kernel_bindgen_crate.${target_name}.bindgen" | |
| rustc_bindgen(bindgen_target) { | |
| forward_variables_from(invoker, | |
| "*", | |
| [ | |
| "visibility", | |
| "crate_name", | |
| "output_name", | |
| "edition", | |
| "deps", | |
| "public_deps", | |
| "data_deps", | |
| "non_rust_deps", | |
| "public_deps", | |
| "public_configs", | |
| "configs", | |
| "rustflags", | |
| ]) | |
| visibility = [ ":*" ] | |
| output_name = string_replace("${main_target}.rs", "-", "_") | |
| if (defined(invoker.non_rust_deps)) { | |
| deps = invoker.non_rust_deps | |
| } | |
| } | |
| kernel_rust_crate(main_target) { | |
| forward_variables_from(invoker, | |
| [ | |
| "testonly", | |
| "visibility", | |
| "crate_name", | |
| "deps", | |
| "public_deps", | |
| "data_deps", | |
| "configs", | |
| "public_configs", | |
| "rustflags", | |
| ]) | |
| sources = get_target_outputs(":$bindgen_target") | |
| source_root = sources[0] | |
| if (!defined(deps)) { | |
| deps = [] | |
| } | |
| deps += [ ":${bindgen_target}" ] | |
| } | |
| } |