From: Asuna Yang <spriteovo@gmail.com>
Add a new `bindgen-backend-option` Kconfig function to test whether the
bindgen backend supports a given flag.
A subsequent commit will use this function to test for RISC-V extension
flags.
Signed-off-by: Asuna Yang <SpriteOvO@gmail.com>
---
scripts/Kconfig.include | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include
index d42042b6c9e2..5d4d29eed0b3 100644
--- a/scripts/Kconfig.include
+++ b/scripts/Kconfig.include
@@ -78,3 +78,8 @@ rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC))
# If you are testing for unstable features, consider testing RUSTC_VERSION
# instead, as features may have different completeness while available.
rustc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(RUSTC) $(1) --crate-type=rlib /dev/null --out-dir=.tmp_$$ -o .tmp_$$/tmp.rlib)
+
+# $(bindgen-backend-option,<flag>)
+# Return y if bindgen backend supports <flag>, n otherwise
+# For now, the backend refers only to libclang, so more specifically, this function tests whether the given flag is recognized by the libclang used by bindgen.
+bindgen-backend-option = $(success,trap "rm -f .tmp_$$.h" EXIT; touch .tmp_$$.h; $(BINDGEN) .tmp_$$.h -- --target=$(BINDGEN_TARGET) $(1))
--
2.51.1
On 12/4/25 15:54, Asuna Yang wrote: > From: Asuna Yang <spriteovo@gmail.com> > > Add a new `bindgen-backend-option` Kconfig function to test whether the > bindgen backend supports a given flag. > > A subsequent commit will use this function to test for RISC-V extension > flags. > > Signed-off-by: Asuna Yang <SpriteOvO@gmail.com> > --- > scripts/Kconfig.include | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/scripts/Kconfig.include b/scripts/Kconfig.include > index d42042b6c9e2..5d4d29eed0b3 100644 > --- a/scripts/Kconfig.include > +++ b/scripts/Kconfig.include > @@ -78,3 +78,8 @@ rustc-llvm-version := $(shell,$(srctree)/scripts/rustc-llvm-version.sh $(RUSTC)) > # If you are testing for unstable features, consider testing RUSTC_VERSION > # instead, as features may have different completeness while available. > rustc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(RUSTC) $(1) --crate-type=rlib /dev/null --out-dir=.tmp_$$ -o .tmp_$$/tmp.rlib) > + > +# $(bindgen-backend-option,<flag>) > +# Return y if bindgen backend supports <flag>, n otherwise > +# For now, the backend refers only to libclang, so more specifically, this function tests whether the given flag is recognized by the libclang used by bindgen. > +bindgen-backend-option = $(success,trap "rm -f .tmp_$$.h" EXIT; touch .tmp_$$.h; $(BINDGEN) .tmp_$$.h -- --target=$(BINDGEN_TARGET) $(1)) > Can probably be simplified down to: $(BINDGEN) /dev/null -- -x c --target=$(BINDGEN_TARGET) $(1)
On 12/4/25 5:06 PM, Vivian Wang wrote: >> + >> +# $(bindgen-backend-option,<flag>) >> +# Return y if bindgen backend supports <flag>, n otherwise >> +# For now, the backend refers only to libclang, so more specifically, this function tests whether the given flag is recognized by the libclang used by bindgen. >> +bindgen-backend-option = $(success,trap "rm -f .tmp_$$.h" EXIT; touch .tmp_$$.h; $(BINDGEN) .tmp_$$.h -- --target=$(BINDGEN_TARGET) $(1)) >> > Can probably be simplified down to: > > $(BINDGEN) /dev/null -- -x c --target=$(BINDGEN_TARGET) $(1) > bindgen is sensitive to file extensions. If the file is not .h or .hpp, it complains: panicked at bindgen/ir/context.rs:562:15: libclang error; possible causes include: - Invalid flag syntax - Unrecognized flags - Invalid flag arguments - File I/O errors - Host vs. target architecture mismatch
On 12/4/25 20:33, Asuna Yang wrote: > On 12/4/25 5:06 PM, Vivian Wang wrote: > >>> + >>> +# $(bindgen-backend-option,<flag>) >>> +# Return y if bindgen backend supports <flag>, n otherwise >>> +# For now, the backend refers only to libclang, so more >>> specifically, this function tests whether the given flag is >>> recognized by the libclang used by bindgen. >>> +bindgen-backend-option = $(success,trap "rm -f .tmp_$$.h" EXIT; >>> touch .tmp_$$.h; $(BINDGEN) .tmp_$$.h -- --target=$(BINDGEN_TARGET) >>> $(1)) >>> >> Can probably be simplified down to: >> >> $(BINDGEN) /dev/null -- -x c --target=$(BINDGEN_TARGET) $(1) >> > > bindgen is sensitive to file extensions. If the file is not .h or > .hpp, it complains: > > panicked at bindgen/ir/context.rs:562:15: > libclang error; possible causes include: > - Invalid flag syntax > - Unrecognized flags > - Invalid flag arguments > - File I/O errors > - Host vs. target architecture mismatch That's so weird... I can't reproduce this if i pass -x c to bindgen, like this: $ bindgen --version bindgen 0.72.1 $ bindgen /dev/null panicked at /build/rust-bindgen-unwrapped-0.72.1-vendor/bindgen-0.72.1/ir/context.rs:562:15: libclang error; possible causes include: - Invalid flag syntax - Unrecognized flags - Invalid flag arguments - File I/O errors - Host vs. target architecture mismatch If you encounter an error missing from this list, please file an issue or a PR! $ bindgen /dev/null -- -x c Failed to run rustfmt: No such file or directory (os error 2) (non-fatal, continuing) /* automatically generated by rust-bindgen 0.72.1 */ The -x argument should explicitly tell (lib)clang what language the file is without needing an extension. I don't know why it's not working for you...
> The -x argument should explicitly tell (lib)clang what language the file > is without needing an extension. I don't know why it's not working for > you... Didn't realize that I should pass a `-x` to the backend. It works now, I'll include it in the next revision. Thanks.
© 2016 - 2025 Red Hat, Inc.