-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
53 lines (44 loc) · 1.56 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
42
43
44
45
46
47
48
49
50
51
52
53
use std::env;
use std::path::PathBuf;
fn main() {
std::env::remove_var("NUM_JOBS");
println!("cargo:rerun-if-changed=wrapper.h");
let out = PathBuf::from(env::var("OUT_DIR").unwrap());
// I'm tired of Cargo rebuilding GSL
if !out.join("include/gsl").exists() {
cmake::Config::new("./gsl")
.define("NO_AMPL_BINDINGS", "1")
.define("GSL_DISABLE_TESTS", "1")
.always_configure(true)
.profile("Release")
.build();
}
let mut lib = out.clone();
lib.push("lib");
let mut headers1 = out.clone();
headers1.push("include");
let mut headers2 = out.clone();
headers2.push("include/gsl");
println!("cargo:rustc-link-search=native={}", lib.display());
println!("cargo:rustc-link-lib=static=gsl");
println!("cargo:rustc-link-lib=static=gslcblas");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.clang_arg(format!("-I{}", headers1.display()))
.clang_arg(format!("-I{}", headers2.display()))
.blocklist_item("FP_.*")
.blocklist_item(".*long_double.*")
.allowlist_function("gsl.*")
.allowlist_type("gsl.*")
.allowlist_var("gsl.*")
.allowlist_function("GSL.*")
.allowlist_type("GSL.*")
.allowlist_var("GSL.*")
.generate()
.expect("Unable to generate bindings");
let out = PathBuf::from(std::env::var("OUT_DIR").unwrap());
let out = out.join("bindings.rs");
bindings
.write_to_file(out)
.expect("Couldn't write bindings!");
}