-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
executable file
·54 lines (44 loc) · 1.4 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
use std::{env, path::Path};
#[cfg(feature = "dynamic-link")]
fn statik_link() -> bool {
false
}
#[cfg(not(feature = "dynamic-link"))]
fn statik_link() -> bool {
true
}
fn probe(s: &str) -> pkg_config::Library {
pkg_config::Config::new()
.cargo_metadata(false)
.probe(s)
.unwrap()
}
fn link_library(s: &str) {
pkg_config::Config::new()
.statik(statik_link())
.probe(s)
.unwrap();
}
const LIB_OPENSLIDE: &str = "openslide";
fn main() {
let libopenslide = probe(LIB_OPENSLIDE);
let include_dir = libopenslide
.include_paths
.get(0)
.expect("Could not find include path for openslide");
let bindings = bindgen::Builder::default()
.header(include_dir.join("openslide.h").to_string_lossy())
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
let out_dir = env::var_os("OUT_DIR").expect("Var env OUT_DIR is undefined");
let dest_path = Path::new(&out_dir).join("bindings.rs");
bindings
.write_to_file(dest_path)
.expect("Couldn't write bindings!");
link_library(LIB_OPENSLIDE);
}