fabaccess-bffh/api/build.rs

66 lines
2.0 KiB
Rust
Raw 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)
}
2021-12-01 17:12:57 +01:00
#[cfg(not(feature = "gen_static"))]
2020-02-14 12:20:17 +01:00
fn main() {
2021-08-29 10:09:41 +02:00
let mut compile_command = ::capnpc::CompilerCommand::new();
2021-11-26 02:25:48 +01:00
compile_command
.src_prefix("schema")
.default_parent_module(vec!["schema".to_string()]);
2021-08-29 10:09:41 +02:00
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());
2021-11-26 02:25:48 +01:00
compile_command
.file(entry.path());
2021-08-29 10:09:41 +02:00
}
println!("Compiling schemas...");
compile_command.run().expect("Failed to generate API code");
2020-02-14 12:20:17 +01:00
}
2021-12-01 17:12:57 +01:00
#[cfg(feature = "gen_static")]
fn main() {
let mut compile_command = ::capnpc::CompilerCommand::new();
compile_command
.src_prefix("schema")
.output_path("src/schema")
.default_parent_module(vec!["schema".to_string()]);
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());
}
compile_command.run().expect("Failed to generate extra API code");
}