-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbuild.rs
More file actions
47 lines (40 loc) · 1.43 KB
/
build.rs
File metadata and controls
47 lines (40 loc) · 1.43 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::env;
use std::path::PathBuf;
use std::process::Command;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let package_name = env::var("CARGO_PKG_NAME").unwrap();
// Output to Sources/CFlow/include/flow.h (where Swift build uses it)
let output_file = PathBuf::from(&crate_dir)
.parent()
.expect("Failed to get parent directory")
.join("Sources")
.join("CFlow")
.join("include")
.join(format!("{}.h", package_name));
// Ensure include directory exists
std::fs::create_dir_all(output_file.parent().unwrap())
.expect("Failed to create include directory");
// Run cbindgen CLI
let status = Command::new("cbindgen")
.arg("--crate")
.arg(&package_name)
.arg("--config")
.arg(PathBuf::from(&crate_dir).join("cbindgen.toml"))
.arg("--output")
.arg(&output_file)
.current_dir(&crate_dir)
.status()
.expect("Failed to run cbindgen - ensure it's installed via: cargo install cbindgen");
if !status.success() {
panic!("cbindgen generation failed");
}
// Only re-run cbindgen when FFI-relevant files change
println!("cargo:rerun-if-changed=src/ffi.rs");
println!("cargo:rerun-if-changed=src/types.rs");
println!("cargo:rerun-if-changed=cbindgen.toml");
println!(
"cargo:warning=Generated C header: {}",
output_file.display()
);
}