-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.rs
More file actions
39 lines (32 loc) · 1.08 KB
/
build.rs
File metadata and controls
39 lines (32 loc) · 1.08 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
34
35
36
37
38
39
// from cbindgen docs and
// https://michael-f-bryan.github.io/rust-ffi-guide/cbindgen.html
extern crate cbindgen;
use std::env;
use std::path::PathBuf;
fn main() {
let headers_enabled = env::var_os("CARGO_FEATURE_HEADERS").is_some();
if !headers_enabled { return (); }
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let package_name = env::var("CARGO_PKG_NAME").unwrap();
let output_file = target_dir()
.join(format!("{}.h", package_name))
.display()
.to_string();
cbindgen::Builder::new()
.with_language(cbindgen::Language::C)
.with_include_version(true)
.with_include_guard("COMPRESSED_MAP_H")
.with_crate(crate_dir)
// .with_parse_expand(&["compressed_map"])
.exclude_item("PERMUTE_ZERO")
.generate()
.expect("Unable to generate bindings")
.write_to_file(&output_file);
}
fn target_dir() -> PathBuf {
if let Ok(target) = env::var("CARGO_TARGET_DIR") {
PathBuf::from(target)
} else {
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("target")
}
}