rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Better docs or features for intermediate-complexity use cases (nested headers)

Open agrover opened this issue 8 years ago • 5 comments

I'm following the instructions for using libbindgen in build.rs, and I'm trying to generate bindings for a c library that uses glib. This example doesn't seem to quite meet my needs because glib headers assume an include path for headers they then include, and adding the subheaders to my wrapper.h I think it thinks #include <glib-2.0/glib/gmacros.h> is different from glib/gmacros.h. Or anyways, it's not working. glib assumes users just include the top-level glib.h.

Then I can look at Servo's use of bindgen for Stylo, and how it's recursively finding includes, but it's also doing a lot of other stuff so "just make bindgen handle includes recursively" isn't easy to extract from that for my project. Nested includes and include paths are something that almost every C lib that has more than one header does, so more docs or moving this capability into base bindgen would help a lot, I think.

agrover avatar Jan 28 '17 01:01 agrover

Yay, seems like .clang_arg("-I").clang_arg("/usr/include/glib-2.0") is the way. Leaving open to see if devs think any code or doc changes might be desirable in this area.

😃

agrover avatar Jan 28 '17 01:01 agrover

clang_args([&str]) would be an improvement.

Yamakaky avatar Jan 28 '17 01:01 Yamakaky

I believe better docs are needed, definitely, and any help on that regard is really appreciated. Currently we have some "documentation" sparse around some issues, but we need to really put it together.

emilio avatar Jan 28 '17 14:01 emilio

@agrover thanks to your clang_arg comment I made my libcouchbase binding work as well, otherwise it always did complain about not finding headers even if they were in the same directory as the "main" one. https://github.com/couchbaselabs/couchbase-rs/blob/master/couchbase-sys/build.rs#L33

daschl avatar Jan 30 '17 06:01 daschl

Triage:

Do we still need to document this? If so, then somewhere here https://rust-lang.github.io/rust-bindgen/ ?

amanjeev avatar Sep 20 '22 18:09 amanjeev