rust-bindgen
rust-bindgen copied to clipboard
Document how to use bindgen with pkg-config or similar.
It may be useful to see documentation on bindgen being integrated with it, or with stuff that requires altering the include path in bindgen in general.
It'd be a nice addition to the book I think.
This seems to work, though it does feel weird that I have to do this.
let library = pkg_config::probe_library("foobar")?;
let bindings = bindgen::Builder::default()
.clang_args(library.include_paths.iter().map(|path| format!("-I{}", path.to_string_lossy())))
.header("src/wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");