capnp and protoc versioning

This commit is contained in:
Christien Rioux 2023-09-15 11:45:12 -04:00
parent 34bc67676a
commit 3dcbad832d
12 changed files with 157 additions and 28 deletions

1
.capnp_version Normal file
View File

@ -0,0 +1 @@
1.0.1

View File

@ -1,8 +1,4 @@
.vscode .vscode
.git .git
external/keyring-manager/android_test/.gradle
external/keyring-manager/android_test/app/build
external/keyring-manager/android_test/build
external/keyring-manager/android_test/local.properties
target target
veilid-core/pkg veilid-core/pkg

1
.protoc_version Normal file
View File

@ -0,0 +1 @@
24.3

17
Cargo.lock generated
View File

@ -829,15 +829,18 @@ checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
[[package]] [[package]]
name = "capnp" name = "capnp"
version = "0.17.2" version = "0.18.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95e65021d89250bbfe7c2791789ced2c4bdc21b0e8bb59c64f3fd6145a5fd678" checksum = "9eddbd729bd9742aa22d29e871a42ffea7f216a4ddbfdaf09ea88150ef2e7f76"
dependencies = [
"embedded-io",
]
[[package]] [[package]]
name = "capnpc" name = "capnpc"
version = "0.17.2" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbbc3763fb3e6635188e9cc51ee11a26f8777c553ca377430818dbebaaf6042b" checksum = "5067f3c8ee94d993d03150153e9a57a6ff330127b1c1ad76475051e1cef79c2d"
dependencies = [ dependencies = [
"capnp", "capnp",
] ]
@ -1635,6 +1638,12 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "embedded-io"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "658bbadc628dc286b9ae02f0cb0f5411c056eb7487b72f0083203f115de94060"
[[package]] [[package]]
name = "enum-as-inner" name = "enum-as-inner"
version = "0.5.1" version = "0.5.1"

View File

@ -150,9 +150,9 @@ Install Git from <https://git-scm.com/download/win>
Install Rust from <https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe> Install Rust from <https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe>
Ensure that protoc.exe is in a directory in your path. For example, it can be obtained from <https://github.com/protocolbuffers/protobuf/releases/download/v24.2/protoc-24.2-win64.zip> Ensure that protoc.exe is in a directory in your path. For example, it can be obtained from <https://github.com/protocolbuffers/protobuf/releases/download/v24.3/protoc-24.3-win64.zip>
Ensure that capnp.exe is in a directory in your path. For example, it can be obtained from <https://capnproto.org/capnproto-c++-win32-0.10.4.zip> Ensure that capnp.exe is in a directory in your path. For example, it can be obtained from <https://capnproto.org/capnproto-c++-win32-1.0.1.zip>
Start a Command Prompt window. Start a Command Prompt window.

View File

@ -74,14 +74,14 @@ deps-linux:
# Code + Linux deps # Code + Linux deps
code-linux: code-linux:
FROM +deps-linux FROM +deps-linux
COPY --dir .cargo files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid COPY --dir .cargo .capnp_version .protoc_version files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid
RUN cat /veilid/scripts/earthly/cargo-linux/config.toml >> /veilid/.cargo/config.toml RUN cat /veilid/scripts/earthly/cargo-linux/config.toml >> /veilid/.cargo/config.toml
WORKDIR /veilid WORKDIR /veilid
# Code + Linux + Android deps # Code + Linux + Android deps
code-android: code-android:
FROM +deps-android FROM +deps-android
COPY --dir .cargo files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid COPY --dir .cargo .capnp_version .protoc_version files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid
RUN cat /veilid/scripts/earthly/cargo-linux/config.toml >> /veilid/.cargo/config.toml RUN cat /veilid/scripts/earthly/cargo-linux/config.toml >> /veilid/.cargo/config.toml
RUN cat /veilid/scripts/earthly/cargo-android/config.toml >> /veilid/.cargo/config.toml RUN cat /veilid/scripts/earthly/cargo-android/config.toml >> /veilid/.cargo/config.toml
WORKDIR /veilid WORKDIR /veilid

View File

@ -21,8 +21,8 @@ IF NOT DEFINED PROTOC_FOUND (
FOR %%X IN (capnp.exe) DO (SET CAPNP_FOUND=%%~$PATH:X) FOR %%X IN (capnp.exe) DO (SET CAPNP_FOUND=%%~$PATH:X)
IF NOT DEFINED CAPNP_FOUND ( IF NOT DEFINED CAPNP_FOUND (
echo capnproto compiler ^(capnp^) is required but it's not installed. Install capnp 0.10.4 or higher. Ensure it is in your path. Aborting. echo capnproto compiler ^(capnp^) is required but it's not installed. Install capnp 1.0.1 or higher. Ensure it is in your path. Aborting.
echo capnp is available here: https://capnproto.org/capnproto-c++-win32-0.10.4.zip echo capnp is available here: https://capnproto.org/capnproto-c++-win32-1.0.1.zip
goto end goto end
) )

View File

@ -1,9 +1,12 @@
#!/bin/bash #!/bin/bash
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
CAPNPROTO_VERSION=$(cat "$SCRIPTDIR/../../.capnp_version")
mkdir /tmp/capnproto-install mkdir /tmp/capnproto-install
pushd /tmp/capnproto-install pushd /tmp/capnproto-install
curl -O https://capnproto.org/capnproto-c++-0.10.4.tar.gz curl -O https://capnproto.org/capnproto-c++-${CAPNPROTO_VERSION}.tar.gz
tar zxf capnproto-c++-0.10.4.tar.gz tar zxf capnproto-c++-${CAPNPROTO_VERSION}.tar.gz
cd capnproto-c++-0.10.4 cd capnproto-c++-${CAPNPROTO_VERSION}
./configure --without-openssl ./configure --without-openssl
make -j$1 check make -j$1 check
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then

View File

@ -1,13 +1,24 @@
#!/bin/bash #!/bin/bash
VERSION=23.3 SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
PROTOC_VERSION=$(cat "$SCRIPTDIR/../../.protoc_version")
UNAME_M=$(uname -m)
if [[ "$UNAME_M" == "x86_64" ]]; then
PROTOC_ARCH=x86_64
elif [[ "$UNAME_M" == "aarch64" ]]; then
PROTOC_ARCH=aarch_64
else
echo Unsupported build architecture
exit 1
fi
mkdir /tmp/protoc-install mkdir /tmp/protoc-install
pushd /tmp/protoc-install pushd /tmp/protoc-install
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v$VERSION/protoc-$VERSION-linux-x86_64.zip curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/protoc-$PROTOC_VERSION-linux-$PROTOC_ARCH.zip
unzip protoc-$VERSION-linux-x86_64.zip unzip protoc-$PROTOC_VERSION-linux-$PROTOC_ARCH.zip
if [ "$EUID" -ne 0 ]; then if [ "$EUID" -ne 0 ]; then
if command -v checkinstall &> /dev/null; then if command -v checkinstall &> /dev/null; then
sudo checkinstall --pkgversion=$VERSION -y cp -r bin include /usr/local/ sudo checkinstall --pkgversion=$PROTOC_VERSION -y cp -r bin include /usr/local/
cp *.deb ~ cp *.deb ~
else else
sudo cp -r bin include /usr/local/ sudo cp -r bin include /usr/local/
@ -16,7 +27,7 @@ if [ "$EUID" -ne 0 ]; then
sudo rm -rf /tmp/protoc-install sudo rm -rf /tmp/protoc-install
else else
if command -v checkinstall &> /dev/null; then if command -v checkinstall &> /dev/null; then
checkinstall --pkgversion=$VERSION -y cp -r bin include /usr/local/ checkinstall --pkgversion=$PROTOC_VERSION -y cp -r bin include /usr/local/
cp *.deb ~ cp *.deb ~
else else
cp -r bin include /usr/local/ cp -r bin include /usr/local/

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 enum-as-inner = "=0.5.1" # temporary fix for trust-dns-resolver v0.22.0
# Serialization # 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 = { version = "1.0.183", features = ["derive"] }
serde_json = { version = "1.0.105" } serde_json = { version = "1.0.105" }
serde-big-array = "0.5.1" serde-big-array = "0.5.1"
@ -282,7 +282,7 @@ wasm-logger = "0.2.0"
### BUILD OPTIONS ### BUILD OPTIONS
[build-dependencies] [build-dependencies]
capnpc = "0.17.2" capnpc = "0.18.0"
[package.metadata.wasm-pack.profile.release] [package.metadata.wasm-pack.profile.release]
wasm-opt = ["-O", "--enable-mutable-globals"] 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() { 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() ::capnpc::CompilerCommand::new()
.file("proto/veilid.capnp") .file("proto/veilid.capnp")
.run() .run()

View File

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