I have a *-sys crate that depends on the system library glib. I found that bindings to items from glib already exist in the glib-sys crate. Currently, my *-sys crate re-generates those bindings. However, I want to use the ones that already exist under glib-sys.
To do this, I blocklisted glib's types in my build.rs:
let bindings = bindgen::Builder::default()
However, if bindgen does not generate these, the crate fails to build as it cannot find those types. I want to instruct bindgen that they do in fact exist under glib-sys. I was advised to do this using type aliases, but I can't find any way to do so.
I also created a new file types.rs which I include alongside bindings.rs. However, one of the types that I have to define in types.rs requires __BindgenBitfieldUnit, which isn't provided by glib_sys. I get the following error when trying to build:
error[E0412]: cannot find type `__BindgenBitfieldUnit` in this scope
28 | pub _bitfield_1: __BindgenBitfieldUnit<[u8; 4]>,
| ^^^^^^^^^^^^^^^^^^^^^ not found in this scope
If I remove the call to blocklist_type, this struct still generates. I'm confused about this struct-- it doesn't match the pattern (?i)\b_?G\w+, so I don't know why it isn't generating. I tried
adding a line .allowlist_type("__BindgenBitfieldUnit") and
modifying .allowlist_type("Playerctl_.*") to .allowlist_type("Playerctl_.*|__BindgenBitfieldUnit"),
but neither of these result in the struct being generated.
To find what I was missing, I removed the calls to allowlist_*, blocklist_type, and the include!("types.rs"). This generated the full bindings.rs along with all of the types from glib-sys. I copied the structs I was missing from that file and placed them in my types.rs. Now, the crate has everything it needs to build!