-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathbuild.rs
More file actions
42 lines (34 loc) · 1.26 KB
/
build.rs
File metadata and controls
42 lines (34 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use std::{env, path::PathBuf};
const PROTOC: &str = "PROTOC";
const PROTOC_INCLUDE: &str = "PROTOC_INCLUDE";
const PROTO_ROOT: &str = "proto";
const PROTO_FILES: &[&str] = &[
"proto/arpc.proto",
"proto/shredstream.proto",
"proto/shreder.proto",
"proto/jetstream.proto",
"proto/geyser.proto",
"proto/solana-storage.proto",
];
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("cargo:rerun-if-env-changed=PROTOC");
println!("cargo:rerun-if-env-changed=PROTOC_INCLUDE");
println!("cargo:rerun-if-changed=proto");
let include_dir = ensure_protoc()?;
let out_dir = PathBuf::from(env::var("OUT_DIR")?);
let include_dir = include_dir.to_string_lossy().into_owned();
let includes = [PROTO_ROOT, include_dir.as_str()];
tonic_prost_build::configure()
.file_descriptor_set_path(out_dir.join("proto_descriptors.bin"))
.compile_protos(PROTO_FILES, &includes)?;
Ok(())
}
fn ensure_protoc() -> core::result::Result<PathBuf, protoc_bin_vendored::Error> {
let protoc = protoc_bin_vendored::protoc_bin_path()?;
let include_path = protoc_bin_vendored::include_path()?;
unsafe {
env::set_var(PROTOC, &protoc);
env::set_var(PROTOC_INCLUDE, &include_path);
}
Ok(include_path)
}