build.rs 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. fn main() -> Result<(), std::io::Error> {
  2. const PROTOC_ENVAR: &str = "PROTOC";
  3. if std::env::var(PROTOC_ENVAR).is_err() {
  4. #[cfg(not(windows))]
  5. std::env::set_var(PROTOC_ENVAR, protobuf_src::protoc());
  6. }
  7. let proto_base_path = std::path::PathBuf::from("proto");
  8. let proto_files = [
  9. "confirmed_block.proto",
  10. "entries.proto",
  11. "transaction_by_addr.proto",
  12. ];
  13. let mut protos = Vec::new();
  14. for proto_file in &proto_files {
  15. let proto = proto_base_path.join(proto_file);
  16. println!("cargo:rerun-if-changed={}", proto.display());
  17. protos.push(proto);
  18. }
  19. tonic_build::configure()
  20. .build_client(true)
  21. .build_server(false)
  22. .type_attribute(
  23. "TransactionErrorType",
  24. "#[cfg_attr(test, derive(enum_iterator::Sequence))]",
  25. )
  26. .type_attribute(
  27. "InstructionErrorType",
  28. "#[cfg_attr(test, derive(enum_iterator::Sequence))]",
  29. )
  30. .compile(&protos, &[proto_base_path])
  31. }