summaryrefslogtreecommitdiff
path: root/system/rust/build.rs
blob: c4ccf5c05e2d71107758b8de7fc2b1c84634eeb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! Build file to generate packets
//!
//! Run `cargo install .` in `tools/pdl` to ensure `pdl` is in your
//! path.
use std::{
    env,
    fs::File,
    path::Path,
    process::{Command, Stdio},
};

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

    let pdl = Command::new("pdl")
        .args(["--output-format", "rust_no_alloc", "src/packets.pdl"])
        .stdout(Stdio::piped())
        .spawn()
        .unwrap();

    let mut rustfmt =
        Command::new("rustfmt").stdin(pdl.stdout.unwrap()).stdout(dest_file).spawn().unwrap();

    rustfmt.wait().unwrap();

    if let Some(err) = rustfmt.stderr {
        panic!("{err:?}");
    }

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