summaryrefslogtreecommitdiff
path: root/system/rust/build.rs
diff options
context:
space:
mode:
Diffstat (limited to 'system/rust/build.rs')
-rw-r--r--system/rust/build.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/system/rust/build.rs b/system/rust/build.rs
new file mode 100644
index 0000000000..f0e49e69df
--- /dev/null
+++ b/system/rust/build.rs
@@ -0,0 +1,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");
+}