1use std::{
19 fs::OpenOptions,
20 io::{Read, Write},
21 path::Path,
22};
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_build::configure()
29 .protoc_arg("--experimental_allow_proto3_optional")
31 .out_dir("src")
32 .compile_protos_with_config(prost_config(), &[proto_path], &[proto_dir])?;
33
34 let mut file = OpenOptions::new()
36 .read(true)
37 .open("src/arrow.flight.protocol.rs")?;
38 let mut buffer = String::new();
39 file.read_to_string(&mut buffer)?;
40 let mut file = OpenOptions::new()
42 .write(true)
43 .truncate(true)
44 .open("src/arrow.flight.protocol.rs")?;
45 file.write_all("// This file was automatically generated through the build.rs script, and should not be edited.\n\n".as_bytes())?;
46 file.write_all(buffer.as_bytes())?;
47
48 let proto_dir = Path::new("../format");
49 let proto_path = Path::new("../format/FlightSql.proto");
50
51 tonic_build::configure()
52 .protoc_arg("--experimental_allow_proto3_optional")
54 .out_dir("src/sql")
55 .compile_protos_with_config(prost_config(), &[proto_path], &[proto_dir])?;
56
57 let mut file = OpenOptions::new()
59 .read(true)
60 .open("src/sql/arrow.flight.protocol.sql.rs")?;
61 let mut buffer = String::new();
62 file.read_to_string(&mut buffer)?;
63 let mut file = OpenOptions::new()
65 .write(true)
66 .truncate(true)
67 .open("src/sql/arrow.flight.protocol.sql.rs")?;
68 file.write_all("// This file was automatically generated through the build.rs script, and should not be edited.\n\n".as_bytes())?;
69 file.write_all(buffer.as_bytes())?;
70
71 let google_protobuf_rs = Path::new("src/sql/google.protobuf.rs");
74 if google_protobuf_rs.exists() && google_protobuf_rs.metadata().unwrap().len() == 0 {
75 std::fs::remove_file(google_protobuf_rs).unwrap();
76 }
77
78 Ok(())
80}
81
82fn prost_config() -> prost_build::Config {
83 let mut config = prost_build::Config::new();
84 config.bytes([".arrow"]);
85 config
86}