We’ll be using this thread to announce bindgen releases. Feel free to ask questions about the releases and bindgen in general here.

Announcing bindgen v0.29.0

bindgen automatically generates Rust FFI bindings to C and C++ libraries.

Upgrade to this release by updating your Cargo.toml :

bindgen = "0.29.0"

Changelog

Since this is the first post, I’m including some items that aren’t strictly new changes in v0.29.0, but are recent changes nonetheless.

Added

“Constified enum modules” translating C/C++ enum s into constants within a module for namespacing, rather than mangling the name of the generated constants. For example, it turns this: // bindgen-flags: --constified-enum-module PetKind enum PetKind { Doggo, Kitty, Hamster }; struct Pet { PetKind kind; char* noise; }; Into this: /* automatically generated by rust-bindgen */ pub mod PetKind { pub type Type = ::std::os::raw::c_uint; pub const Doggo: Type = 0; pub const Kitty: Type = 1; pub const Hamster: Type = 2; } #[repr(C)] #[derive(Debug, Copy)] pub struct Pet { pub kind: PetKind::Type, pub noise: *mut ::std::os::raw::c_char, } The default translation strategy for enum s will generate constants with names like PetKind_Hamster instead. Use bindgen::Builder::constified_enum_module or --constified-enum-module .

You can now mark particular template instantiations as “opaque”, so that bindgen emits a blob of bytes with the correct size and alignment rather than creating generic Rust types. This is useful as a workaround for when a template has a specialization for the given type arguments, which bindgen does not yet support. Previously, it was all of a templates’ instantiations would be opaque or none of them would be. Use bindgen::Builder::opaque_type("SomeTemplate<Foo, Bar>") or --opaque-type "SomeTemplate<Foo, Bar>" .

Added the ability to preprocess and dump the input headers given to bindgen to a file. This should make creating reproducible, system independent, standalone test cases much easier! Bring on the new issues! Use bindgen::Builder::dump_preprocessed_input or --dump-preprocessed-input .

We now use a fix-point analysis to determine whether any given type can derive Debug , or whether it has an explicit virtual table pointer. Previously we were using an ad-hoc algorithm that had at various times suffered from things like going into infinite loops when coming across cycles. Hopefully those kinds of bugs are a thing of the past! #767 #765

Changed

The bindgen repository has moved under the rust-lang-nursery umbrella! The new repository URL is https://github.com/rust-lang-nursery/rust-bindgen

Fixed

No longer generating layout tests for template instantiations using type arguments that we didn’t generate bindings for (which then caused compilation errors). #679

Fixed function name mangling when cross compiling bindings for iOS. #776

Don’t include parent inline namespace s’ names in types’ names. Names of types from some STLs were showing up like std___cxx11_basic_string when they should have been std_basic_string . #789

Fixed a bug where we wouldn’t generate type definitions for some types referenced by an opaque type’s methods, causing compilation errors. #807

Fixed function name mangling issues for win32 targets. #819

Fixed a bug where bindgen was generating a generic type alias that didn’t use its type parameter, which is illegal Rust code and caused compilation errors. #820

The generated size, alignment, and field offset unit tests now have stable names rather than sometimes including an internal identifier which is inherently unstable. This was causing unnecessary diffs when folks were checking in new versions of bindings into their VCS. #394

Fixed a bug where we would try and derive(Debug, Default) on structs that had padding like [u8; 33] , which is larger than the largest array length for which Rust will derive traits. This would cause compilation errors when compiling the emitted bindings. #648

Friends

Thanks to everyone who contributed to these last couple releases!

Dylan McKay

Emilio Cobos Álvarez

Holger Rapp

Kevin Lefevre

Manish Goregaokar

Nick Fitzgerald

Omar Akkila

Ralph Giles

Robin Lambertz

Shing Lyu

Travis Finkenauer

tz70s

UK992

Xidorn Quan

zzhu

Contributing

Want to join us? Check out our CONTRIBUTING.md and take a look at some of these issues:

Want to help improve our documentation? Check out the issues labeled “docs”.