1 //! Build file to generate packets 2 //! 3 //! Run `cargo install --path .` in `external/rust/crates/pdl-compiler` to ensure `pdlc` 4 //! is in your path. 5 use std::{env, fs::File, io::Write, path::Path}; 6 main()7fn main() { 8 let out_dir = env::var_os("OUT_DIR").unwrap(); 9 let dest_path = Path::new(&out_dir).join("_packets.rs"); 10 let mut dest_file = File::create(dest_path).unwrap(); 11 12 let mut sources = pdl_compiler::ast::SourceDatabase::new(); 13 let file = pdl_compiler::parser::parse_file(&mut sources, "src/packets.pdl") 14 .expect("failed to parse input pdl file"); 15 16 let generated = pdl_compiler::backends::rust::generate(&sources, &file, &[]); 17 dest_file.write_all(generated.as_bytes()).unwrap(); 18 19 println!("cargo:rerun-if-changed=build.rs"); 20 println!("cargo:rerun-if-changed=src/packets.pdl"); 21 } 22