Merge branch 'main' into 'main'

updated capnp version 0.18 --> 0.19

See merge request veilid/veilid!279
This commit is contained in:
Christien Rioux 2024-05-21 19:08:29 +00:00
commit 2bfb6c635c
4 changed files with 427 additions and 225 deletions

12
Cargo.lock generated
View File

@ -823,18 +823,18 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
[[package]]
name = "capnp"
version = "0.18.13"
version = "0.19.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b671a5b39eadb909b0c2b81d22a400d446526e651e64be9eb6674b33644a4"
checksum = "3aed85272154b3c0bfda873c40395f13adcfbc89696bf639a512291077f8cd17"
dependencies = [
"embedded-io",
]
[[package]]
name = "capnpc"
version = "0.18.1"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a642faaaa78187e70bdcc0014c593c213553cfeda3b15054426d0d596048b131"
checksum = "c75ba30e0f08582d53c2f3710cf4bb65ff562614b1ba86906d7391adffe189ec"
dependencies = [
"capnp",
]
@ -1697,9 +1697,9 @@ checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2"
[[package]]
name = "embedded-io"
version = "0.5.0"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "658bbadc628dc286b9ae02f0cb0f5411c056eb7487b72f0083203f115de94060"
checksum = "edd0f118536f44f5ccd48bcb8b111bdc3de888b58c74639dfb034a357d0f206d"
[[package]]
name = "encode_unicode"

View File

@ -124,7 +124,7 @@ async-std-resolver = { version = "0.24.0", optional = true }
hickory-resolver = { version = "0.24.0", optional = true }
# Serialization
capnp = { version = "0.18.10", default-features = false, features = ["alloc"] }
capnp = { version = "0.19.5", default-features = false, features = ["alloc"] }
serde = { version = "1.0.193", features = ["derive", "rc"] }
serde_json = { version = "1.0.108" }
serde-big-array = "0.5.1"
@ -269,7 +269,7 @@ wasm-logger = "0.2.0"
### BUILD OPTIONS
[build-dependencies]
capnpc = "0.18.0"
capnpc = "0.19.0"
glob = "0.3.1"
filetime = "0.2.23"
sha2 = "0.10.8"

View File

@ -8,7 +8,7 @@ use std::{
process::{Command, Stdio},
};
const CAPNP_VERSION: &str = "1.0.1";
const CAPNP_VERSION: &str = "1.0.2";
fn get_desired_capnp_version_string() -> String {
CAPNP_VERSION.to_string()
@ -36,14 +36,30 @@ where
P: AsRef<Path>,
Q: AsRef<Path>,
{
let Some(out_bh) = get_build_hash(output) else {
let (Some(out_bh), Some(out_capnp_hash)) = get_build_hash_and_capnp_version_hash(output) else {
// output file not found or no build hash, we are outdated
println!("cargo:warning=Output file not found or no build hash.");
return Ok(true);
};
// Check if desired CAPNP_VERSION hash has changed
let mut hasher = Sha256::new();
hasher.update(get_desired_capnp_version_string().as_bytes());
let capnp_hash = hasher.finalize().to_vec();
let in_bh = make_build_hash(input);
Ok(out_bh != in_bh)
if out_bh != in_bh {
println!("cargo:warning=Build hash has changed.");
return Ok(true);
}
if out_capnp_hash != capnp_hash {
println!("cargo:warning=Capnp desired version hash has changed.");
return Ok(true);
}
Ok(false)
}
fn calculate_hash(lines: std::io::Lines<std::io::BufReader<std::fs::File>>) -> Vec<u8> {
@ -58,15 +74,27 @@ fn calculate_hash(lines: std::io::Lines<std::io::BufReader<std::fs::File>>) -> V
out.to_vec()
}
fn get_build_hash<Q: AsRef<Path>>(output_path: Q) -> Option<Vec<u8>> {
let lines = std::io::BufReader::new(std::fs::File::open(output_path).ok()?).lines();
fn get_build_hash_and_capnp_version_hash<Q: AsRef<Path>>(
output_path: Q,
) -> (Option<Vec<u8>>, Option<Vec<u8>>) {
let output_file = match std::fs::File::open(output_path).ok() {
// Returns a file handle if the file exists
Some(f) => f,
// Returns None, None if the file does not exist
None => return (None, None),
};
let lines = std::io::BufReader::new(output_file).lines();
let mut build_hash = None;
let mut capnp_version_hash = None;
for l in lines {
let l = l.unwrap();
if let Some(rest) = l.strip_prefix("//BUILDHASH:") {
return Some(hex::decode(rest).unwrap());
build_hash = Some(hex::decode(rest).unwrap());
} else if let Some(rest) = l.strip_prefix("//CAPNPDESIREDVERSIONHASH:") {
capnp_version_hash = Some(hex::decode(rest).unwrap());
}
}
None
(build_hash, capnp_version_hash)
}
fn make_build_hash<P: AsRef<Path>>(input_path: P) -> Vec<u8> {
@ -75,13 +103,26 @@ fn make_build_hash<P: AsRef<Path>>(input_path: P) -> Vec<u8> {
calculate_hash(lines)
}
fn append_hash<P: AsRef<Path>, Q: AsRef<Path>>(input_path: P, output_path: Q) {
fn append_hash_and_desired_capnp_version_hash<P: AsRef<Path>, Q: AsRef<Path>>(
input_path: P,
output_path: Q,
) {
let input_path = input_path.as_ref();
let output_path = output_path.as_ref();
let lines = std::io::BufReader::new(std::fs::File::open(input_path).unwrap()).lines();
let h = calculate_hash(lines);
let mut out_file = OpenOptions::new().append(true).open(output_path).unwrap();
writeln!(out_file, "\n//BUILDHASH:{}", hex::encode(h)).unwrap();
let mut hasher = Sha256::new();
hasher.update(get_desired_capnp_version_string().as_bytes());
writeln!(
out_file,
"\n//CAPNPDESIREDVERSIONHASH:{}",
hex::encode(hasher.finalize())
)
.unwrap();
}
fn do_capnp_build() {
@ -122,7 +163,8 @@ fn do_capnp_build() {
.expect("compiling schema");
// If successful, append a hash of the input to the output file
append_hash("proto/veilid.capnp", "proto/veilid_capnp.rs");
// Also append a hash of the desired capnp version to the output file
append_hash_and_desired_capnp_version_hash("proto/veilid.capnp", "proto/veilid_capnp.rs");
}
fn main() {

File diff suppressed because it is too large Load Diff