ZeroTierOne/rustybits/zeroidc/build.rs

37 lines
1021 B
Rust
Raw Normal View History

2021-10-27 23:11:06 +00:00
extern crate cbindgen;
2023-08-03 21:47:50 +00:00
use cbindgen::{Config, Language};
2021-10-27 23:11:06 +00:00
use std::env;
use std::path::PathBuf;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let package_name = env::var("CARGO_PKG_NAME").unwrap();
2023-08-04 20:09:14 +00:00
let output_file = target_dir().join(format!("{}.h", package_name)).display().to_string();
2021-10-27 23:11:06 +00:00
let config = Config {
language: Language::C,
cpp_compat: true,
namespace: Some(String::from("zeroidc")),
..Default::default()
};
cbindgen::generate_with_config(&crate_dir, config)
2023-08-03 21:47:50 +00:00
.unwrap()
.write_to_file(&output_file);
2021-10-27 23:11:06 +00:00
}
2023-08-03 21:47:50 +00:00
/// Find the location of the `target/` directory. Note that this may be
/// overridden by `cmake`, so we also need to check the `CARGO_TARGET_DIR`
2021-10-27 23:11:06 +00:00
/// variable.
fn target_dir() -> PathBuf {
if let Ok(target) = env::var("CARGO_TARGET_DIR") {
PathBuf::from(target)
} else {
2023-08-03 21:47:50 +00:00
PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap())
.join("..")
.join("target")
2021-10-27 23:11:06 +00:00
}
}