Skip to content

Commit

Permalink
feat(network): ensure protoc version >=3.15 (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaastarkware authored May 16, 2024
1 parent 6390dde commit 48f8c3e
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions crates/papyrus_network/build.rs
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(())
}
}

0 comments on commit 48f8c3e

Please sign in to comment.