-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
41 lines (41 loc) · 1.6 KB
/
build.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
40
41
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn main() {
let pkg_lib_dir_out = Command::new("pg_config")
.arg("--pkglibdir")
.output()
.unwrap();
let lib_dir_out = Command::new("pg_config").arg("--libdir").output().unwrap();
let include_dir_out = Command::new("pg_config")
.arg("--includedir-server")
.output()
.unwrap();
let pkg_lib_dir = String::from_utf8_lossy(&pkg_lib_dir_out.stdout);
let pkg_lib_dir = pkg_lib_dir.trim_end();
let lib_dir = String::from_utf8_lossy(&lib_dir_out.stdout);
let lib_dir = lib_dir.trim_end();
let include_flag = format!("-I{}", String::from_utf8_lossy(&include_dir_out.stdout));
let include_flag = include_flag.trim_end();
// println!("cargo:rustc-link-lib=pgcommon");
println!("cargo:rerun-if-changed=wrapper.h");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rustc-link-search={}", pkg_lib_dir);
println!("cargo:rustc-link-search={}", lib_dir);
println!("cargo::rustc-link-arg=-fPIC");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg(include_flag)
.clang_arg("-fPIC")
.blocklist_item("FP_NAN")
.blocklist_item("FP_INFINITE")
.blocklist_item("FP_ZERO")
.blocklist_item("FP_NORMAL")
.blocklist_item("FP_SUBNORMAL")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}