1use std::{fs::OpenOptions, io::Write, path::Path};
8
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10 let proto_dir = Path::new("../format");
11 let proto_path = Path::new("../format/Flight.proto");
12
13 tonic_prost_build::configure()
14 .protoc_arg("--experimental_allow_proto3_optional")
16 .out_dir("src")
17 .compile_with_config(prost_config(), &[proto_path], &[proto_dir])?;
18
19 let buffer = std::fs::read_to_string("src/arrow.flight.protocol.rs")?;
20 let mut file = OpenOptions::new()
22 .write(true)
23 .truncate(true)
24 .open("src/arrow.flight.protocol.rs")?;
25 file.write_all("// This file was automatically generated through the build.rs script, and should not be edited.\n\n".as_bytes())?;
26 file.write_all(buffer.as_bytes())?;
27
28 let proto_dir = Path::new("../format");
29 let proto_path = Path::new("../format/FlightSql.proto");
30
31 tonic_prost_build::configure()
32 .protoc_arg("--experimental_allow_proto3_optional")
34 .out_dir("src/sql")
35 .compile_with_config(prost_config(), &[proto_path], &[proto_dir])?;
36
37 let buffer = std::fs::read_to_string("src/sql/arrow.flight.protocol.sql.rs")?;
38 let mut file = OpenOptions::new()
40 .write(true)
41 .truncate(true)
42 .open("src/sql/arrow.flight.protocol.sql.rs")?;
43 file.write_all("// This file was automatically generated through the build.rs script, and should not be edited.\n\n".as_bytes())?;
44 file.write_all(buffer.as_bytes())?;
45
46 let google_protobuf_rs = Path::new("src/sql/google.protobuf.rs");
49 if google_protobuf_rs.exists() && google_protobuf_rs.metadata().unwrap().len() == 0 {
50 std::fs::remove_file(google_protobuf_rs).unwrap();
51 }
52
53 Ok(())
55}
56
57fn prost_config() -> prost_build::Config {
58 let mut config = prost_build::Config::new();
59 config.bytes([".arrow"]);
60 config
61}