42 lines
No EOL
1.1 KiB
Rust
42 lines
No EOL
1.1 KiB
Rust
extern crate cbindgen;
|
|
|
|
use std::env;
|
|
use std::path::PathBuf;
|
|
use cbindgen::{ Config, ParseConfig };
|
|
|
|
|
|
fn main() {
|
|
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();
|
|
|
|
let config = Config {
|
|
language: cbindgen::Language::C,
|
|
include_guard: Some("FFI_H".to_string()),
|
|
parse: ParseConfig {
|
|
parse_deps: true,
|
|
include: Some(vec!["shared".to_string()]),
|
|
..Default::default()
|
|
},
|
|
..Default::default()
|
|
};
|
|
|
|
cbindgen::generate_with_config(&crate_dir, config)
|
|
.unwrap()
|
|
.write_to_file(&output_file);
|
|
}
|
|
|
|
/// 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`
|
|
/// variable.
|
|
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")
|
|
}
|
|
} |