summaryrefslogtreecommitdiff
path: root/system/rust/build.rs
blob: f0e49e69df9f421e0ddd4a879bc5c672b297a9f2 (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
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");
}