Debian Codegraph @

README.md

raw
1 [![crates.io](https://img.shields.io/crates/v/bindgen.svg)](https://crates.io/crates/bindgen)
2 [![docs.rs](https://docs.rs/bindgen/badge.svg)](https://docs.rs/bindgen/)
3
4 # `bindgen`
5
6 **`bindgen` automatically generates Rust FFI bindings to C (and some C++) libraries.**
7
8 For example, given the C header `doggo.h`:
9
10 ```c
11 typedef struct Doggo {
12 int many;
13 char wow;
14 } Doggo;
15
16 void eleven_out_of_ten_majestic_af(Doggo* pupper);
17 ```
18
19 `bindgen` produces Rust FFI code allowing you to call into the `doggo` library's
20 functions and use its types:
21
22 ```rust
23 /* automatically generated by rust-bindgen 0.99.9 */
24
25 #[repr(C)]
26 pub struct Doggo {
27 pub many: ::std::os::raw::c_int,
28 pub wow: ::std::os::raw::c_char,
29 }
30
31 extern "C" {
32 pub fn eleven_out_of_ten_majestic_af(pupper: *mut Doggo);
33 }
34 ```
35
36 ## Users Guide
37
38 [📚 Read the `bindgen` users guide here! 📚](https://rust-lang.github.io/rust-bindgen)
39
40 ## MSRV
41
42 The `bindgen` minimum supported Rust version is **1.70.0**.
43
44 The `bindgen-cli` minimum supported Rust version is **1.70.0**.
45
46 No MSRV bump policy has been established yet, so MSRV may increase in any release.
47
48 The MSRV is the minimum Rust version that can be used to *compile* each crate. However, `bindgen` and `bindgen-cli` can generate bindings that are compatible with Rust versions below the current MSRV.
49
50 Most of the time, the `bindgen-cli` crate will have a more recent MSRV than `bindgen` as crates such as `clap` require it.
51
52 ## API Reference
53
54 [API reference documentation is on docs.rs](https://docs.rs/bindgen)
55
56 ## Environment Variables
57
58 In addition to the [library API](https://docs.rs/bindgen) and [executable command-line API][bindgen-cmdline],
59 `bindgen` can be controlled through environment variables.
60
61 End-users should set these environment variables to modify `bindgen`'s behavior without modifying the source code of direct consumers of `bindgen`.
62
63 - `BINDGEN_EXTRA_CLANG_ARGS`: extra arguments to pass to `clang`
64 - Arguments are whitespace-separated
65 - Use shell-style quoting to pass through whitespace
66 - Examples:
67 - Specify alternate sysroot: `--sysroot=/path/to/sysroot`
68 - Add include search path with spaces: `-I"/path/with spaces"`
69 - `BINDGEN_EXTRA_CLANG_ARGS_<TARGET>`: similar to `BINDGEN_EXTRA_CLANG_ARGS`,
70 but used to set per-target arguments to pass to clang. Useful to set system include
71 directories in a target-specific way in cross-compilation environments with multiple targets.
72 Has precedence over `BINDGEN_EXTRA_CLANG_ARGS`.
73
74 Additionally, `bindgen` uses `libclang` to parse C and C++ header files.
75 To modify how `bindgen` searches for `libclang`, see the [`clang-sys` documentation][clang-sys-env].
76 For more details on how `bindgen` uses `libclang`, see the [`bindgen` users guide][bindgen-book-clang].
77
78 ## Releases
79
80 We don't follow a specific release calendar, but if you need a release please
81 file an issue requesting that (ping `@emilio` for increased effectiveness).
82
83 ## Contributing
84
85 [See `CONTRIBUTING.md` for hacking on `bindgen`!](./CONTRIBUTING.md)
86
87 [bindgen-cmdline]: https://rust-lang.github.io/rust-bindgen/command-line-usage.html
88 [clang-sys-env]: https://github.com/KyleMayes/clang-sys#environment-variables
89 [bindgen-book-clang]: https://rust-lang.github.io/rust-bindgen/requirements.html#clang