Skip to contentSkip to conversation

rust: fix bindgen arguments

PATCH In review [email protected] 2 participants 2 messages Mar 29, 2023 – Apr 6, 2023 Rust

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rust: fix bindgen arguments

From: Matteo Croce <[email protected]>

bindgen renamed some arguments to be more inclusive. Detect if bindgen uses the new syntax and use it, otherwise fallback to the previous one.

---
 rust/Makefile | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
rust/Makefile +6 -2
index ff70c4c916f8..3a4971d84b63 100644
@@ -68,6 +68,11 @@ quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
 		--crate-name $(subst rustdoc-,,$@) \
 		@$(objtree)/include/generated/rustc_cfg $<
 
+bindgen-list = $(shell if $(BINDGEN) --help |grep -q -- --allowlist;			\
+	then echo "--blocklist-type '.*' --allowlist-var '' --allowlist-function";	\
+	else echo "--blacklist-type '.*' --whitelist-var '' --whitelist-function";	\
+	fi)
+
 # The `html_logo_url` and `html_favicon_url` forms of the `doc` attribute
 # can be used to specify a custom logo. However:
 #   - The given value is used as-is, thus it cannot be relative or a local file
@@ -300,8 +305,7 @@ $(obj)/bindings/bindings_generated.rs: $(src)/bindings/bindings_helper.h \
 # given it is `libclang`; but for consistency, future Clang changes and/or
 # a potential future GCC backend for `bindgen`, we disable it too.
 $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_flags = \
-    --blacklist-type '.*' --whitelist-var '' \
-    --whitelist-function 'rust_helper_.*'
+    $(bindgen-list) 'rust_helper_.*'
 $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_cflags = \
     -I$(objtree)/$(obj) -Wno-missing-prototypes -Wno-missing-declarations
 $(obj)/bindings/bindings_helpers_generated.rs: private bindgen_target_extra = ; \
Signature · 1 line
2.40.0
#1 lore raw

Hi Matteo,

Quoted 4 lines · On Thu, Mar 30, 2023 at 1:39 AM <[email protected]> wrote:

bindgen renamed some arguments to be more inclusive. Detect if bindgen uses the new syntax and use it, otherwise fallback to the previous one.

We will be updating to a new bindgen version soon-ish, at which time I will perform the change from one to the other directly, instead of having to handle both cases.

But thanks for this patch!

Cheers,
Miguel