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 pdl_compiler; 6 use std::{env, fs::File, io::Write, path::Path}; 7 main()8fn main() { 9 let out_dir = env::var_os("OUT_DIR").unwrap(); 10 let dest_path = Path::new(&out_dir).join("_packets.rs"); 11 let mut dest_file = File::create(dest_path).unwrap(); 12 13 let mut sources = pdl_compiler::ast::SourceDatabase::new(); 14 let file = pdl_compiler::parser::parse_file(&mut sources, "src/packets.pdl") 15 .expect("failed to parse input pdl file"); 16 let schema = pdl_compiler::backends::intermediate::generate(&file).unwrap(); 17 18 let generated = pdl_compiler::backends::rust_no_allocation::generate(&file, &schema).unwrap(); 19 dest_file.write_all(generated.as_bytes()).unwrap(); 20 21 println!("cargo:rerun-if-changed=build.rs"); 22 println!("cargo:rerun-if-changed=src/packets.pdl"); 23 } 24