30 lines
1008 B
Rust
30 lines
1008 B
Rust
//! Build script to generate Rust code from ONNX protobuf definitions.
|
|
|
|
use std::env;
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
|
|
fn main() {
|
|
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
|
|
|
// Download and compile ONNX proto if not present
|
|
let proto_dir = out_dir.join("protos");
|
|
fs::create_dir_all(&proto_dir).unwrap();
|
|
|
|
// Write the ONNX proto file (subset needed for parsing)
|
|
let onnx_proto = include_str!("protos/onnx.proto");
|
|
let proto_path = proto_dir.join("onnx.proto");
|
|
fs::write(&proto_path, onnx_proto).unwrap();
|
|
|
|
// Compile the proto file with clippy attributes to suppress warnings
|
|
// on generated code that we don't control
|
|
prost_build::Config::new()
|
|
.out_dir(&out_dir)
|
|
.type_attribute(".", "#[allow(missing_docs)]")
|
|
.compile_protos(&[proto_path], &[proto_dir])
|
|
.expect("Failed to compile ONNX proto");
|
|
|
|
println!("cargo:rerun-if-changed=protos/onnx.proto");
|
|
println!("cargo:rerun-if-changed=build.rs");
|
|
}
|