-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.rs
45 lines (38 loc) · 1.16 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
extern crate bindgen;
use anyhow::Result;
use std::env;
use std::path::PathBuf;
fn try_main() -> Result<()> {
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
// Configure C build
env::set_var(
"CFLAGS",
format!(
"-I{dir}/vendor/xxhash/ {old}",
dir = env::var("CARGO_MANIFEST_DIR")?,
old = env::var("CFLAGS").unwrap_or_else(|_| "".to_string())
),
);
// Compile xxhash
cc::Build::new()
.file("src/xxhash_bindings.c")
.compile("xxhash");
// Generate rust bindings
println!("cargo:rerun-if-changed=src/bindings.h");
bindgen::Builder::default()
.clang_arg("-I./vendor/xxhash/")
.header("src/xxhash_bindings.h")
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.generate()
.expect("Unable to generate bindings")
.write_to_file(out_dir.join("xxhash_bindings.rs"))
.expect("Couldn't write bindings!");
Ok(())
}
fn main() {
if let Err(er) = try_main() {
println!("{}", er);
}
}