Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
469 changes: 215 additions & 254 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions kinode/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ path = "src/main.rs"

[build-dependencies]
anyhow = "1.0.71"
kit = { git = "https://github.com/kinode-dao/kit", rev = "0c43430" }
reqwest = { version = "0.11.22", features = ["blocking"] }
kit = { git = "https://github.com/kinode-dao/kit", rev = "f96cdaa" }
rayon = "1.8.1"
sha2 = "0.10"
tokio = { version = "1.28", features = ["macros"] }
tokio = "1.28"
walkdir = "2.4"
zip = "0.6"

Expand Down Expand Up @@ -82,6 +82,6 @@ tokio-tungstenite = "0.20.1"
url = "2.4.1"
uuid = { version = "1.1.2", features = ["serde", "v4"] }
warp = "0.3.5"
wasmtime = "15.0.1"
wasmtime-wasi = "15.0.1"
wasmtime = "17.0.1"
wasmtime-wasi = "17.0.1"
zip = "0.6"
137 changes: 71 additions & 66 deletions kinode/build.rs
Original file line number Diff line number Diff line change
@@ -1,91 +1,96 @@
use rayon::prelude::*;
use std::{
fs,
fs::{self, File},
io::{Cursor, Read, Write},
path::{Path, PathBuf},
};
use zip::write::FileOptions;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
if std::env::var("SKIP_BUILD_SCRIPT").is_ok() {
println!("Skipping build script");
return Ok(());
}

let pwd = std::env::current_dir().unwrap();
let parent_dir = pwd.parent().unwrap();

// Build wasm32-wasi apps, zip, and add to bootstrapped_processes.rs
let mut bootstrapped_processes = Vec::new();
writeln!(
bootstrapped_processes,
"pub static BOOTSTRAPPED_PROCESSES: &[(&str, &[u8], &[u8])] = &[",
)
.unwrap();
let packages_dir = format!("{}/packages", pwd.display());
eprintln!("{packages_dir:?}");
for entry in std::fs::read_dir(packages_dir).unwrap() {
let entry_path = entry.unwrap().path();
let metadata_path = format!("{}/metadata.json", entry_path.display());
let parent_pkg_path = format!("{}/pkg", entry_path.display());

fn build_and_zip_package(
entry_path: PathBuf,
parent_pkg_path: &str,
) -> anyhow::Result<(String, String, Vec<u8>)> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
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 = FileOptions::default()
.compression_method(zip::CompressionMethod::Stored)
.unix_permissions(0o755);
{
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();

for sub_entry in walkdir::WalkDir::new(parent_pkg_path) {
let sub_entry = sub_entry?;
let path = sub_entry.path();
let name = path
.strip_prefix(std::path::Path::new(&parent_pkg_path))
.unwrap();
let name = path.strip_prefix(Path::new(parent_pkg_path))?;

// 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();
zip.start_file(name.to_string_lossy(), options)?;
let mut file = File::open(path)?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer).unwrap();
zip.write_all(&buffer).unwrap();
file.read_to_end(&mut buffer)?;
zip.write_all(&buffer)?;
} else if !name.as_os_str().is_empty() {
zip.add_directory(name.to_string_lossy().into_owned(), options)
.unwrap();
zip.add_directory(name.to_string_lossy(), options)?;
}
}
zip.finish().unwrap();
zip.finish()?;
}

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);
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)?;
let zip_filename = format!("{}.zip", entry_path.file_name().unwrap().to_str().unwrap());
Ok((entry_path.display().to_string(), zip_filename, zip_contents))
})
}

fn main() -> anyhow::Result<()> {
let pwd = std::env::current_dir()?;
let parent_dir = pwd.parent().unwrap();
let packages_dir = pwd.join("packages");

let entries: Vec<_> = fs::read_dir(packages_dir)?
.map(|entry| entry.unwrap().path())
.collect();

let results: Vec<anyhow::Result<(String, String, Vec<u8>)>> = entries
.par_iter()
.map(|entry_path| {
let parent_pkg_path = entry_path.join("pkg");
build_and_zip_package(entry_path.clone(), parent_pkg_path.to_str().unwrap())
})
.collect();

// Process results, e.g., write to `bootstrapped_processes.rs`
// This part remains sequential
let mut bootstrapped_processes = vec![];
writeln!(
bootstrapped_processes,
"pub static BOOTSTRAPPED_PROCESSES: &[(&str, &[u8], &[u8])] = &["
)?;

for result in results {
match result {
Ok((entry_path, zip_filename, zip_contents)) => {
// Further processing, like saving ZIP files and updating bootstrapped_processes
let metadata_path = format!("{}/metadata.json", entry_path);
let zip_path = format!("{}/target/{}", parent_dir.display(), zip_filename);
fs::write(&zip_path, &zip_contents)?;

writeln!(
bootstrapped_processes,
" (\"{}\", include_bytes!(\"{}\"), include_bytes!(\"{}\")),",
zip_filename, metadata_path, zip_path,
)?;
}
Err(e) => return Err(e),
}

// Add zip bytes to bootstrapped_processes.rs
writeln!(
bootstrapped_processes,
" (\"{}\", include_bytes!(\"{}\"), include_bytes!(\"{}\")),",
zip_filename, metadata_path, zip_path,
)
.unwrap();
}
writeln!(bootstrapped_processes, "];").unwrap();

writeln!(bootstrapped_processes, "];")?;
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(())
}
4 changes: 2 additions & 2 deletions kinode/packages/app_store/app_store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ alloy-primitives = "0.6.2"
alloy-sol-types = "0.6.2"
anyhow = "1.0"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "d7511c2" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "3232423" }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sha2 = "0.10.8"
sha3 = "0.10.8"
url = "2.4.1"
urlencoding = "2.1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }
zip = { version = "0.6.6", default-features = false }

[lib]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/app_store/download/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/app_store/ft_worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
rand = "0.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/app_store/install/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/app_store/uninstall/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/chess/chess/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ edition = "2021"
anyhow = "1.0"
base64 = "0.13"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
pleco = "0.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
url = "*"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/homepage/homepage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/kns_indexer/kns_indexer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ alloy-primitives = "0.6.2"
alloy-sol-types = "0.6.2"
bincode = "1.3.3"
hex = "0.4.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "d7511c2" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "3232423" }
rmp-serde = "1.1.2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/terminal/alias/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/terminal/cat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/terminal/echo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/terminal/hi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ edition = "2021"


[dependencies]
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/terminal/m/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
clap = "4.4.18"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
regex = "1.10.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/terminal/terminal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
bincode = "1.3.3"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.6.0-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
rand = "0.8"
regex = "1.10.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
4 changes: 2 additions & 2 deletions kinode/packages/terminal/top/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ edition = "2021"

[dependencies]
anyhow = "1.0"
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", tag = "v0.5.9-alpha" }
kinode_process_lib = { git = "https://github.com/kinode-dao/process_lib", rev = "12bf9ee" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "efcc759" }
wit-bindgen = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "21a46c7" }

[lib]
crate-type = ["cdylib"]
Expand Down
Loading