diff --git a/Cargo.lock b/Cargo.lock index 1646d1d0..e217f4e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3194,13 +3194,14 @@ dependencies = [ [[package]] name = "kit" version = "0.1.0" -source = "git+https://github.com/kinode-dao/kit?rev=a4fc76d#a4fc76db7e09b23e4532b8261d82677c76837f3d" +source = "git+https://github.com/kinode-dao/kit?rev=15a4681#15a468109d54af140ce2b7313b3d3ed776943d7c" dependencies = [ "anyhow", "base64 0.21.7", "clap", "dirs 5.0.1", "futures-util", + "hex", "kinode_process_lib 0.5.5", "nix", "regex", diff --git a/kinode/Cargo.toml b/kinode/Cargo.toml index 06a60f8f..2a8a5197 100644 --- a/kinode/Cargo.toml +++ b/kinode/Cargo.toml @@ -14,7 +14,7 @@ path = "src/main.rs" [build-dependencies] anyhow = "1.0.71" -kit = { git = "https://github.com/kinode-dao/kit", rev = "a4fc76d" } +kit = { git = "https://github.com/kinode-dao/kit", rev = "15a4681" } reqwest = { version = "0.11.22", features = ["blocking"] } sha2 = "0.10" tokio = { version = "1.28", features = ["macros"] } diff --git a/kinode/build.rs b/kinode/build.rs index d15684ea..0a051b6f 100644 --- a/kinode/build.rs +++ b/kinode/build.rs @@ -1,6 +1,6 @@ use std::{ fs, - io::{Read, Write}, + io::{Cursor, Read, Write}, }; #[tokio::main] @@ -14,8 +14,7 @@ async fn main() -> anyhow::Result<()> { let parent_dir = pwd.parent().unwrap(); // Build wasm32-wasi apps, zip, and add to bootstrapped_processes.rs - let mut bootstrapped_processes = - fs::File::create(format!("{}/src/bootstrapped_processes.rs", pwd.display(),)).unwrap(); + let mut bootstrapped_processes = Vec::new(); writeln!( bootstrapped_processes, "pub static BOOTSTRAPPED_PROCESSES: &[(&str, &[u8])] = &[", @@ -30,34 +29,45 @@ async fn main() -> anyhow::Result<()> { kit::build::execute(&entry_path, false, false, false, true).await?; // After processing all sub-apps, zip the parent's pkg/ directory + let mut writer = Cursor::new(Vec::new()); + { + let options = zip::write::FileOptions::default() + .compression_method(zip::CompressionMethod::Stored) + .unix_permissions(0o755); + let mut zip = zip::ZipWriter::new(&mut writer); + for sub_entry in walkdir::WalkDir::new(&parent_pkg_path) { + let sub_entry = sub_entry.unwrap(); + let path = sub_entry.path(); + let name = path + .strip_prefix(std::path::Path::new(&parent_pkg_path)) + .unwrap(); + + // Write a directory or file to the ZIP archive + if path.is_file() { + zip.start_file(name.to_string_lossy().into_owned(), options) + .unwrap(); + let mut file = std::fs::File::open(path).unwrap(); + let mut buffer = Vec::new(); + file.read_to_end(&mut buffer).unwrap(); + zip.write_all(&buffer).unwrap(); + } else if !name.as_os_str().is_empty() { + zip.add_directory(name.to_string_lossy().into_owned(), options) + .unwrap(); + } + } + zip.finish().unwrap(); + } + let zip_contents = writer.into_inner(); let zip_filename = format!("{}.zip", entry_path.file_name().unwrap().to_str().unwrap(),); let zip_path = format!("{}/target/{}", parent_dir.display(), zip_filename); - let writer = std::fs::File::create(&zip_path).unwrap(); - let options = zip::write::FileOptions::default() - .compression_method(zip::CompressionMethod::Stored) - .unix_permissions(0o755); - let mut zip = zip::ZipWriter::new(writer); - for sub_entry in walkdir::WalkDir::new(&parent_pkg_path) { - let sub_entry = sub_entry.unwrap(); - let path = sub_entry.path(); - let name = path - .strip_prefix(std::path::Path::new(&parent_pkg_path)) - .unwrap(); - - // Write a directory or file to the ZIP archive - if path.is_file() { - zip.start_file(name.to_string_lossy().into_owned(), options) - .unwrap(); - let mut file = std::fs::File::open(path).unwrap(); - let mut buffer = Vec::new(); - file.read_to_end(&mut buffer).unwrap(); - zip.write_all(&buffer).unwrap(); - } else if !name.as_os_str().is_empty() { - zip.add_directory(name.to_string_lossy().into_owned(), options) - .unwrap(); + if !std::path::Path::new(&zip_path).exists() { + fs::write(&zip_path, zip_contents)?; + } else { + let existing_zip_contents = fs::read(&zip_path)?; + if zip_contents != existing_zip_contents { + fs::write(&zip_path, zip_contents)?; } } - zip.finish().unwrap(); // Add zip bytes to bootstrapped_processes.rs writeln!( @@ -68,5 +78,13 @@ async fn main() -> anyhow::Result<()> { .unwrap(); } writeln!(bootstrapped_processes, "];").unwrap(); + let bootstrapped_processes_path = pwd.join("src/bootstrapped_processes.rs"); + if bootstrapped_processes_path.exists() { + let existing_bootstrapped_processes = fs::read(&bootstrapped_processes_path)?; + if bootstrapped_processes == existing_bootstrapped_processes { + return Ok(()); + } + } + fs::write(&bootstrapped_processes_path, bootstrapped_processes)?; Ok(()) }