rust-lang / rust-bindgen

Automatically generates Rust FFI bindings to C (and some C++) libraries.
https://rust-lang.github.io/rust-bindgen/
BSD 3-Clause "New" or "Revised" License
4.46k stars 694 forks source link

Check and log libclang version in library usage, not just bin #341

Open froydnj opened 7 years ago

froydnj commented 7 years ago

I ran into some trouble testing build-time bindgen in Stylo today because I didn't realize I needed to set CLANG_PATH appropriately, and was getting nonsensical backtraces along with errors about undeclared identifiers in header files. I think it'd be good to add a min_version: Option<clang_sys::CXVersion> to BindgenOptions, which Bindings::generate can then check against the returned version from clang_sys::support::Clang::find(), complaining if the version found isn't new enough, with a friendly error message. Then Stylo can provide the appropriate version and everybody can walk away happy.

froydnj commented 7 years ago

Or maybe an Option<ClangVersion>, since libbindgen appears to have its own notion of clang's version, for reasons that I do not understand.

froydnj commented 7 years ago

Alternatively, after reading @fitzgen's explanation of bindgen, maybe bindgen itself should be doing the checking so that it catches configuration errors from the user.

fitzgen commented 7 years ago

We have https://github.com/servo/rust-bindgen/blob/a1e2029/bindgen/src/main.rs#L26-L43 for the bindgen executable. It would be good to have something similar for libbindgen as well, or to move that check into libbindgen.

fitzgen commented 7 years ago

FWIW I did this in https://github.com/servo/rust-bindgen/pull/793 but then we started running into libclang dynamic loading bugs and I left it at that.

If someone wants to try again, they might find that PR helpful. Or maybe not, its not like its a lot of code.