2020-06-05 20:22:27 +00:00
|
|
|
//! Compiles Protocol Buffers and FlatBuffers schema definitions into
|
|
|
|
//! native Rust types.
|
2020-11-05 18:44:36 +00:00
|
|
|
//!
|
|
|
|
//! Source files are found in
|
2020-06-05 20:22:27 +00:00
|
|
|
|
|
|
|
use std::{
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
process::Command,
|
|
|
|
};
|
|
|
|
|
|
|
|
type Error = Box<dyn std::error::Error>;
|
|
|
|
type Result<T, E = Error> = std::result::Result<T, E>;
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
2020-11-05 18:44:36 +00:00
|
|
|
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
2020-06-05 20:22:27 +00:00
|
|
|
|
|
|
|
generate_grpc_types(&root)?;
|
|
|
|
generate_wal_types(&root)?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-11-11 20:20:53 +00:00
|
|
|
/// Schema used with IOx specific gRPC requests
|
2020-06-05 20:22:27 +00:00
|
|
|
///
|
2020-12-11 18:15:53 +00:00
|
|
|
/// Creates `influxdata.platform.storage.rs` and
|
|
|
|
/// `com.github.influxdata.idpe.storage.read.rs`
|
2020-06-05 20:22:27 +00:00
|
|
|
fn generate_grpc_types(root: &Path) -> Result<()> {
|
2020-11-11 20:20:53 +00:00
|
|
|
let proto_files = vec![
|
2020-12-02 11:55:15 +00:00
|
|
|
root.join("test.proto"),
|
2020-11-11 20:20:53 +00:00
|
|
|
root.join("predicate.proto"),
|
2020-11-12 12:07:42 +00:00
|
|
|
root.join("storage_common.proto"),
|
|
|
|
root.join("storage_common_idpe.proto"),
|
2020-11-11 20:20:53 +00:00
|
|
|
root.join("service.proto"),
|
2020-11-12 12:07:42 +00:00
|
|
|
root.join("source.proto"),
|
2020-11-11 20:20:53 +00:00
|
|
|
];
|
2020-06-05 20:22:27 +00:00
|
|
|
|
2020-11-11 20:20:53 +00:00
|
|
|
// Tell cargo to recompile if any of these proto files are changed
|
|
|
|
for proto_file in &proto_files {
|
|
|
|
println!("cargo:rerun-if-changed={}", proto_file.display());
|
|
|
|
}
|
|
|
|
|
|
|
|
tonic_build::configure().compile(&proto_files, &[root.into()])?;
|
2020-06-05 20:22:27 +00:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Schema used in the WAL
|
|
|
|
///
|
|
|
|
/// Creates `wal_generated.rs`
|
|
|
|
fn generate_wal_types(root: &Path) -> Result<()> {
|
2020-11-05 18:44:36 +00:00
|
|
|
let wal_file = root.join("wal.fbs");
|
2020-06-05 20:22:27 +00:00
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed={}", wal_file.display());
|
|
|
|
let out_dir: PathBuf = std::env::var_os("OUT_DIR")
|
|
|
|
.expect("Could not determine `OUT_DIR`")
|
|
|
|
.into();
|
|
|
|
|
|
|
|
let status = Command::new("flatc")
|
|
|
|
.arg("--rust")
|
|
|
|
.arg("-o")
|
|
|
|
.arg(&out_dir)
|
|
|
|
.arg(wal_file)
|
|
|
|
.status();
|
|
|
|
|
|
|
|
match status {
|
|
|
|
Ok(status) if !status.success() => panic!("`flatc` failed to compile the .fbs to Rust"),
|
|
|
|
Ok(_status) => {} // Successfully compiled
|
|
|
|
Err(err) => panic!("Could not execute `flatc`: {}", err),
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|