-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
33 lines (26 loc) · 1.04 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
use std::env;
use std::fs;
use std::path::{Path, PathBuf};
fn main() {
let crate_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
// Determine the target directory within the workspace root
let target_dir = env::var("CARGO_TARGET_DIR")
.map(PathBuf::from)
.unwrap_or_else(|_| crate_dir.join("target"));
// Ensure the target directory exists
fs::create_dir_all(&target_dir).expect("Unable to create target directory");
// Create the header file path
let header_path = Path::new(&target_dir)
.join("include")
.join("_ndelementrs.h");
let config_path = Path::new(&crate_dir).join("cbindgen.toml");
let config = cbindgen::Config::from_file(config_path).expect("Unable to load cbindgen config");
// Generate the bindings
let bindings = cbindgen::Builder::new()
.with_crate(crate_dir)
.with_config(config)
.generate()
.expect("Unable to generate bindings");
// Write the bindings to the header file
bindings.write_to_file(header_path);
}