pq_sys/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#[cfg(any(feature = "bundled", feature = "bundled_without_openssl"))]
extern crate pq_src;

#[allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
mod bindings {
    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
}

pub use bindings::*;

#[test]
fn check_generated_bindings_match() {
    let libpq_include_path = concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/pq-src/source/src/interfaces/libpq/"
    );
    let postgres_include_path = concat!(env!("CARGO_MANIFEST_DIR"), "/pq-src/source/src/include");
    let additional_includes_path =
        concat!(env!("CARGO_MANIFEST_DIR"), "/pq-src/additional_include/");

    let builder = include!("make_bindings.rs").clang_args([
        "-I",
        libpq_include_path,
        "-I",
        postgres_include_path,
        "-I",
        additional_includes_path,
    ]);

    let generated_bindings = builder.generate().expect("Unable to generate bindings");

    let mut out = Vec::<u8>::new();
    generated_bindings.write(Box::new(&mut out)).unwrap();
    let generated_bindings = String::from_utf8(out).unwrap();

    let bundled_bindings =
        std::fs::read_to_string(String::from(env!("OUT_DIR")) + "/bindings.rs").unwrap();
    similar_asserts::assert_eq!(generated_bindings, bundled_bindings,)
}