commit | 841fd4c8dc3790b068e2b63fbf892ccad5f17e00 | [log] [tgz] |
---|---|---|
author | Alan Wu <XrXr@users.noreply.github.com> | Wed Apr 13 18:55:49 2022 -0400 |
committer | Emilio Cobos Álvarez <emilio@crisal.io> | Tue Apr 19 21:18:17 2022 +0200 |
tree | 1f783c4dd19eee8443a3a97378f305fca0eccedf | |
parent | c27578fac5372575e3caa933a83eac931ae3b53f [diff] |
Use common type alias for anonymous enums in consts mode Previously, anonymous enums generated a type alias but did not use it. For example the following: ```C enum { ZERO, ONE = 4999, }; ``` Generated this: ```Rust /* automatically generated by rust-bindgen 0.59.2 */ pub const ZERO: ::std::os::raw::c_uint = 0; pub const ONE: ::std::os::raw::c_uint = 4999; pub type _bindgen_ty_1 = ::std::os::raw::c_uint; ``` For use cases where humans look at bindgen's Rust output this was a little strange since it's a deviation from how the Rust output for named enums is organized, where all constants share the same type using the type alias. The unused type alias also triggered the dead_code lint. Change to use the generated type alias.
bindgen
bindgen
automatically generates Rust FFI bindings to C (and some C++) libraries.
For example, given the C header doggo.h
:
typedef struct Doggo { int many; char wow; } Doggo; void eleven_out_of_ten_majestic_af(Doggo* pupper);
bindgen
produces Rust FFI code allowing you to call into the doggo
library's functions and use its types:
/* automatically generated by rust-bindgen 0.99.9 */ #[repr(C)] pub struct Doggo { pub many: ::std::os::raw::c_int, pub wow: ::std::os::raw::c_char, } extern "C" { pub fn eleven_out_of_ten_majestic_af(pupper: *mut Doggo); }
📚 Read the bindgen
users guide here! 📚
The minimum supported Rust version is 1.54.
No MSRV bump policy has been established yet, so MSRV may increase in any release.
API reference documentation is on docs.rs
In addition to the library API and executable command-line API, bindgen
can be controlled through environment variables.
End-users should set these environment variables to modify bindgen
's behavior without modifying the source code of direct consumers of bindgen
.
BINDGEN_EXTRA_CLANG_ARGS
: extra arguments to pass to clang
--sysroot=/path/to/sysroot
-I"/path/with spaces"
BINDGEN_EXTRA_CLANG_ARGS_<TARGET>
: similar to BINDGEN_EXTRA_CLANG_ARGS
, but used to set per-target arguments to pass to clang. Useful to set system include directories in a target-specific way in cross-compilation environments with multiple targets. Has precedence over BINDGEN_EXTRA_CLANG_ARGS
.Additionally, bindgen
uses libclang
to parse C and C++ header files. To modify how bindgen
searches for libclang
, see the clang-sys
documentation. For more details on how bindgen
uses libclang
, see the bindgen
users guide.
We don't follow a specific release calendar, but if you need a release please file an issue requesting that (ping @emilio
for increased effectiveness).