1#![deny(clippy::allow_attributes)]
21
22use std::{fs::OpenOptions, io::Write, path::Path};
23
24fn main() -> Result<(), Box<dyn std::error::Error>> {
25 let proto_dir = Path::new("../format");
26 let proto_path = Path::new("../format/Flight.proto");
27
28 tonic_prost_build::configure()
29 .protoc_arg("--experimental_allow_proto3_optional")
31 .out_dir("src")
32 .compile_with_config(prost_config(), &[proto_path], &[proto_dir])?;
33
34 let buffer = std::fs::read_to_string("src/arrow.flight.protocol.rs")?;
35 let mut file = OpenOptions::new()
37 .write(true)
38 .truncate(true)
39 .open("src/arrow.flight.protocol.rs")?;
40 file.write_all("// This file was automatically generated through the build.rs script, and should not be edited.\n\n".as_bytes())?;
41 file.write_all(buffer.as_bytes())?;
42
43 let proto_dir = Path::new("../format");
44 let proto_path = Path::new("../format/FlightSql.proto");
45
46 tonic_prost_build::configure()
47 .protoc_arg("--experimental_allow_proto3_optional")
49 .out_dir("src/sql")
50 .compile_with_config(prost_config(), &[proto_path], &[proto_dir])?;
51
52 let buffer = std::fs::read_to_string("src/sql/arrow.flight.protocol.sql.rs")?;
53 let mut file = OpenOptions::new()
55 .write(true)
56 .truncate(true)
57 .open("src/sql/arrow.flight.protocol.sql.rs")?;
58 file.write_all("// This file was automatically generated through the build.rs script, and should not be edited.\n\n".as_bytes())?;
59 file.write_all(buffer.as_bytes())?;
60
61 let google_protobuf_rs = Path::new("src/sql/google.protobuf.rs");
64 if google_protobuf_rs.exists() && google_protobuf_rs.metadata().unwrap().len() == 0 {
65 std::fs::remove_file(google_protobuf_rs).unwrap();
66 }
67
68 Ok(())
70}
71
72fn prost_config() -> prost_build::Config {
73 let mut config = prost_build::Config::new();
74 config.bytes([".arrow"]);
75 config
76}