2023-03-29 23:45:13

by Matteo Croce

[permalink] [raw]
Subject: [PATCH] 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.

Signed-off-by: Matteo Croce <[email protected]>
---
rust/Makefile | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/rust/Makefile b/rust/Makefile
index ff70c4c916f8..3a4971d84b63 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -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 = ; \
--
2.40.0


2023-04-06 23:30:06

by Miguel Ojeda

[permalink] [raw]
Subject: Re: [PATCH] rust: fix bindgen arguments

Hi Matteo,

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