fabaccess-bffh/build.rs

40 lines
1.3 KiB
Rust
Raw Permalink Normal View History

2021-08-29 10:09:41 +02:00
use walkdir::{WalkDir, DirEntry};
fn is_hidden(entry: &DirEntry) -> bool {
entry.file_name()
.to_str()
2021-09-19 18:17:42 +02:00
.map(|s| s.starts_with('.'))
2021-08-29 10:09:41 +02:00
.unwrap_or(false)
}
2020-02-14 12:20:17 +01:00
fn main() {
2021-08-29 10:09:41 +02:00
// Tell cargo to only run this script if the schema files or this script have changed
println!("cargo:rerun-if-changed=schema");
let mut compile_command = ::capnpc::CompilerCommand::new();
// Set parent module of all generated schema files.
// i.e. a file "user.capnp" will result in module "schema::user"
compile_command.default_parent_module(vec!["schema".into()]);
for entry in WalkDir::new("schema")
.max_depth(2)
.into_iter()
.filter_entry(|e| !is_hidden(e))
.filter_map(Result::ok) // Filter all entries that access failed on
.filter(|e| !e.file_type().is_dir()) // Filter directories
// Filter non-schema files
.filter(|e| e.file_name()
.to_str()
.map(|s| s.ends_with(".capnp"))
.unwrap_or(false)
)
{
println!("Collecting schema file {}", entry.path().display());
compile_command.file(entry.path());
}
println!("Compiling schemas...");
compile_command.run().expect("Failed to generate API code");
2020-02-14 12:20:17 +01:00
}