|
1 | 1 | use std::{
|
2 | 2 | env,
|
3 | 3 | path::PathBuf,
|
4 |
| - process::Command, |
| 4 | + process::{ |
| 5 | + Command, |
| 6 | + Stdio, |
| 7 | + }, |
5 | 8 | };
|
6 | 9 |
|
7 | 10 | fn main() {
|
8 | 11 | let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
|
9 | 12 | let out_var = env::var("OUT_DIR").unwrap();
|
10 | 13 |
|
11 |
| - // Clone the Wormhole repository, which we need to access the protobuf definitions for Wormhole |
12 |
| - // P2P message types. |
| 14 | + // Download the Wormhole repository at a certain tag, which we need to access the protobuf definitions |
| 15 | + // for Wormhole P2P message types. |
13 | 16 | //
|
14 |
| - // TODO: This is ugly and costly, and requires git. Instead of this we should have our own tool |
| 17 | + // TODO: This is ugly. Instead of this we should have our own tool |
15 | 18 | // build process that can generate protobuf definitions for this and other user cases. For now
|
16 | 19 | // this is easy and works and matches upstream Wormhole's `Makefile`.
|
17 |
| - let _ = Command::new("git") |
| 20 | + |
| 21 | + const WORMHOLE_VERSION: &str = "2.18.1"; |
| 22 | + |
| 23 | + let wh_curl = Command::new("curl") |
18 | 24 | .args([
|
19 |
| - "clone", |
20 |
| - "https://github.com/wormhole-foundation/wormhole", |
21 |
| - "wormhole", |
| 25 | + "-s", |
| 26 | + "-L", |
| 27 | + format!("https://github.com/wormhole-foundation/wormhole/archive/refs/tags/v{WORMHOLE_VERSION}.tar.gz").as_str(), |
22 | 28 | ])
|
| 29 | + .stdout(Stdio::piped()) |
| 30 | + .spawn() |
| 31 | + .expect("failed to download wormhole archive"); |
| 32 | + |
| 33 | + let _ = Command::new("tar") |
| 34 | + .args(["xvz"]) |
| 35 | + .stdin(Stdio::from(wh_curl.stdout.unwrap())) |
23 | 36 | .output()
|
24 |
| - .expect("failed to execute process"); |
| 37 | + .expect("failed to extract wormhole archive"); |
25 | 38 |
|
26 | 39 | // Move the tools directory to the root of the repo because that's where the build script
|
27 | 40 | // expects it to be, paths get hardcoded into the binaries.
|
28 | 41 | let _ = Command::new("mv")
|
29 |
| - .args(["wormhole/tools", "tools"]) |
| 42 | + .args([ |
| 43 | + format!("wormhole-{WORMHOLE_VERSION}/tools").as_str(), |
| 44 | + "tools", |
| 45 | + ]) |
30 | 46 | .output()
|
31 |
| - .expect("failed to execute process"); |
| 47 | + .expect("failed to move wormhole tools directory"); |
32 | 48 |
|
33 | 49 | // Move the protobuf definitions to the src/network directory, we don't have to do this
|
34 | 50 | // but it is more intuitive when debugging.
|
35 | 51 | let _ = Command::new("mv")
|
36 | 52 | .args([
|
37 |
| - "wormhole/proto/gossip/v1/gossip.proto", |
| 53 | + format!("wormhole-{WORMHOLE_VERSION}/proto/gossip/v1/gossip.proto").as_str(), |
38 | 54 | "src/network/p2p.proto",
|
39 | 55 | ])
|
40 | 56 | .output()
|
41 |
| - .expect("failed to execute process"); |
| 57 | + .expect("failed to move wormhole protobuf definitions"); |
42 | 58 |
|
43 | 59 | // Build the protobuf compiler.
|
44 | 60 | let _ = Command::new("./build.sh")
|
45 | 61 | .current_dir("tools")
|
46 | 62 | .output()
|
47 |
| - .expect("failed to execute process"); |
| 63 | + .expect("failed to run protobuf compiler build script"); |
48 | 64 |
|
49 | 65 | // Make the protobuf compiler executable.
|
50 | 66 | let _ = Command::new("chmod")
|
51 | 67 | .args(["+x", "tools/bin/*"])
|
52 | 68 | .output()
|
53 |
| - .expect("failed to execute process"); |
| 69 | + .expect("failed to make protofuf compiler executable"); |
54 | 70 |
|
55 | 71 | // Generate the protobuf definitions. See buf.gen.yaml to see how we rename the module for our
|
56 | 72 | // particular use case.
|
57 | 73 | let _ = Command::new("./tools/bin/buf")
|
58 | 74 | .args(["generate", "--path", "src"])
|
59 | 75 | .output()
|
60 |
| - .expect("failed to execute process"); |
| 76 | + .expect("failed to generate protobuf definitions"); |
61 | 77 |
|
62 | 78 | // Build the Go library.
|
63 | 79 | let mut cmd = Command::new("go");
|
|
0 commit comments