-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathbuild.rs
More file actions
58 lines (53 loc) · 2.38 KB
/
Copy pathbuild.rs
File metadata and controls
58 lines (53 loc) · 2.38 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
48
49
50
51
52
53
54
55
56
57
58
//! Regenerates `include/sqlrite.h` from the `extern "C"` surface in
//! `src/lib.rs` whenever a dependency changes. `cbindgen` walks the
//! crate root and emits a C header with the function signatures,
//! type definitions, and doc comments preserved.
//!
//! Output lives in `sqlrite-ffi/include/sqlrite.h` so downstream
//! consumers (the C examples, future Python/Node/Go SDKs) can grab
//! the header from a stable path even without running `cargo build`
//! themselves — we commit it alongside the code.
use std::env;
use std::path::PathBuf;
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR set by cargo");
let crate_dir = PathBuf::from(crate_dir);
let out_dir = crate_dir.join("include");
if let Err(e) = std::fs::create_dir_all(&out_dir) {
panic!("failed to create include/ dir: {e}");
}
let out_path = out_dir.join("sqlrite.h");
let config = cbindgen::Config {
language: cbindgen::Language::C,
header: Some(
"// Auto-generated by cbindgen from sqlrite-ffi/src/lib.rs.\n\
// Do not edit by hand — changes will be overwritten on the next build.\n\
//\n\
// This is the C ABI for the SQLRite embedded database engine. Every\n\
// non-Rust SDK (Python / Node.js / Go / raw C) binds against the same\n\
// functions declared here. See sqlrite-ffi/src/lib.rs for the full\n\
// memory-ownership and error-handling rules."
.to_string(),
),
include_guard: Some("SQLRITE_H".to_string()),
cpp_compat: true,
pragma_once: true,
documentation: true,
documentation_style: cbindgen::DocumentationStyle::C99,
documentation_length: cbindgen::DocumentationLength::Full,
..Default::default()
};
match cbindgen::generate_with_config(&crate_dir, config) {
Ok(bindings) => {
bindings.write_to_file(&out_path);
println!("cargo:rerun-if-changed=src/lib.rs");
}
// Don't fail the build on a cbindgen error — just warn. This
// keeps `cargo build` working on systems where cbindgen's
// toolchain dependencies aren't present, while still
// regenerating the header on dev machines.
Err(e) => {
println!("cargo:warning=cbindgen header generation failed: {e}");
}
}
}