112a9d9c8Sopenharmony_ci[](https://crates.io/crates/bindgen) 212a9d9c8Sopenharmony_ci[](https://docs.rs/bindgen/) 312a9d9c8Sopenharmony_ci 412a9d9c8Sopenharmony_ci# `bindgen` 512a9d9c8Sopenharmony_ci 612a9d9c8Sopenharmony_ci**`bindgen` automatically generates Rust FFI bindings to C (and some C++) libraries.** 712a9d9c8Sopenharmony_ci 812a9d9c8Sopenharmony_ciFor example, given the C header `doggo.h`: 912a9d9c8Sopenharmony_ci 1012a9d9c8Sopenharmony_ci```c 1112a9d9c8Sopenharmony_citypedef struct Doggo { 1212a9d9c8Sopenharmony_ci int many; 1312a9d9c8Sopenharmony_ci char wow; 1412a9d9c8Sopenharmony_ci} Doggo; 1512a9d9c8Sopenharmony_ci 1612a9d9c8Sopenharmony_civoid eleven_out_of_ten_majestic_af(Doggo* pupper); 1712a9d9c8Sopenharmony_ci``` 1812a9d9c8Sopenharmony_ci 1912a9d9c8Sopenharmony_ci`bindgen` produces Rust FFI code allowing you to call into the `doggo` library's 2012a9d9c8Sopenharmony_cifunctions and use its types: 2112a9d9c8Sopenharmony_ci 2212a9d9c8Sopenharmony_ci```rust 2312a9d9c8Sopenharmony_ci/* automatically generated by rust-bindgen 0.99.9 */ 2412a9d9c8Sopenharmony_ci 2512a9d9c8Sopenharmony_ci#[repr(C)] 2612a9d9c8Sopenharmony_cipub struct Doggo { 2712a9d9c8Sopenharmony_ci pub many: ::std::os::raw::c_int, 2812a9d9c8Sopenharmony_ci pub wow: ::std::os::raw::c_char, 2912a9d9c8Sopenharmony_ci} 3012a9d9c8Sopenharmony_ci 3112a9d9c8Sopenharmony_ciextern "C" { 3212a9d9c8Sopenharmony_ci pub fn eleven_out_of_ten_majestic_af(pupper: *mut Doggo); 3312a9d9c8Sopenharmony_ci} 3412a9d9c8Sopenharmony_ci``` 3512a9d9c8Sopenharmony_ci 3612a9d9c8Sopenharmony_ci## Users Guide 3712a9d9c8Sopenharmony_ci 3812a9d9c8Sopenharmony_ci[ Read the `bindgen` users guide here! ](https://rust-lang.github.io/rust-bindgen) 3912a9d9c8Sopenharmony_ci 4012a9d9c8Sopenharmony_ci## MSRV 4112a9d9c8Sopenharmony_ci 4212a9d9c8Sopenharmony_ciThe minimum supported Rust version is **1.60.0**. 4312a9d9c8Sopenharmony_ci 4412a9d9c8Sopenharmony_ciNo MSRV bump policy has been established yet, so MSRV may increase in any release. 4512a9d9c8Sopenharmony_ci 4612a9d9c8Sopenharmony_ciThe MSRV is the minimum Rust version that can be used to *compile* `bindgen`. However, `bindgen` can generate bindings that are compatible with Rust versions below the current MSRV. 4712a9d9c8Sopenharmony_ci 4812a9d9c8Sopenharmony_ci## API Reference 4912a9d9c8Sopenharmony_ci 5012a9d9c8Sopenharmony_ci[API reference documentation is on docs.rs](https://docs.rs/bindgen) 5112a9d9c8Sopenharmony_ci 5212a9d9c8Sopenharmony_ci## Environment Variables 5312a9d9c8Sopenharmony_ci 5412a9d9c8Sopenharmony_ciIn addition to the [library API](https://docs.rs/bindgen) and [executable command-line API][bindgen-cmdline], 5512a9d9c8Sopenharmony_ci`bindgen` can be controlled through environment variables. 5612a9d9c8Sopenharmony_ci 5712a9d9c8Sopenharmony_ciEnd-users should set these environment variables to modify `bindgen`'s behavior without modifying the source code of direct consumers of `bindgen`. 5812a9d9c8Sopenharmony_ci 5912a9d9c8Sopenharmony_ci- `BINDGEN_EXTRA_CLANG_ARGS`: extra arguments to pass to `clang` 6012a9d9c8Sopenharmony_ci - Arguments are whitespace-separated 6112a9d9c8Sopenharmony_ci - Use shell-style quoting to pass through whitespace 6212a9d9c8Sopenharmony_ci - Examples: 6312a9d9c8Sopenharmony_ci - Specify alternate sysroot: `--sysroot=/path/to/sysroot` 6412a9d9c8Sopenharmony_ci - Add include search path with spaces: `-I"/path/with spaces"` 6512a9d9c8Sopenharmony_ci- `BINDGEN_EXTRA_CLANG_ARGS_<TARGET>`: similar to `BINDGEN_EXTRA_CLANG_ARGS`, 6612a9d9c8Sopenharmony_ci but used to set per-target arguments to pass to clang. Useful to set system include 6712a9d9c8Sopenharmony_ci directories in a target-specific way in cross-compilation environments with multiple targets. 6812a9d9c8Sopenharmony_ci Has precedence over `BINDGEN_EXTRA_CLANG_ARGS`. 6912a9d9c8Sopenharmony_ci 7012a9d9c8Sopenharmony_ciAdditionally, `bindgen` uses `libclang` to parse C and C++ header files. 7112a9d9c8Sopenharmony_ciTo modify how `bindgen` searches for `libclang`, see the [`clang-sys` documentation][clang-sys-env]. 7212a9d9c8Sopenharmony_ciFor more details on how `bindgen` uses `libclang`, see the [`bindgen` users guide][bindgen-book-clang]. 7312a9d9c8Sopenharmony_ci 7412a9d9c8Sopenharmony_ci## Releases 7512a9d9c8Sopenharmony_ci 7612a9d9c8Sopenharmony_ciWe don't follow a specific release calendar, but if you need a release please 7712a9d9c8Sopenharmony_cifile an issue requesting that (ping `@emilio` for increased effectiveness). 7812a9d9c8Sopenharmony_ci 7912a9d9c8Sopenharmony_ci## Contributing 8012a9d9c8Sopenharmony_ci 8112a9d9c8Sopenharmony_ci[See `CONTRIBUTING.md` for hacking on `bindgen`!](./CONTRIBUTING.md) 8212a9d9c8Sopenharmony_ci 8312a9d9c8Sopenharmony_ci[bindgen-cmdline]: https://rust-lang.github.io/rust-bindgen/command-line-usage.html 8412a9d9c8Sopenharmony_ci[clang-sys-env]: https://github.com/KyleMayes/clang-sys#environment-variables 8512a9d9c8Sopenharmony_ci[bindgen-book-clang]: https://rust-lang.github.io/rust-bindgen/requirements.html#clang 86