build.rs
1 use std::process::{Command, ExitStatus}; 2 3 const GPRC_VERSION: &str = "1.70"; 4 5 fn main() { 6 // first time for uv 7 if gen_py().is_err() { 8 println!("cargo::warning=try using sys python to gen proto"); 9 Command::new("python3") 10 .args(["-m", "venv", ".venv"]) 11 .status() 12 .unwrap(); 13 Command::new(".venv/bin/pip") 14 .args([ 15 "install", 16 format!("grpcio-tools=={}", GPRC_VERSION).as_str(), 17 ]) 18 .status() 19 .unwrap(); 20 gen_py().unwrap(); 21 return; 22 } 23 println!("cargo::warning=try using uv's python to gen proto"); 24 } 25 26 fn gen_py() -> std::io::Result<ExitStatus> { 27 let vpy = ".venv/bin/python3"; 28 let proto_dir = "../rust/proto/src"; 29 let proto_path = "../rust/proto/src/entity.proto"; 30 let out = "src/lakesoul/metadata/generated"; 31 32 Command::new(vpy) 33 .args([ 34 "-m", 35 "grpc.tools.protoc", 36 &format!("-I={}", proto_dir), 37 &format!("--python_out={}", out), 38 &format!("--pyi_out={}", out), 39 proto_path, 40 ]) 41 .status() 42 }