mirror of
https://gitlab.com/veilid/veilid.git
synced 2024-12-28 17:01:00 -06:00
switch to build hash from modtime for capnp generation
This commit is contained in:
parent
599677bb2d
commit
2ef91116ee
712
Cargo.lock
generated
712
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -274,6 +274,8 @@ wasm-logger = "0.2.0"
|
||||
capnpc = "0.18.0"
|
||||
glob = "0.3.1"
|
||||
filetime = "0.2.23"
|
||||
sha2 = "0.10.8"
|
||||
hex = "0.4.3"
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = ["-O", "--enable-mutable-globals"]
|
||||
|
@ -1,7 +1,10 @@
|
||||
use filetime::{set_file_mtime, FileTime};
|
||||
use glob::glob;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::BufRead;
|
||||
use std::io::Write;
|
||||
use std::{
|
||||
env, fs, io,
|
||||
env, io,
|
||||
path::Path,
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
@ -29,24 +32,61 @@ fn get_capnp_version_string() -> String {
|
||||
s[20..].to_owned()
|
||||
}
|
||||
|
||||
fn is_input_file_outdated<P1, P2>(input: P1, output: P2) -> io::Result<bool>
|
||||
fn is_input_file_outdated<P, Q>(input: P, output: Q) -> io::Result<bool>
|
||||
where
|
||||
P1: AsRef<Path>,
|
||||
P2: AsRef<Path>,
|
||||
P: AsRef<Path>,
|
||||
Q: AsRef<Path>,
|
||||
{
|
||||
let out_meta = fs::metadata(output);
|
||||
if let Ok(meta) = out_meta {
|
||||
let output_mtime = meta.modified()?;
|
||||
let Some(out_bh) = get_build_hash(output) else {
|
||||
// output file not found or no build hash, we are outdated
|
||||
return Ok(true);
|
||||
};
|
||||
|
||||
// if input file is more recent than our output, we are outdated
|
||||
let input_meta = fs::metadata(input)?;
|
||||
let input_mtime = input_meta.modified()?;
|
||||
let in_bh = make_build_hash(input);
|
||||
|
||||
Ok(input_mtime > output_mtime)
|
||||
} else {
|
||||
// output file not found, we are outdated
|
||||
Ok(true)
|
||||
Ok(out_bh != in_bh)
|
||||
}
|
||||
|
||||
fn calculate_hash(lines: std::io::Lines<std::io::BufReader<std::fs::File>>) -> Vec<u8> {
|
||||
let mut hasher = Sha256::new();
|
||||
// Build hash of lines, ignoring EOL conventions
|
||||
for l in lines {
|
||||
let l = l.unwrap();
|
||||
hasher.update(l.as_bytes());
|
||||
hasher.update(b"\n");
|
||||
}
|
||||
let out = hasher.finalize();
|
||||
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();
|
||||
for l in lines {
|
||||
let l = l.unwrap();
|
||||
if l.starts_with("//BUILDHASH:") {
|
||||
return Some(hex::decode(&l[12..]).unwrap());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn make_build_hash<P: AsRef<Path>>(input_path: P) -> Vec<u8> {
|
||||
let input_path = input_path.as_ref();
|
||||
let lines = std::io::BufReader::new(std::fs::File::open(input_path).unwrap()).lines();
|
||||
calculate_hash(lines)
|
||||
}
|
||||
|
||||
fn append_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()
|
||||
.write(true)
|
||||
.append(true)
|
||||
.open(output_path)
|
||||
.unwrap();
|
||||
writeln!(out_file, "\n//BUILDHASH:{}", hex::encode(h)).unwrap();
|
||||
}
|
||||
|
||||
fn do_capnp_build() {
|
||||
@ -86,8 +126,8 @@ fn do_capnp_build() {
|
||||
.run()
|
||||
.expect("compiling schema");
|
||||
|
||||
// If successful, update modification time
|
||||
set_file_mtime("proto/veilid_capnp.rs", FileTime::now()).unwrap();
|
||||
// If successful, append a hash of the input to the output file
|
||||
append_hash("proto/veilid.capnp", "proto/veilid_capnp.rs");
|
||||
}
|
||||
|
||||
// Fix for missing __extenddftf2 on Android x86_64 Emulator
|
||||
@ -97,11 +137,13 @@ fn fix_android_emulator() {
|
||||
if target_arch == "x86_64" && target_os == "android" {
|
||||
let missing_library = "clang_rt.builtins-x86_64-android";
|
||||
let android_home = env::var("ANDROID_HOME").expect("ANDROID_HOME not set");
|
||||
let lib_path = glob(&format!("{android_home}/ndk/25.1.8937393/**/lib{missing_library}.a"))
|
||||
.expect("failed to glob")
|
||||
.next()
|
||||
.expect("Need libclang_rt.builtins-x86_64-android.a")
|
||||
.unwrap();
|
||||
let lib_path = glob(&format!(
|
||||
"{android_home}/ndk/25.1.8937393/**/lib{missing_library}.a"
|
||||
))
|
||||
.expect("failed to glob")
|
||||
.next()
|
||||
.expect("Need libclang_rt.builtins-x86_64-android.a")
|
||||
.unwrap();
|
||||
let lib_dir = lib_path.parent().unwrap();
|
||||
println!("cargo:rustc-link-search={}", lib_dir.display());
|
||||
println!("cargo:rustc-link-lib=static={missing_library}");
|
||||
@ -117,7 +159,7 @@ fn main() {
|
||||
}
|
||||
|
||||
if is_input_file_outdated("./proto/veilid.capnp", "./proto/veilid_capnp.rs").unwrap() {
|
||||
println!("cargo:warning=rebuilding proto/veilid_capnp.rs because it is older than proto/veilid.capnp");
|
||||
println!("cargo:warning=rebuilding proto/veilid_capnp.rs because it has changed from the last generation of proto/veilid.capnp");
|
||||
do_capnp_build();
|
||||
}
|
||||
|
||||
|
@ -7680,7 +7680,7 @@ pub mod node_info {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(2), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_envelope_support(&mut self, value: ::capnp::primitive_list::Reader<'a,u8>) -> ::capnp::Result<()> {
|
||||
pub fn set_envelope_support(&mut self, value: ::capnp::primitive_list::Reader<'_,u8>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(2), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -7696,7 +7696,7 @@ pub mod node_info {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(3), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_crypto_support(&mut self, value: ::capnp::primitive_list::Reader<'a,u32>) -> ::capnp::Result<()> {
|
||||
pub fn set_crypto_support(&mut self, value: ::capnp::primitive_list::Reader<'_,u32>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(3), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -7712,7 +7712,7 @@ pub mod node_info {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(4), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_capabilities(&mut self, value: ::capnp::primitive_list::Reader<'a,u32>) -> ::capnp::Result<()> {
|
||||
pub fn set_capabilities(&mut self, value: ::capnp::primitive_list::Reader<'_,u32>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(4), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -7728,7 +7728,7 @@ pub mod node_info {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(5), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_dial_info_detail_list(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::dial_info_detail::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_dial_info_detail_list(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::dial_info_detail::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(5), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -8096,7 +8096,7 @@ pub mod signed_direct_node_info {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_signatures(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::typed_signature::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_signatures(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::typed_signature::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -8388,7 +8388,7 @@ pub mod signed_relayed_node_info {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_relay_ids(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::typed_key::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_relay_ids(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::typed_key::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -8428,7 +8428,7 @@ pub mod signed_relayed_node_info {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(3), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_signatures(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::typed_signature::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_signatures(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::typed_signature::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(3), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -9004,7 +9004,7 @@ pub mod peer_info {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_node_ids(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::typed_key::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_node_ids(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::typed_key::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(0), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -9277,7 +9277,7 @@ pub mod routed_operation {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_signatures(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::signature512::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_signatures(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::signature512::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(0), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -10547,7 +10547,7 @@ pub mod operation_find_node_q {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_capabilities(&mut self, value: ::capnp::primitive_list::Reader<'a,u32>) -> ::capnp::Result<()> {
|
||||
pub fn set_capabilities(&mut self, value: ::capnp::primitive_list::Reader<'_,u32>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -10777,7 +10777,7 @@ pub mod operation_find_node_a {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(0), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -12994,7 +12994,7 @@ pub mod operation_get_value_a {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -13619,7 +13619,7 @@ pub mod operation_set_value_a {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -13912,7 +13912,7 @@ pub mod operation_watch_value_q {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_subkeys(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::subkey_range::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_subkeys(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::subkey_range::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -14273,7 +14273,7 @@ pub mod operation_watch_value_a {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(0), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -14536,7 +14536,7 @@ pub mod operation_value_changed {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_subkeys(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::subkey_range::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_subkeys(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::subkey_range::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -15047,7 +15047,7 @@ pub mod operation_supply_block_a {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(0), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(0), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -15516,7 +15516,7 @@ pub mod operation_find_block_a {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(1), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_suppliers(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_suppliers(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(1), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -15532,7 +15532,7 @@ pub mod operation_find_block_a {
|
||||
::capnp::traits::FromPointerBuilder::get_from_pointer(self.builder.get_pointer_field(2), ::core::option::Option::None)
|
||||
}
|
||||
#[inline]
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'a,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
pub fn set_peers(&mut self, value: ::capnp::struct_list::Reader<'_,crate::veilid_capnp::peer_info::Owned>) -> ::capnp::Result<()> {
|
||||
::capnp::traits::SetPointerBuilder::set_pointer_builder(self.builder.reborrow().get_pointer_field(2), value, false)
|
||||
}
|
||||
#[inline]
|
||||
@ -21292,3 +21292,5 @@ pub mod operation {
|
||||
pub type WhichBuilder<'a,> = Which<::capnp::Result<crate::veilid_capnp::question::Builder<'a>>,::capnp::Result<crate::veilid_capnp::statement::Builder<'a>>,::capnp::Result<crate::veilid_capnp::answer::Builder<'a>>>;
|
||||
}
|
||||
}
|
||||
|
||||
//BUILDHASH:ab4fd70d40c9e543f799ce326dd41c61c7ea78132fb53f164156073d9786a9f6
|
||||
|
Loading…
Reference in New Issue
Block a user