1# Copyright 2024 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14import("//build_overrides/pigweed.gni") 15import("//build_overrides/pigweed_environment.gni") 16import("$dir_pw_build/exec.gni") 17 18_bindgen_exe_path = 19 rebase_path(pw_env_setup_CIPD_PIGWEED + "/rust_bindgen/bindgen") 20 21# Bindgen is not part of GN tools, so use pw_exec to run it. 22template("rust_bindgen_action") { 23 pw_exec(target_name) { 24 forward_variables_from(invoker, 25 [ 26 "cflags", 27 "cflags_c", 28 "configs", 29 "defines", 30 "deps", 31 "public_configs", 32 "public_deps", 33 "visibility", 34 ]) 35 not_needed(invoker, "*") 36 37 output_gen_rs = "$target_gen_dir/${target_name}.rs" 38 39 program = _bindgen_exe_path 40 header = rebase_path(invoker.header, root_build_dir) 41 42 outputs = [ output_gen_rs ] 43 depfile = "$target_out_dir/${target_name}.d" 44 args = [ 45 "--depfile", 46 rebase_path(depfile, root_build_dir), 47 "--output", 48 rebase_path(output_gen_rs, root_build_dir), 49 ] 50 51 args += [ 52 # Do not search for system default include paths. 53 "--no-include-path-detection", 54 ] 55 if (defined(invoker.flags)) { 56 foreach(flag, invoker.flags) { 57 args += [ flag ] 58 } 59 } 60 61 args += [ 62 header, 63 "--", 64 "{{defines}}", 65 "{{include_dirs}}", 66 "{{cflags}}", 67 "{{cflags_c}}", 68 ] 69 } 70} 71