-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
34 lines (28 loc) · 872 Bytes
/
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
use std::env;
use std::path::PathBuf;
fn main() {
let version = rustc_version::version().unwrap();
println!("cargo:rustc-env=RUSTC_VERSION={}", version);
#[cfg(feature = "cpp")]
generate_cpp_headers();
}
#[allow(dead_code)]
fn generate_cpp_headers() {
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!("{}.hpp", package_name))
.display()
.to_string();
cbindgen::generate(crate_dir)
.expect("Unable to generate bindings")
.write_to_file(&output_file);
}
#[allow(dead_code)]
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")
}
}