summaryrefslogtreecommitdiff
path: root/system/rust/build.rs
blob: bae31cdcaae2431793c5b10a8ccd82b0074796b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//! Build file to generate packets
//!
//! Run `cargo install --path .` in `external/rust/crates/pdl-compiler` to ensure `pdlc`
//! is in your path.
use std::{env, fs::File, io::Write, path::Path};

fn main() {
    let out_dir = env::var_os("OUT_DIR").unwrap();
    let dest_path = Path::new(&out_dir).join("_packets.rs");
    let mut dest_file = File::create(dest_path).unwrap();

    let mut sources = pdl_compiler::ast::SourceDatabase::new();
    let file = pdl_compiler::parser::parse_file(&mut sources, "src/packets.pdl")
        .expect("failed to parse input pdl file");

    let generated = pdl_compiler::backends::rust::generate(&sources, &file, &[]);
    dest_file.write_all(generated.as_bytes()).unwrap();

    println!("cargo:rerun-if-changed=build.rs");
    println!("cargo:rerun-if-changed=src/packets.pdl");
}