capnp and protoc versioning

This commit is contained in:
Christien Rioux 2023-09-15 11:45:12 -04:00
parent fdd04ad24f
commit c01be8f62d
11 changed files with 155 additions and 26 deletions

View file

@ -129,7 +129,7 @@ trust-dns-resolver = { version = "0.22.0", optional = true }
enum-as-inner = "=0.5.1" # temporary fix for trust-dns-resolver v0.22.0
# Serialization
capnp = { version = "0.17.2", default_features = false }
capnp = { version = "0.18.1", default_features = false }
serde = { version = "1.0.183", features = ["derive"] }
serde_json = { version = "1.0.105" }
serde-big-array = "0.5.1"
@ -282,7 +282,7 @@ wasm-logger = "0.2.0"
### BUILD OPTIONS
[build-dependencies]
capnpc = "0.17.2"
capnpc = "0.18.0"
[package.metadata.wasm-pack.profile.release]
wasm-opt = ["-O", "--enable-mutable-globals"]

View file

@ -1,4 +1,102 @@
use std::path::PathBuf;
use std::process::{Command, Stdio};
fn get_workspace_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("..")
.canonicalize()
.expect("want workspace dir")
}
fn get_desired_capnp_version_string() -> String {
std::fs::read_to_string(get_workspace_dir().join(".capnp_version"))
.expect("should find .capnp_version file")
.trim()
.to_owned()
}
fn get_capnp_version_string() -> String {
let output = Command::new("capnpc")
.arg("--version")
.stdout(Stdio::piped())
.output()
.expect("capnpc was not in the PATH");
let s = String::from_utf8(output.stdout)
.expect("'capnpc --version' output was not a valid string")
.trim()
.to_owned();
if !s.starts_with("Cap'n Proto version ") {
panic!("invalid capnpc version string: {}", s);
}
s[20..].to_owned()
}
fn get_desired_protoc_version_string() -> String {
std::fs::read_to_string(get_workspace_dir().join(".protoc_version"))
.expect("should find .protoc_version file")
.trim()
.to_owned()
}
fn get_protoc_version_string() -> String {
let output = Command::new("protoc")
.arg("--version")
.stdout(Stdio::piped())
.output()
.expect("protoc was not in the PATH");
let s = String::from_utf8(output.stdout)
.expect("'protoc --version' output was not a valid string")
.trim()
.to_owned();
if !s.starts_with("libprotoc ") {
panic!("invalid protoc version string: {}", s);
}
s[10..].to_owned()
}
fn main() {
let desired_capnp_version_string = get_desired_capnp_version_string();
let capnp_version_string = get_capnp_version_string();
let desired_protoc_version_string = get_desired_protoc_version_string();
let protoc_version_string = get_protoc_version_string();
// Check capnp version
let desired_capnp_major_version =
usize::from_str_radix(desired_capnp_version_string.split_once(".").unwrap().0, 10)
.expect("should be valid int");
if usize::from_str_radix(capnp_version_string.split_once(".").unwrap().0, 10)
.expect("should be valid int")
!= desired_capnp_major_version
{
panic!(
"capnproto version should be major version 1, preferably {} but is {}",
desired_capnp_version_string, capnp_version_string
);
} else if capnp_version_string != desired_capnp_version_string {
println!(
"capnproto version may be untested: {}",
capnp_version_string
);
}
// Check protoc version
let desired_protoc_major_version =
usize::from_str_radix(desired_protoc_version_string.split_once(".").unwrap().0, 10)
.expect("should be valid int");
if usize::from_str_radix(protoc_version_string.split_once(".").unwrap().0, 10)
.expect("should be valid int")
< desired_protoc_major_version
{
panic!(
"capnproto version should be at least major version {} but is {}",
desired_protoc_major_version, protoc_version_string
);
} else if protoc_version_string != desired_protoc_version_string {
println!("protoc version may be untested: {}", protoc_version_string);
}
::capnpc::CompilerCommand::new()
.file("proto/veilid.capnp")
.run()

View file

@ -32,8 +32,13 @@ pub fn decode_dial_info(reader: &veilid_capnp::dial_info::Reader) -> Result<Dial
let request = ws
.get_request()
.map_err(RPCError::map_protocol("missing WS request"))?;
DialInfo::try_ws(socket_address, request.to_owned())
.map_err(RPCError::map_protocol("invalid WS dial info"))
DialInfo::try_ws(
socket_address,
request
.to_string()
.map_err(RPCError::map_protocol("invalid WS request string"))?,
)
.map_err(RPCError::map_protocol("invalid WS dial info"))
}
veilid_capnp::dial_info::Which::Wss(wss) => {
let wss = wss.map_err(RPCError::protocol)?;
@ -44,8 +49,13 @@ pub fn decode_dial_info(reader: &veilid_capnp::dial_info::Reader) -> Result<Dial
let request = wss
.get_request()
.map_err(RPCError::map_protocol("missing WSS request"))?;
DialInfo::try_wss(socket_address, request.to_owned())
.map_err(RPCError::map_protocol("invalid WSS dial info"))
DialInfo::try_wss(
socket_address,
request
.to_string()
.map_err(RPCError::map_protocol("invalid WSS request string"))?,
)
.map_err(RPCError::map_protocol("invalid WSS dial info"))
}
}
}