use flatbuffers_build::BuilderOptions;
use std::env;
use std::path::Path;
fn flatbuffers_schemas() -> Result<(), String> {
let schema_dir = Path::new("tests");
println!("cargo:rerun-if-changed={}", schema_dir.display());
let fbs_files: Vec<_> = std::fs::read_dir(schema_dir)
.expect("Failed to read schemas directory")
.filter_map(|entry| {
let path = entry.ok()?.path();
if path.extension().map_or(false, |ext| ext == "fbs") {
Some(path.to_string_lossy().into_owned())
} else {
None
}
})
.collect();
let compiler = if env::consts::OS == "macos" {
"/opt/flatbuffers/bin/flatc"
} else {
"/opt/flatbuffers/bin/flatc"
};
BuilderOptions::new_with_files(&fbs_files)
.set_compiler(compiler)
.set_output_path("./tests/fb")
.add_flatc_arguments(&["--reflect-types", "--rust-module-root-file"])
.compile()
.expect("FlatBuffers compilation failed");
Ok(())
}
fn main() {
if !Path::new("tests").exists() {
return;
}
flatbuffers_schemas().unwrap();
println!("cargo:rerun-if-changed=build.rs");
}