Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to avoid bindgen being out of sync with cc? #2962

Open
Sympatron opened this issue Oct 25, 2024 · 1 comment
Open

How to avoid bindgen being out of sync with cc? #2962

Sympatron opened this issue Oct 25, 2024 · 1 comment

Comments

@Sympatron
Copy link

Sympatron commented Oct 25, 2024

My understanding is, that it is very common to wrap a C library in a Rust *-sys crate by using bindgen to automatically generate Rust bindings and cc to compile the C code.

As far as I understand it bindgen uses libclang to parse the C headers and cc uses whatever compiler the user provides.

This can lead to problems, because both toolchains don't need to agree on everything. While cross compiling for thumbv6m-none-eabi on Windows, bindgen generated u32 for enums and cc used u8 when possible (-fshort-enums).

This is quite unfortunate and hard to catch. Is there a common workaround for this?

PS: If there is a better place for this issue please tell me.

@pvdrz
Copy link
Contributor

pvdrz commented Oct 25, 2024

the easiest I can think of is to set the relevant environment variables for clang-sys and use the same paths when calling Build::compiler

The docs for Build::compiler also say that the compiler is automatically detected from a number of environment variables so it might be that setting CC or similar to be consistent with the clang-sys environment variables might work as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants