-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(network): ensure protoc version >=3.15 (#1991)
- Loading branch information
1 parent
6390dde
commit 48f8c3e
Showing
1 changed file
with
33 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
use std::io::Result; | ||
use std::env; | ||
use std::io::{Error, ErrorKind, Result}; | ||
use std::process::Command; | ||
|
||
fn main() -> Result<()> { | ||
println!("Building"); | ||
prost_build::compile_protos( | ||
&[ | ||
"src/protobuf_messages/proto/p2p/proto/header.proto", | ||
"src/protobuf_messages/proto/p2p/proto/state.proto", | ||
], | ||
&["src/protobuf_messages/proto/"], | ||
)?; | ||
Ok(()) | ||
let protoc = env::var("PROTOC").unwrap_or("protoc".to_string()); | ||
|
||
let protoc_version = String::from_utf8_lossy( | ||
&Command::new(protoc).arg("--version").output().expect("Protoc is not installed.").stdout, | ||
) | ||
.to_string(); | ||
|
||
let parts: Vec<&str> = protoc_version.split_whitespace().collect(); | ||
let protoc_version_str = parts.get(1).expect("Failed to determine protoc version"); | ||
let mut protoc_version_parts = protoc_version_str | ||
.split('.') | ||
.map(|part| part.parse::<u32>().expect("Error parsing protoc version")); | ||
let major = protoc_version_parts.next().expect("Protoc version did not have a major number"); | ||
let minor = protoc_version_parts.next().unwrap_or_default(); | ||
|
||
if major < 3 || (major == 3 && minor < 15) { | ||
Err(Error::new( | ||
ErrorKind::Other, | ||
"protoc version is too old. version 3.15.x or greater is needed.", | ||
)) | ||
} else { | ||
prost_build::compile_protos( | ||
&[ | ||
"src/protobuf_messages/proto/p2p/proto/header.proto", | ||
"src/protobuf_messages/proto/p2p/proto/state.proto", | ||
], | ||
&["src/protobuf_messages/proto/"], | ||
)?; | ||
Ok(()) | ||
} | ||
} |