use tonic_build::Builder;
fn timestamp(f: impl AsRef<std::path::Path>) -> std::time::SystemTime {
std::fs::metadata(f).unwrap().modified().unwrap()
}
const GRPC_OUTPUT_FILE: &str = "src/qdrant.rs";
#[test]
fn protos() {
let out_time = timestamp(GRPC_OUTPUT_FILE);
let mut protos = std::fs::read_dir("proto").unwrap();
let protos_files_synced = !protos.any(|d| timestamp(d.unwrap().path()) > out_time);
let protos_test_synced = timestamp("tests/protos.rs") <= out_time;
if protos_files_synced && protos_test_synced {
println!("protobuf files not changed. Exiting early!");
return;
}
tonic_build::configure()
.configure_deprecations()
.out_dir("src/") .compile_protos(
&["proto/qdrant.proto"], &["proto"], )
.unwrap();
let custom_reexports = [
"pub use crate::manual_builder::*;",
"pub use crate::builder_types::*;",
"pub use crate::qdrant_client::builders::*;",
"pub use crate::builders::*;",
];
append_to_file(GRPC_OUTPUT_FILE, &custom_reexports.join("\n"));
append_to_file(GRPC_OUTPUT_FILE, "pub use prost_types::Timestamp;");
eprintln!("protos_files_synced:{protos_files_synced}, protos_test_synced:{protos_test_synced}");
eprintln!("proto definitions may be changed. Stubs recompiled. Please commit the changes.")
}
trait BuilderExt {
fn configure_deprecations(self) -> Self;
}
impl BuilderExt for Builder {
fn configure_deprecations(self) -> Self {
self.field_attribute(
"PointsUpdateOperation.operation.delete_deprecated",
"#[deprecated(since = \"1.7.0\", note = \"use `DeletePoints` instead\")]",
)
.field_attribute(
"PointsUpdateOperation.operation.clear_payload_deprecated",
"#[deprecated(since = \"1.7.0\", note = \"use `ClearPayload` instead\")]",
)
.field_attribute(
"Vector.data",
"#[doc = \"\n\nDeprecated since 1.16.0, use [`vector`](crate::qdrant::Vector::vector) field instead.\"]",
)
.field_attribute(
"Vector.indices",
"#[doc = \"\n\nDeprecated since 1.16.0, use [`vector`](crate::qdrant::Vector::vector) field instead.\"]",
)
.field_attribute(
"Vector.vectors_count",
"#[doc = \"\n\nDeprecated since 1.16.0, use [`vector`](crate::qdrant::Vector::vector) field instead.\"]",
)
.field_attribute(
"VectorOutput.data",
"#[doc = \"\n\nDeprecated since 1.16.0, use [`into_vector`](crate::qdrant::VectorOutput::into_vector) method instead.\"]",
)
.field_attribute(
"VectorOutput.indices",
"#[doc = \"\n\nDeprecated since 1.16.0, use [`into_vector`](crate::qdrant::VectorOutput::into_vector) method instead.\"]",
)
.field_attribute(
"VectorOutput.vectors_count",
"#[doc = \"\n\nDeprecated since 1.16.0, use [`into_vector`](crate::qdrant::VectorOutput::into_vector) method instead.\"]",
)
}
}
fn append_to_file(path: &str, line: &str) {
use std::fs::OpenOptions;
use std::io::prelude::*;
writeln!(
OpenOptions::new().append(true).open(path).unwrap(),
"{line}",
)
.unwrap()
}