use std::collections::HashMap;
use std::path::{Path, PathBuf};
use serde::{Deserialize, Serialize};
use walkdir::{DirEntry, WalkDir};
#[derive(Serialize, Deserialize, Debug)]
#[serde(untagged)]
enum EnumMapValue {
Key(String),
Value(isize),
}
#[derive(Serialize, Deserialize, Debug)]
struct EnumDefinition {
#[serde(rename = "type")]
typename: String,
values: Vec<HashMap<String, EnumMapValue>>,
}
fn main() {
println!("cargo:rerun-if-changed=kicad/api/proto");
let api_path = PathBuf::from("kicad/api/proto");
if !api_path.exists() || !api_path.is_dir() {
println!("The KiCad API input files are not present. Try running `git submodule init`.");
std::process::exit(1);
}
let mut protos: Vec<PathBuf> = vec![];
let walker = WalkDir::new(api_path).into_iter();
fn is_proto(e: &DirEntry) -> bool {
e.file_name()
.to_str()
.map(|s| s.ends_with(".proto"))
.unwrap_or(false)
}
for entry in walker.filter_entry(|e| is_proto(e) || e.file_type().is_dir()) {
if !entry.as_ref().unwrap().file_type().is_dir() {
protos.push(entry.unwrap().into_path());
}
}
protobuf_codegen::Codegen::new()
.protoc()
.include(Path::new("kicad/api/proto"))
.inputs(&protos)
.cargo_out_dir("proto")
.run_from_script();
}