-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbuild.rs
57 lines (51 loc) · 1.64 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
54
55
56
57
// [[file:~/Workspace/Programming/rust-libs/l-bfgs-b-c/lbfgsb.note::*build.rs][build.rs:1]]
use std::collections::HashSet;
use std::env;
use std::path::PathBuf;
#[derive(Debug)]
struct IgnoreMacros(HashSet<String>);
impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior {
if self.0.contains(name) {
bindgen::callbacks::MacroParsingBehavior::Ignore
} else {
bindgen::callbacks::MacroParsingBehavior::Default
}
}
}
fn main() {
println!("cargo:rustc-link-lib=m");
cc::Build::new()
.cpp(false)
.include("lib/src")
.file("lib/src/lbfgsb.c")
.file("lib/src/linesearch.c")
.file("lib/src/subalgorithms.c")
.file("lib/src/print.c")
.file("lib/src/linpack.c")
.file("lib/src/miniCBLAS.c")
.file("lib/src/timer.c")
.compile("liblbfgsb.a");
let ignored_macros = IgnoreMacros(
vec![
"FP_INFINITE".into(),
"FP_NAN".into(),
"FP_NORMAL".into(),
"FP_SUBNORMAL".into(),
"FP_ZERO".into(),
"IPPORT_RESERVED".into(),
]
.into_iter()
.collect(),
);
let bindings = bindgen::Builder::default()
.header("lib/src/lbfgsb.h")
.parse_callbacks(Box::new(ignored_macros))
.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!");
}
// build.rs:1 ends here