Files
gitks/build.rs
T
zhenyi 5b740eecd7 chore(deps): update dependencies and migrate to tonic-prost
- Replace tonic-build with tonic-prost-build in build dependencies
- Update clru from 0.6.3 to 0.6
- Update serde from 1.0.228 to 1.0
- Update gix from 0.84.0 to 0.84
- Update gix-archive from 0.33.0 to 0.33
- Update duct from 1.1.1 to 1.0
- Update tracing from 0.1.32 to 0.1
- Update tokio-stream from 0.1.18 to 0.1
- Update thiserror from 2.0.18 to 2.0
- Update prost from 0.13 to 0.14
- Update prost-types from 0.13 to 0.14
- Update tonic from 0.12 to 0.14 with transport feature
- Add tonic-prost dependency at version 0.14
- Update tonic-prost-build in build dependencies from 0.12 to 0.14
- Remove async-stream and async-stream-impl dependencies
- Update axum from 0.7.9 to 0.8.9
- Update various other transitive dependencies including getrandom, indexmap, hashbrown, socket2, log, matchit, petgraph, tower, and windows-sys related packages
2026-06-04 18:07:17 +08:00

52 lines
1.5 KiB
Rust

use std::fs;
use std::path::{Path, PathBuf};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR")?);
let proto_dir = manifest_dir.join("proto");
let out_dir = PathBuf::from(std::env::var("OUT_DIR")?);
fs::create_dir_all(&out_dir)?;
clean_generated_files(&out_dir)?;
let protos = proto_files(&proto_dir)?;
for proto in &protos {
println!("cargo:rerun-if-changed={}", proto.display());
}
println!("cargo:rerun-if-changed={}", proto_dir.display());
println!("cargo:rerun-if-changed=build.rs");
tonic_prost_build::configure()
.build_client(true)
.build_server(true)
.emit_rerun_if_changed(false)
.out_dir(&out_dir)
.compile_protos(&protos, &[proto_dir])?;
Ok(())
}
fn proto_files(proto_dir: &Path) -> Result<Vec<PathBuf>, Box<dyn std::error::Error>> {
let mut files = fs::read_dir(proto_dir)?
.map(|entry| entry.map(|entry| entry.path()))
.collect::<Result<Vec<_>, _>>()?;
files.retain(|path| path.extension().is_some_and(|ext| ext == "proto"));
files.sort();
Ok(files)
}
fn clean_generated_files(out_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
for entry in fs::read_dir(out_dir)? {
let path = entry?.path();
let is_generated_rs = path.extension().is_some_and(|ext| ext == "rs")
&& path.file_name().is_some_and(|name| name != "mod.rs");
if is_generated_rs {
fs::remove_file(path)?;
}
}
Ok(())
}