/ core / build.rs
build.rs
 1  use std::{env, path::PathBuf};
 2  
 3  static NODE_DESCRIPTOR_FILE: &str = "node_v1alpha2_descriptor.bin";
 4  static STARKNET_DESCRIPTOR_FILE: &str = "starknet_v1alpha2_descriptor.bin";
 5  
 6  fn main() -> Result<(), Box<dyn std::error::Error>> {
 7      let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
 8      println!("cargo:rerun-if-changed=proto/node/v1alpha2");
 9      println!("cargo:rerun-if-changed=proto/starknet/v1alpha2");
10      println!("cargo:rerun-if-changed=proto/quota/v1");
11  
12      tonic_build::configure()
13          .build_client(true)
14          .build_server(true)
15          .protoc_arg("--experimental_allow_proto3_optional")
16          .file_descriptor_set_path(out_dir.join(NODE_DESCRIPTOR_FILE))
17          .compile(&["proto/node/v1alpha2/stream.proto"], &["proto/node"])?;
18  
19      tonic_build::configure()
20          .build_client(true)
21          .build_server(true)
22          .protoc_arg("--experimental_allow_proto3_optional")
23          .file_descriptor_set_path(out_dir.join(STARKNET_DESCRIPTOR_FILE))
24          .compile_well_known_types(true)
25          .extern_path(".google.protobuf", "::pbjson_types")
26          .compile(
27              &[
28                  "proto/starknet/v1alpha2/starknet.proto",
29                  "proto/starknet/v1alpha2/filter.proto",
30              ],
31              &["proto/starknet"],
32          )?;
33  
34      // only add jsonpb definitions for finality. cursor is implemented manually.
35      let node_description_set = std::fs::read(out_dir.join(NODE_DESCRIPTOR_FILE))?;
36      pbjson_build::Builder::new()
37          .register_descriptors(&node_description_set)?
38          .exclude([".apibara.node.v1alpha2.Cursor"])
39          .build(&[".apibara"])?;
40  
41      // add jsonpb definitions, but only for the data types
42      let starknet_description_set = std::fs::read(out_dir.join(STARKNET_DESCRIPTOR_FILE))?;
43      pbjson_build::Builder::new()
44          .register_descriptors(&starknet_description_set)?
45          .exclude([".apibara.starknet.v1alpha2.FieldElement"])
46          .build(&[".apibara"])?;
47  
48      // we only need the client for the quota service.
49      tonic_build::configure()
50          .build_client(true)
51          .build_server(false)
52          .protoc_arg("--experimental_allow_proto3_optional")
53          .compile(&["proto/quota/v1/quota.proto"], &["proto/quota"])?;
54  
55      Ok(())
56  }