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