pq_sys/
lib.rs

1#[cfg(any(feature = "bundled", feature = "bundled_without_openssl"))]
2extern crate pq_src;
3
4#[allow(non_camel_case_types, non_upper_case_globals, non_snake_case)]
5mod bindings {
6    #[cfg(buildscript_run)]
7    include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
8}
9
10#[cfg(not(buildscript_run))]
11compile_error!(
12    "pq-sys relies on build scripts beeing executed. \n \
13     Please double check that you don't have a `[target.*.pq]` entry \
14     in your `.cargo/config.toml`\n \
15     These entries prevent build scripts from beeing run"
16);
17
18pub use bindings::*;
19
20#[cfg(not(feature = "buildtime_bindgen"))]
21#[test]
22fn check_generated_bindings_match() {
23    let libpq_include_path = concat!(
24        env!("CARGO_MANIFEST_DIR"),
25        "/pq-src/source/src/interfaces/libpq/"
26    );
27    let postgres_include_path = concat!(env!("CARGO_MANIFEST_DIR"), "/pq-src/source/src/include");
28    let additional_includes_path =
29        concat!(env!("CARGO_MANIFEST_DIR"), "/pq-src/additional_include/");
30
31    let builder = include!("make_bindings.rs").clang_args([
32        "-I",
33        libpq_include_path,
34        "-I",
35        postgres_include_path,
36        "-I",
37        additional_includes_path,
38    ]);
39
40    let generated_bindings = builder.generate().expect("Unable to generate bindings");
41
42    let mut out = Vec::<u8>::new();
43    generated_bindings.write(Box::new(&mut out)).unwrap();
44    let generated_bindings = String::from_utf8(out).unwrap();
45
46    let bundled_bindings =
47        std::fs::read_to_string(String::from(env!("OUT_DIR")) + "/bindings.rs").unwrap();
48    similar_asserts::assert_eq!(generated_bindings, bundled_bindings,)
49}