37 lines
1.7 KiB
Rust
37 lines
1.7 KiB
Rust
use std::env;
|
|
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
// this doesn't make _much_ difference really, since this is our only Rust source file
|
|
// but it seems it's probably better than not having it
|
|
// what we really want is to tell Rust to only regenerate the header file if the Rust code actually compiles
|
|
// but we don't have that flexibility
|
|
// and it's an issue because cbindgen tries to be fault-tolerant in some ways that don't even seem to make sense
|
|
//
|
|
// e.g. mis-spell "Option" as "Option" and you get
|
|
// void print_optional(Optio<const int8_t*> x);
|
|
// instead of
|
|
// void print_optional(const int8_t *x);
|
|
// and that's only an issue because in HLS TH dependent-file watching gives up after an error
|
|
// i.e. once the containing splice has thrown an exception once, the containing file needs a manual edit to kick it
|
|
// and that's really not helped by Rust Analyzer mostly only showing diagnostics on save
|
|
// P.S. strings to stdout?! what a terrible API
|
|
// don't get me started in the discoverability of actually then using the terminal for debugging:
|
|
// println!("cargo::warning={:?}", env::var("OUT_DIR"));
|
|
println!("cargo::rerun-if-changed=lib.rs");
|
|
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
|
|
let profile = env::var("PROFILE").unwrap();
|
|
cbindgen::Builder::new()
|
|
.with_crate(&crate_dir)
|
|
.with_language(cbindgen::Language::C)
|
|
.with_style(cbindgen::Style::Tag)
|
|
.generate()
|
|
.expect("Unable to generate bindings")
|
|
.write_to_file(
|
|
PathBuf::from(&crate_dir)
|
|
.join("target")
|
|
.join(&profile)
|
|
.join("garnet_rs.h"),
|
|
);
|
|
}
|