build.rs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. use std::{
  2. env,
  3. path::PathBuf,
  4. process::Command,
  5. };
  6. fn main() {
  7. let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
  8. // Print OUT_DIR for debugging build issues.
  9. println!("OUT_DIR={}", out_dir.display());
  10. // We'll use git to pull in protobuf dependencies. This trick lets us use the Rust OUT_DIR
  11. // directory as a mini-repo with wormhole and googleapis as remotes, so we can copy out the
  12. // TREEISH paths we want.
  13. let protobuf_setup = r#"
  14. git init .
  15. git clean -df
  16. git remote add wormhole https://github.com/wormhole-foundation/wormhole.git
  17. git remote add googleapis https://github.com/googleapis/googleapis.git
  18. git fetch --depth=1 wormhole main
  19. git fetch --depth=1 googleapis master
  20. git read-tree --prefix=proto/ -u wormhole/main:proto
  21. git read-tree --prefix=proto/google/api/ -u googleapis/master:google/api
  22. "#;
  23. // Run each command to prepare the OUT_DIR with the protobuf definitions. We need to make sure
  24. // to change the working directory to OUT_DIR, otherwise git will complain.
  25. let _ = Command::new("sh")
  26. .args(["-c", protobuf_setup])
  27. .current_dir(&out_dir)
  28. .output()
  29. .expect("failed to setup protobuf definitions");
  30. // We build the resulting protobuf definitions using Rust's prost_build crate, which generates
  31. // Rust code from the protobuf definitions.
  32. tonic_build::configure()
  33. .build_server(false)
  34. .compile(
  35. &[
  36. out_dir.join("proto/spy/v1/spy.proto"),
  37. out_dir.join("proto/gossip/v1/gossip.proto"),
  38. out_dir.join("proto/node/v1/node.proto"),
  39. out_dir.join("proto/publicrpc/v1/publicrpc.proto"),
  40. ],
  41. &[out_dir.join("proto")],
  42. )
  43. .expect("failed to compile protobuf definitions");
  44. }