-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.rs
More file actions
29 lines (22 loc) · 802 Bytes
/
build.rs
File metadata and controls
29 lines (22 loc) · 802 Bytes
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
extern crate cbindgen;
use std::env;
use std::fs;
use std::path::PathBuf;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let package_name = env::var("CARGO_PKG_NAME").unwrap();
// Create include directory in project root
let include_dir = PathBuf::from(&crate_dir).join("include");
fs::create_dir_all(&include_dir).expect("Unable to create include directory");
let output_file = include_dir
.join(format!("{}.h", package_name))
.display()
.to_string();
cbindgen::Builder::new()
.with_crate(crate_dir)
.with_language(cbindgen::Language::C)
.generate()
.expect("Unable to generate bindings")
.write_to_file(&output_file);
println!("cargo:rerun-if-changed=src/lib.rs");
}