Why does Rust bindgen even attempt bitfields?

A list of questions and concerns I have as I try to work with C bitfields from the Rust side

C bitfields in Rust are hard

Basically I have this issue where I don't know how FFI should handle C bitfields. They're tricky, error-prone and implementation-defined.

How does Golang deal with this? It doesn't.

And to be fair, Rust doesn't either.

But then why does bindgen attempt to have bitfields at all. Yes, I see the unsafe but wouldn't it be "safer" to recommend exporting C helper functions to deal with this? I actually don't understand how any crate can say they have "C-compatible" bitfields.

My mental model right now is: if the compilers are LLVM-based, then ABI should match up. This is most likely wrong.

Written by