• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Include the Generated Bindings in `src/lib.rs`
2
3We can use the `include!` macro to dump our generated bindings right into our
4crate's main entry point, `src/lib.rs`:
5
6```rust,ignore
7#![allow(non_upper_case_globals)]
8#![allow(non_camel_case_types)]
9#![allow(non_snake_case)]
10
11include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
12```
13
14Because `bzip2`'s symbols do not follow Rust's style conventions, we suppress a
15bunch of warnings with a few `#![allow(...)]` pragmas.
16
17We can run `cargo build` again to check that the bindings themselves compile:
18
19```bash
20$ cargo build
21   Compiling bindgen-tutorial-bzip2-sys v0.1.0
22    Finished debug [unoptimized + debuginfo] target(s) in 62.8 secs
23```
24
25And we can run `cargo test` to verify that the layout, size, and alignment of
26our generated Rust FFI structs match what `bindgen` thinks they should be:
27
28```bash
29$ cargo test
30   Compiling bindgen-tutorial-bzip2-sys v0.1.0
31    Finished debug [unoptimized + debuginfo] target(s) in 0.0 secs
32     Running target/debug/deps/bzip2_sys-10413fc2af207810
33
34running 14 tests
35test bindgen_test_layout___darwin_pthread_handler_rec ... ok
36test bindgen_test_layout___sFILE ... ok
37test bindgen_test_layout___sbuf ... ok
38test bindgen_test_layout__bindgen_ty_1 ... ok
39test bindgen_test_layout__bindgen_ty_2 ... ok
40test bindgen_test_layout__opaque_pthread_attr_t ... ok
41test bindgen_test_layout__opaque_pthread_cond_t ... ok
42test bindgen_test_layout__opaque_pthread_mutex_t ... ok
43test bindgen_test_layout__opaque_pthread_condattr_t ... ok
44test bindgen_test_layout__opaque_pthread_mutexattr_t ... ok
45test bindgen_test_layout__opaque_pthread_once_t ... ok
46test bindgen_test_layout__opaque_pthread_rwlock_t ... ok
47test bindgen_test_layout__opaque_pthread_rwlockattr_t ... ok
48test bindgen_test_layout__opaque_pthread_t ... ok
49
50test result: ok. 14 passed; 0 failed; 0 ignored; 0 measured
51
52   Doc-tests bindgen-tutorial-bzip2-sys
53
54running 0 tests
55
56test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
57```
58