-
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbuild.rs
More file actions
78 lines (69 loc) · 2.9 KB
/
build.rs
File metadata and controls
78 lines (69 loc) · 2.9 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 share_dir_out = Command::new("pg_config").arg("--sharedir").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 share_dir = String::from_utf8_lossy(&share_dir_out.stdout);
let share_dir = share_dir.trim_end();
let include_flag = format!("-I{}", String::from_utf8_lossy(&include_dir_out.stdout).trim_end());
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");
println!("cargo:rustc-env=PG_SHARE_DIR={}", share_dir);
if cfg!(target_os = "macos") {
// Get gettext lib path from brew
let gettext_lib = Command::new("brew")
.args(["--prefix", "gettext"])
.output()
.expect("Failed to get gettext path from brew")
.stdout;
let gettext_lib = format!("{}/lib", String::from_utf8_lossy(&gettext_lib).trim_end());
println!("cargo:rustc-link-search={}", gettext_lib);
println!("cargo:rustc-link-lib=intl");
// Add link to PostgreSQL libraries
println!("cargo:rustc-link-lib=pq");
println!("cargo:rustc-link-lib=pgcommon");
println!("cargo:rustc-link-lib=pgport");
}
let mut builder = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg(include_flag)
.clang_arg("-fPIC");
// Add macOS-specific include path for gettext if on macOS
if cfg!(target_os = "macos") {
let gettext_include = Command::new("brew")
.args(["--prefix", "gettext"])
.output()
.expect("Failed to get gettext path from brew")
.stdout;
let gettext_include = format!("-I{}/include", String::from_utf8_lossy(&gettext_include).trim_end());
builder = builder.clang_arg(&gettext_include);
}
let bindings = builder
.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!");
}