use std::{
env,
fs::File,
io::{Read, Write},
path::Path,
};
fn main() {
let out_dir = env::var("OUT_DIR").expect("OUT_DIR should exist");
let name = "transform";
protobuf_codegen_pure::Codegen::new()
.out_dir(&out_dir)
.input(format!("proto/{}.proto", name))
.include("proto")
.customize(protobuf_codegen_pure::Customize {
carllerche_bytes_for_bytes: Some(true),
carllerche_bytes_for_string: Some(true),
..Default::default()
})
.run()
.expect("protoc");
let proto_path = Path::new(&out_dir).join(format!("{}.rs", name));
let mut contents = String::new();
File::open(&proto_path)
.unwrap()
.read_to_string(&mut contents)
.unwrap();
let new_contents = format!("mod proto {{pub mod {} {{ \n{}\n}}}}", name, contents);
File::create(&proto_path)
.unwrap()
.write_all(new_contents.as_bytes())
.unwrap();
}