// build.rs use meta::build_insts; use std::env; use std::fs; use std::path::Path; use std::process::Command; fn main() { let out_dir = env::var_os("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir); for code in build_insts() { let dest_path = dest_path.join(code.file_name); fs::write(&dest_path, code.code).unwrap(); // Run rustfmt on the generated file let rustfmt_output = Command::new("rustfmt") .arg(&dest_path) .output() .expect("Failed to execute rustfmt"); if !rustfmt_output.status.success() { // If rustfmt failed, print the error and panic eprintln!( "rustfmt failed: {}", String::from_utf8_lossy(&rustfmt_output.stderr) ); panic!("rustfmt failed"); } } println!("cargo::rerun-if-changed=build.rs"); println!("cargo::rerun-if-changed=crates/meta/src/codegen.rs"); println!("cargo::rerun-if-changed=crates/meta/src/instructions.rs"); }