cbindgen icon indicating copy to clipboard operation
cbindgen copied to clipboard

Is there a way to specify which headers (and libraries?) from a particular version of GCC to use for generating C/C++ headers?

Open zephyrus00jp opened this issue 2 years ago • 2 comments

Hi I am using GCC to build mozilla Firefox and thunderbird mail client. I create local patches on a PC that runs Debian GNU/Linux x86_64.

I encountered an error while I was building thunderbird the other day, which subsequently disappeared, but I think the bahavior of cbindgen is sub-optiomal or even undesirable.

The bug I encountered is filed in mozilla's bugzilla. https://bugzilla.mozilla.org/show_bug.cgi?id=1840554

C-C TB build fails with /dist/include/mozilla/Assertions.h:367:12: fatal error: 'type_traits' file not found

Some background on the usage of GCC on my PC and what I found is as follows.

I had been using gcc-10, gcc-11 and gcc-12 up to the day when I encountered the problem. I used to compile thunderbird using gcc-10. But subsequently began compiling it using gcc-11. gcc-12 seemed to have a run-time issue and thus I occasionally tried compiling thunderbird using it, but mainly I did the local build using gcc-11. All version of gcc-10, gcc-11, and gcc-12 had been installed on my PC. Since GCC project has released gcc-13 some time ago, I wanted to use gcc-13 which seemed to have solved some issues of gcc-11 and gcc-12 which I had reported, but Debian is known to be very conservative to maintain OS stability and gcc-13 did not become available even its so called testing repository until a few days ago.

Now the bug which kept me from building the mail client thunderbird until I figured it out in the mentioned https://bugzilla.mozilla.org/show_bug.cgi?id=1840554 was this.

I had gcc-10, gcc-11 and gcc-12 and fully installed, but even if I try to use gcc-11 for build, cbindgen tries to use the headers of the highest numbered installed headers. For example, if I try to use gcc-11 for building thunderbird, cbindgen seems to pick up the headers for gcc-13.

The original bug in https://bugzilla.mozilla.org/show_bug.cgi?id=1840554 occurred because before gcc-13 was fully offered for Debian GNU/Linux , something in the Debian package testing repository created the directory for gcc-13 headers but did not fully populate it, I think. But the mere presence (and may be the presence of a few incomplete headers) made cbindgen to use that incomplete gcc-13 header directory to create C/C++ binding headers. So naturally, during the generation cbindgen encountered non-existing header files.

For the messages from thunderbird rust compilation where gcc-13 headers were used when gcc-11 is used for build is shown in https://bugzilla.mozilla.org/show_bug.cgi?id=1840554#c14 (Well, the problem is that there does not seem a mechanism to pass the intention of my using gcc-11 for build to cbindgen. It is possible that the build invokes gcc compiler as in "/usr/bin/ccache gcc-11" and any intelligent logic in the build and cbindgen fails to pick up my choice of specific gcc version.

I am not sure if this use of the highest numbered header directory for C/C++ header generation by cbindgen is an intended behavior. This could cause issues with incompatible compiler versions, etc. It is not uncommon to have multiple versions of the compiler. I would rather specify the intended version if possible.

But then, I realize there is NO way to specify the directory to use for a particular C/C++ version. Or is there?

zephyrus00jp avatar Jul 02 '23 00:07 zephyrus00jp

Are you sure you made this issue in the right repo? Your log in the bugzilla points to nss-gk-api, and the build-script of that crate uses bindgen, not cbindgen.

Note: The below is not related to cbindgen at all, and is just meant as a hint for your problem:

FYI, with bindgen you can pass arguments to (lib)clang, which affect include directories. You can have a look at the official clang cli documentation. You can pass such flags by setting the environment variable BINDGEN_EXTRA_CLANG_ARGS.

jschwe avatar Aug 26 '23 07:08 jschwe

Are you sure you made this issue in the right repo? Your log in the bugzilla points to nss-gk-api, and the build-script of that crate uses bindgen, not cbindgen.

Note: The below is not related to cbindgen at all, and is just meant as a hint for your problem:

FYI, with bindgen you can pass arguments to (lib)clang, which affect include directories. You can have a look at the official clang cli documentation. You can pass such flags by setting the environment variable BINDGEN_EXTRA_CLANG_ARGS.

Oops, I might have picked up the wrong github page. Let me check. It will be a bit slow process, I am down with Covid-19 and the recovery has been very slow. Thank you for your patience.

zephyrus00jp avatar Sep 11 '23 10:09 zephyrus00jp

Yep, this looks like it should go to rust-bindgen, and yeah you can point it to the toolchain location if you can point clang to it :)

emilio avatar Apr 15 '24 01:04 emilio