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 if (defined(invoker.libclang_path)) { 43 # Note `-isysroot` may not work properly when `LIBCLANG_PATH` is set. 44 env = [ "LIBCLANG_PATH=" + invoker.libclang_path ] 45 } 46 47 outputs = [ output_gen_rs ] 48 depfile = "$target_out_dir/${target_name}.d" 49 args = [ 50 "--depfile", 51 rebase_path(depfile, root_build_dir), 52 "--output", 53 rebase_path(output_gen_rs, root_build_dir), 54 ] 55 56 args += [ 57 # Do not search for system default include paths. 58 "--no-include-path-detection", 59 ] 60 if (defined(invoker.flags)) { 61 foreach(flag, invoker.flags) { 62 args += [ flag ] 63 } 64 } 65 66 args += [ 67 header, 68 "--", 69 "{{defines}}", 70 "{{include_dirs}}", 71 "{{cflags}}", 72 "{{cflags_c}}", 73 ] 74 } 75} 76