Skip to content

Commit

Permalink
Merge pull request #202 from kinode-dao/v0.6.10
Browse files Browse the repository at this point in the history
v0.6.10
  • Loading branch information
nick1udwig authored Aug 9, 2024
2 parents 39275de + 4602148 commit 9e9f87b
Show file tree
Hide file tree
Showing 14 changed files with 147 additions and 63 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kit"
version = "0.6.9"
version = "0.6.10"
edition = "2021"

[build-dependencies]
Expand Down
17 changes: 7 additions & 10 deletions src/boot_fake_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ const LOCAL_PREFIX: &str = "kinode-";
pub const CACHE_EXPIRY_SECONDS: u64 = 300;

#[derive(Deserialize, Debug)]
struct Release {
tag_name: String,
assets: Vec<Asset>,
pub struct Release {
pub tag_name: String,
pub assets: Vec<Asset>,
}

#[derive(Deserialize, Debug)]
struct Asset {
name: String,
pub struct Asset {
pub name: String,
}

#[instrument(level = "trace", skip_all)]
Expand Down Expand Up @@ -254,7 +254,7 @@ pub async fn get_from_github(owner: &str, repo: &str, endpoint: &str) -> Result<
}

#[instrument(level = "trace", skip_all)]
async fn fetch_releases(owner: &str, repo: &str) -> Result<Vec<Release>> {
pub async fn fetch_releases(owner: &str, repo: &str) -> Result<Vec<Release>> {
let bytes = get_from_github(owner, repo, "releases").await?;
if bytes.is_empty() {
return Ok(vec![]);
Expand Down Expand Up @@ -411,10 +411,7 @@ pub async fn execute(
.join(if release { "release" } else { "debug" })
.join("kinode")
} else {
return Err(eyre!(
"--runtime-path {:?} must be a directory (the repo).",
runtime_path,
));
runtime_path
}
}
};
Expand Down
5 changes: 1 addition & 4 deletions src/boot_real_node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ pub async fn execute(
.join(if release { "release" } else { "debug" })
.join("kinode")
} else {
return Err(eyre!(
"--runtime-path {:?} must be a directory (the repo).",
runtime_path,
));
runtime_path
}
}
};
Expand Down
28 changes: 10 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ async fn execute(
Some(f) => f.clone(),
None => "".into(),
};
let url = matches.get_one::<u16>("NODE_PORT")
let url = matches
.get_one::<u16>("NODE_PORT")
.map(|p| format!("http://localhost:{p}"));
let download_from = matches
.get_one::<String>("NODE")
Expand Down Expand Up @@ -226,16 +227,12 @@ async fn execute(
Some(("build-start-package", matches)) => {
let package_dir = PathBuf::from(matches.get_one::<String>("DIR").unwrap());
let no_ui = matches.get_one::<bool>("NO_UI").unwrap();
let ui_only = matches
.get_one::<bool>("UI_ONLY")
.unwrap_or(&false);
let ui_only = matches.get_one::<bool>("UI_ONLY").unwrap_or(&false);
let url = format!(
"http://localhost:{}",
matches.get_one::<u16>("NODE_PORT").unwrap(),
);
let skip_deps_check = matches
.get_one::<bool>("SKIP_DEPS_CHECK")
.unwrap();
let skip_deps_check = matches.get_one::<bool>("SKIP_DEPS_CHECK").unwrap();
let features = match matches.get_one::<String>("FEATURES") {
Some(f) => f.clone(),
None => "".into(),
Expand Down Expand Up @@ -281,12 +278,8 @@ async fn execute(
Some(("connect", matches)) => {
let local_port = matches.get_one::<u16>("LOCAL_PORT").unwrap();
let disconnect = matches.get_one::<bool>("IS_DISCONNECT").unwrap();
let host = matches
.get_one::<String>("HOST")
.map(|s| s.as_ref());
let host_port = matches
.get_one::<u16>("HOST_PORT")
.map(|hp| hp.clone());
let host = matches.get_one::<String>("HOST").map(|s| s.as_ref());
let host_port = matches.get_one::<u16>("HOST_PORT").map(|hp| hp.clone());
connect::execute(*local_port, *disconnect, host, host_port)
}
Some(("dev-ui", matches)) => {
Expand Down Expand Up @@ -344,8 +337,7 @@ async fn execute(
let publisher = matches
.get_one::<String>("PUBLISHER")
.and_then(|s: &String| Some(s.as_str()));
let package_dir =
PathBuf::from(matches.get_one::<String>("DIR").unwrap());
let package_dir = PathBuf::from(matches.get_one::<String>("DIR").unwrap());
let url = format!(
"http://localhost:{}",
matches.get_one::<u16>("NODE_PORT").unwrap(),
Expand Down Expand Up @@ -375,8 +367,7 @@ async fn execute(
setup::execute(*verbose)
}
Some(("start-package", matches)) => {
let package_dir =
PathBuf::from(matches.get_one::<String>("DIR").unwrap());
let package_dir = PathBuf::from(matches.get_one::<String>("DIR").unwrap());
let url = format!(
"http://localhost:{}",
matches.get_one::<u16>("NODE_PORT").unwrap(),
Expand Down Expand Up @@ -910,7 +901,7 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result<Command> {
.short('t')
.long("template")
.help("Template to create")
.value_parser(["chat", "echo", "fibonacci", "file_transfer"])
.value_parser(["blank", "chat", "echo", "fibonacci", "file_transfer"])
.default_value("chat")
)
.arg(Arg::new("UI")
Expand All @@ -932,6 +923,7 @@ async fn make_app(current_dir: &std::ffi::OsString) -> Result<Command> {
)
.arg(Arg::new("PUBLISHER")
.action(ArgAction::Set)
.short('u')
.long("publisher")
.help("Name of the publisher (Overrides DIR)")
.required(false)
Expand Down
5 changes: 4 additions & 1 deletion src/new/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Language {

#[derive(Clone)]
pub enum Template {
Blank,
Chat,
Echo,
Fibonacci,
Expand All @@ -38,6 +39,7 @@ impl Language {
impl Template {
fn to_string(&self) -> String {
match self {
Template::Blank => "blank",
Template::Chat => "chat",
Template::Echo => "echo",
Template::Fibonacci => "fibonacci",
Expand All @@ -61,11 +63,12 @@ impl From<&String> for Language {
impl From<&String> for Template {
fn from(s: &String) -> Self {
match s.as_str() {
"blank" => Template::Blank,
"chat" => Template::Chat,
"echo" => Template::Echo,
"fibonacci" => Template::Fibonacci,
"file_transfer" => Template::FileTransfer,
_ => panic!("kit: template must be 'chat', 'echo', or 'fibonacci'; not '{s}'"),
_ => panic!("kit: template must be 'blank', 'chat', 'echo', or 'fibonacci'; not '{s}'"),
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/new/templates/rust/no-ui/blank/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*/target/
/target
pkg/*.wasm
*.swp
*.swo
*/wasi_snapshot_preview1.wasm
*/wit/
*/process_env
10 changes: 10 additions & 0 deletions src/new/templates/rust/no-ui/blank/Cargo.toml_
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[workspace]
resolver = "2"
members = [
"{package_name}",
]

[profile.release]
panic = "abort"
opt-level = "s"
lto = true
18 changes: 18 additions & 0 deletions src/new/templates/rust/no-ui/blank/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "{package_name}",
"description": "",
"image": "",
"properties": {
"package_name": "{package_name}",
"current_version": "0.1.0",
"publisher": "{publisher}",
"mirrors": [],
"code_hashes": {
"0.1.0": ""
},
"wit_version": 0,
"dependencies": []
},
"external_url": "",
"animation_url": ""
}
11 changes: 11 additions & 0 deletions src/new/templates/rust/no-ui/blank/pkg/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{
"process_name": "{package_name}",
"process_wasm_path": "/{package_name}.wasm",
"on_exit": "Restart",
"request_networking": false,
"request_capabilities": [],
"grant_capabilities": [],
"public": false
}
]
16 changes: 16 additions & 0 deletions src/new/templates/rust/no-ui/blank/{package_name}/Cargo.toml_
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
name = "{package_name}"
version = "0.1.0"
edition = "2021"

[dependencies]
kinode_process_lib = "0.8.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
wit-bindgen = "0.24.0"

[lib]
crate-type = ["cdylib"]

[package.metadata.component]
package = "kinode:process"
16 changes: 16 additions & 0 deletions src/new/templates/rust/no-ui/blank/{package_name}/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use kinode_process_lib::{await_message, call_init, Address};

wit_bindgen::generate!({
path: "target/wit",
world: "process-v0",
});

call_init!(init);
fn init(_our: Address) {
loop {
match await_message() {
Err(send_error) => println!("got SendError: {send_error}"),
Ok(message) => println!("got Message: {message:?}"),
}
}
}
69 changes: 43 additions & 26 deletions src/run_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ fn expand_home_path(path: &PathBuf) -> Option<PathBuf> {
path.as_os_str()
.to_str()
.and_then(|s| expand_home_path_string(s))
.and_then(|s| Some(Path::new(&s).to_path_buf()))
.map(|s| PathBuf::from(&s))
}

#[instrument(level = "trace", skip_all)]
Expand Down Expand Up @@ -275,7 +275,12 @@ async fn build_packages(
.dependency_package_paths
.iter()
.cloned()
.map(|p| test_dir_path.join(p).canonicalize().unwrap())
.map(|p| {
match expand_home_path(&p) {
Some(p) => p,
None => test_dir_path.join(&p).canonicalize().unwrap(),
}
})
.collect();
let setup_packages: Vec<SetupPackage> = test
.setup_packages
Expand Down Expand Up @@ -340,7 +345,10 @@ async fn build_packages(
let url = format!("http://localhost:{port}");

for dependency_package_path in &test.dependency_package_paths {
let path = test_dir_path.join(&dependency_package_path).canonicalize()?;
let path = match expand_home_path(&dependency_package_path) {
Some(p) => p,
None => test_dir_path.join(&dependency_package_path).canonicalize()?,
};
build::execute(
&path,
false,
Expand Down Expand Up @@ -468,25 +476,37 @@ async fn load_setups(setup_paths: &Vec<SetupPackage>, port: u16) -> Result<()> {

#[instrument(level = "trace", skip_all)]
async fn load_process(path: &Path, drive: &str, port: &u16) -> Result<()> {
let basename = get_basename(path).unwrap();
let request = inject_message::make_message(
"vfs:distro:sys",
Some(15),
&serde_json::to_string(&serde_json::json!({
"path": format!("/tester:sys/{drive}/{basename}.wasm"),
"action": "Write",
}))
.unwrap(),
None,
None,
path.join("pkg").join(format!("{basename}.wasm")).to_str(),
)?;

let response =
inject_message::send_request(&format!("http://localhost:{}", port), request).await?;
match inject_message::parse_response(response).await {
Ok(_) => {}
Err(e) => return Err(eyre!("Failed to load test {path:?}: {}", e)),
for entry in path.join("pkg").read_dir()? {
let entry = entry?;
let path = entry.path();
if Some("wasm") == path.extension().and_then(|s| s.to_str()) {
println!("include path {:?}", path);
let file_name = path
.file_name()
.and_then(|s| s.to_str())
.unwrap_or_default();
let request = inject_message::make_message(
"vfs:distro:sys",
Some(15),
&serde_json::to_string(&serde_json::json!({
"path": format!("/tester:sys/{drive}/{file_name}"),
"action": "Write",
}))
.unwrap(),
None,
None,
path.to_str(),
)?;

let response = inject_message::send_request(
&format!("http://localhost:{}", port),
request,
).await?;
match inject_message::parse_response(response).await {
Ok(_) => {}
Err(e) => return Err(eyre!("Failed to load test {path:?}: {}", e)),
}
}
}
Ok(())
}
Expand Down Expand Up @@ -768,10 +788,7 @@ pub async fn execute(config_path: PathBuf) -> Result<()> {
})
.join("kinode")
} else {
return Err(eyre!(
"RepoPath {:?} must be a directory (the repo).",
runtime_path
));
runtime_path
}
}
};
Expand Down
3 changes: 1 addition & 2 deletions src/start_package/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ pub async fn execute(package_dir: &Path, url: &str) -> Result<()> {
info!("{}", pkg_publisher);

// Create zip and put it in /target
let parent_dir = pkg_dir.parent().unwrap();
let target_dir = parent_dir.join("target");
let target_dir = package_dir.join("target");
fs::create_dir_all(&target_dir)?;
let zip_filename = target_dir.join(&pkg_publisher).with_extension("zip");
zip_directory(&pkg_dir, &zip_filename.to_str().unwrap())?;
Expand Down

0 comments on commit 9e9f87b

Please sign in to comment.