Announcing bindgen
0.31.0
bindgen
automatically generates Rust FFI bindings to C and C++ libraries.
Upgrade to this release by updating your Cargo.toml
:
bindgen = "0.31.0"
Changelog
Added
-
A new
bindgen
reviewer: @pepyakin You can ask @pepyakin to review all your future pull requests withr? @pepyakin
from now on -
Timers for seeing which phases
bindgen
is spending its time in. On the command line, use the--time-phases
flag. From a builder, use thebindgen::Builder::time_phases(true)
method. #938 -
You can now disable
#[derive(Copy)]
for all types with--no-derive-copy
andbindgen::Builder::derive_copy(false)
. #948 -
We now have an overview of
bindgen
's code base and architecture for newcomers inCONTRIBUTING.md
. #988 -
Derive
PartialOrd
with the--with-derive-partialord
CLI flag orbindgen::Builder::derive_partialord(true)
builder method. #882 -
Derive
Ord
with the--with-derive-ord
CLI flag orbindgen::Builder::derive_ord(true)
builder method. #884 -
When
PartialEq
cannot be derived because of an array larger than Rust's array-derive limit,bindgen
can emit animpl PartialEq for ...
block. Enable this behavior with the--impl-partialeq
CLI flag or thebindgen::Builder::impl_partialeq(true)
method. #1012 -
When deriving
PartialEq
for all types, you can now specify particular types that shouldn'tderive(PartialEq)
with the--no-partialeq <regex>
CLI flag orbindgen::Builder::no_partialeq("<regex>")
builder method. #996 -
Specify types that should not derive
Copy
with the--no-copy <regex>
CLI flag orbindgen::Builder::no_copy("<regex>")
builder method. This functionality was previously only available via comment annotations in the header sources. #1099 -
When deriving
Hash
for all types, you can now specify particular types that shouldn'tderive(Hash)
with the--no-hash <regex>
CLI flag orbindgen::Builder::no_hash("<regex>")
builder method. #1105 -
The
bindgen
users guide now has an FAQ section! If you have any FAQ suggestions to put up there, please open a pull request. [#1020] -
Added
csmith
fuzzing infrastructure.csmith
generates random C and C++ programs, we feed those intobindgen
as headers to generate bindings to, then test that the generated bindings compile and that their layout tests pass. This infrastructure landed in many small bits.We <3 folks who help us find and fix issues via fuzzing! hint hint
-
Added experimental support for the
thiscall
ABI when targetting Rust nightly. #1065
Changed
-
If the user does not explicitly pass a
--target
argument forlibclang
,bindgen
will insert such an argument itself. See #942, #947, and #953 for details. -
C/C++
enum
s are now translated into constants by default, rather than Rustenum
s. The old behavior was a big footgun becauserustc
assumes that the only values of anenum
are its variants, whereas a lot of C/C++ code uses random values asenum
s. Put these two things and it leads to undefined behavior. Translating C/C++enum
s into Rustenum
s is still available with the--rustified-enum <regex>
CLI flag andbindgen::Builder::rustified_enum("<regex>")
builder method. #758 -
Generated bindings are now pretty printed with
rustfmt
by default. Previously, this option existed, but was off by default becausesyntex
did an OK job at pretty printing the bindings. Now that we are usingquote! { ... }
instead ofsyntex
, we lost that pretty printing, and now rely onrustfmt
. You can disablerustfmt
ing with--no-rustfmt-bindings
orbindgen::Builder::rustfmt_bindings(false)
. See #925 and #1022 for details.
Deprecated
-
bindgen::Builder::hide_type
is deprecated in favor ofbindgen::Builder::blacklist_type
. #987 -
bindgen::Builder::whitelisted_type
is deprecated in favor ofbindgen::Builder::whitelist_type
. #987 -
bindgen::Builder::whitelisted_function
is deprecated in favor ofbindgen::Builder::whitelist_function
. #985 -
bindgen::Builder::whitelisted_var
is deprecated in favor ofbindgen::Builder::whitelist_var
. #989
Removed
-
Removed the dependency on (unmaintained)
syntex
, and build times are cut in half!Before:
$ cargo clean; cargo build <snip> Finished dev [unoptimized + debuginfo] target(s) in 98.75 secs
After:
$ cargo clean; cargo build <snip> Finished dev [unoptimized + debuginfo] target(s) in 46.26 secs
-
The
BindgenOptions
type is no longer public. It had been deprecated in previous releases. Usebindgen::Builder
instead. #1000
Fixed
-
Under certain conditions, a globally scoped
enum
could end up with bindings in the wrong namespace module. #888 -
Blacklisted types were incorrectly assumed to always be
Copy
able (and assumed to implement other traits as well).bindgen
is now conservatively pessimistic about the traits that blacklisted types implement. #944 -
When bitfields have a ridiculously large number of bits (for example,
unsigned : 632;
) thenbindgen
was incorrectly deriving traits that couldn't be derived, resulting in errors when compiling the bindings, and was also generatingstruct
s with an incorrect layout. Both issues have been fixed. #982 -
_
is a valid identifier in some C++ contexts, but can't be referenced in Rust, as it is the "throwaway identifier" (a term I just made up, if you use it now, then you owe me money).bindgen
will now translate_
into__
so that it can be used on the Rust side. #1008 -
Nested class definitions were sometimes being emitted in the wrong namespace module in the generated bindings. #1048
-
bindgen
was mis-handlingunion
s that contained bitfield members. This has been fixed. #744 -
Unsigned constants that were greater than
u32::MAX
were being mis-translated bybindgen
. This is now fixed. #1040 -
When given a directory as an input file, or a file to which we don't have read permissions, then
bindgen
will print a more useful error message now. #1029 -
bindgen
previously attempted to deriveHash
for structures with flexibly-sized array members, but knowing how many elements exist in such arrays requires program-specific knowledge thatbindgen
cannot have. #1094
Friends
Thanks to everyone who contributed to this release!
- Alexey Zabelin
- Andrew Gaspar
- Bastien Orivel
- Cldfire
- e
- Emilio Cobos Γlvarez
- Glyn Normington
- Harlan Haskins
- Jackson O'Donnell
- Jeff Muizelaar
- KC
- Liran Ringel
- Manas Karekar
- mchlrhw
- Nick Fitzgerald
- Oliver Geller
- seemyvest
- Sergey Pepyakin
- Taylor Foxhall
- Trevor Reiff
- Zhiting Zhu
Contributing
Join us in our impl period
gitter channel: WG-dev-tools-bindgen
Want to join us? Check out our CONTRIBUTING.md and take a look at some of these issues:
- Issues labeled "easy"
- Issues labeled "less easy"
- Still can't find something to work on? Drop a comment here.
Want to help improve our documentation? Check out the issues labeled "docs".
Found a bug with bindgen
? File an issue here.