2022-10-08 04:30:12 -06:00
|
|
|
use std::fs;
|
|
|
|
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
2024-06-17 04:10:01 -06:00
|
|
|
println!("cargo:rerun-if-changed=../../proto/");
|
2023-02-13 05:02:45 -07:00
|
|
|
|
2024-06-04 07:56:56 -06:00
|
|
|
fs::create_dir_all("src/v2/pb").unwrap_or(());
|
2023-02-13 05:02:45 -07:00
|
|
|
let mut config = prost_build::Config::new();
|
|
|
|
config.protoc_arg("--experimental_allow_proto3_optional");
|
|
|
|
|
2022-10-08 04:30:12 -06:00
|
|
|
tonic_build::configure()
|
|
|
|
.build_client(true)
|
|
|
|
.build_server(false)
|
2024-06-04 07:56:56 -06:00
|
|
|
.out_dir("src/v2/pb")
|
2022-10-08 04:30:12 -06:00
|
|
|
.include_file("mod.rs")
|
2023-02-13 05:02:45 -07:00
|
|
|
.compile_with_config(config, &["../../proto/generate.proto"], &["../../proto"])
|
2024-06-04 11:38:46 -06:00
|
|
|
.map_err(|e| match e.kind(){
|
|
|
|
std::io::ErrorKind::NotFound => {panic!("`protoc` not found, install libprotoc")},
|
|
|
|
std::io::ErrorKind::Other => {panic!("`protoc` version unsupported, upgrade protoc: https://github.com/protocolbuffers/protobuf/releases")},
|
|
|
|
e => {e}
|
|
|
|
}).unwrap_or_else(|e| panic!("protobuf compilation failed: {e}"));
|
2022-10-08 04:30:12 -06:00
|
|
|
|
2024-06-04 07:56:56 -06:00
|
|
|
fs::create_dir_all("src/v3/pb").unwrap_or(());
|
|
|
|
let mut config = prost_build::Config::new();
|
|
|
|
config.protoc_arg("--experimental_allow_proto3_optional");
|
|
|
|
|
|
|
|
tonic_build::configure()
|
|
|
|
.build_client(true)
|
|
|
|
.build_server(false)
|
|
|
|
.out_dir("src/v3/pb")
|
|
|
|
.include_file("mod.rs")
|
|
|
|
.compile_with_config(config, &["../../proto/v3/generate.proto"], &["../../proto"])
|
|
|
|
.unwrap_or_else(|e| panic!("protobuf compilation failed: {e}"));
|
|
|
|
|
2022-10-08 04:30:12 -06:00
|
|
|
Ok(())
|
|
|
|
}
|