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