-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
executable file
·33 lines (27 loc) · 1.16 KB
/
Copy pathbuild.rs
File metadata and controls
executable file
·33 lines (27 loc) · 1.16 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
use std::{env, path::Path};
const LIB_OPENSLIDE: &str = "openslide";
fn main() {
let dynamic_link = cfg!(feature = "dynamic-link");
let library = pkg_config::Config::new()
.statik(!dynamic_link)
.probe(LIB_OPENSLIDE)
.unwrap_or_else(|err| panic!("failed to find {LIB_OPENSLIDE} via pkg-config: {err}"));
let include_dir = library
.include_paths
.first()
.expect("pkg-config returned no 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!");
}