Bindgen: automatically generate Rust FFI bindings to C and C++ libraries

Announcing bindgen v0.30.0

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

Upgrade to this release by updating your Cargo.toml:

bindgen = "0.30.0"

Changelog

Added

  • Explicit control over choosing which Rust version (specific stable versions or
    nightly Rust) to target. This defaults to the latest stable Rust version. #832
bindgen::Builder::default()
    .rust_target(bindgen::RustTarget::Stable_1_19)
    // or `.rust_target(bindgen::RustTarget::Nightly)` to use unstable features

or

$ bindgen --rust-target 1.19
# or `--rust-target nightly` to use unstable features
  • Started adding derive(Copy) for large arrays of Copy things, even when the
    array is too large to derive(Clone) because Rust doesn't implement Clone
    for arrays of length greater than 32. #874

  • bindgen can now determine which types are hashable and add derive(Hash) to
    those types that support it. This is disabled by default, but can be enabled
    via bindgen::Builder::derive_hash or --with-derive-hash. #876

  • bindgen can now generate impl Debug for Blah trait implementations for
    types that contain non-Debug types, and therefore cannot
    derive(Debug). This behavior can be enabled with
    bindgen::Builder::impl_debug and --impl-debug. #875

  • bindgen can now invoke rustfmt on the generated bindings. The bindings
    have historically been fairly pretty printed, but sometimes this is not the
    case, especially with the new impl Debug for Blah feature. Have bindgen
    run rustfmt with bindgen::Builder::rustfmt_bindings and
    --rustfmt-bindings, and use non-default rustfmt configuration files with
    bindgen::Builder::rustfmt_configuration_file and
    --rustfmt-configuration-file. #900

  • bindgen can now determine which types can be compared with == and add
    derive(PartialEq) to those types that support it. This is disabled by
    default, but can be enabled via bindgen::Builder::derive_partialeq or
    --with-derive-partialeq. #878

  • Additionally, bindgen can also add derive(Eq) to those types which we
    determined we could derive(PartialEq) and do not transitively contain any
    floats. Enable this behavior with bindgen::Builder::derive_eq or
    --with-derive-eq. #880

Changed

  • Started emitting Rust unions when targeting stable Rust >= 1.19, not just
    unstable nightly Rust. #832

  • Emitted layout #[test]s no longer contain internal IDs for template
    instantiations including pointers and arrays. This should make generated
    bindings more stable across updates to unrelated parts of the input
    headers. #871

  • Determining whether a type can derive Copy or not was ported from an ad-hoc
    algorithm to our fix-point framework. #766

  • Determining whether a type has a destructor or not was also ported from an
    ad-hoc algorithm to our fix-point framework. #927

Deprecated

  • bindgen::Builder::unstable_rust/--unstable-rust is deprecated, in favor of
    targeting explicit Rust versions with
    bindgen::Builder::rust_target/--rust-target instead. #832

Fixed

  • Fixed a regression in the derive(Default) analysis that resulted in some
    opaque types deriving Default when they shouldn't have. #889

  • Fixed a regression where template instantiation layout #[test]s were being
    generated with invalid Rust identifiers. #906

Friends

Thanks to everyone who contributed to this release!

  • Anna Liao
  • Bastian Köcher
  • Benjamin Dahse
  • Emilio Cobos Álvarez
  • Malo Jaffré
  • Nick Fitzgerald
  • Niv
  • Richard Bradfield
  • Travis Finkenauer
  • Wangshan Lu
  • Xidorn Quan
  • Zhiting Zhu

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".

Found a bug with bindgen? File an issue here.

4 Likes