From 82806e66f2d592c15f674f6191591d73c927b06c Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Wed, 11 Sep 2024 20:18:43 -0700 Subject: [PATCH 01/17] add testing workflow --- .github/workflows/mdbook.yml | 48 ++++++++ src/new/templates/tests.toml | 207 +++++++++++++++++++++++++++++++++++ 2 files changed, 255 insertions(+) create mode 100644 .github/workflows/mdbook.yml create mode 100644 src/new/templates/tests.toml diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml new file mode 100644 index 00000000..2eb5d6f5 --- /dev/null +++ b/.github/workflows/mdbook.yml @@ -0,0 +1,48 @@ +name: Deploy kit Create Release + +on: + # Runs on pushes targeting the default branch + push: + branches: ["main", "v0.7.4"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + build_and_test: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Build the release + run: ./scripts/build-release.py + - name: Unzip the build output + run: unzip /tmp/kit-release/kit-x86_64-unknown-linux-gnu.zip + + #- name: Get latest release from kinode-dao/kit + # id: get-latest-kinode-release + # uses: actions/github-script@v6 + # with: + # script: | + # const repo = { + # owner: 'kinode-dao', + # repo: 'kinode', + # }; + # const release = await github.rest.repos.getLatestRelease(repo); + # const asset = release.data.assets.find(asset => asset.name.match(/kinode-x86_64-unknown-linux-gnu\.zip/)); + # if (!asset) { + # throw new Error('Asset not found'); + # } + # return asset.browser_download_url; + # result-encoding: string + - name: Download the Kinode release + run: wget -q https://files.yael.solutions/240906/kinode-x86_64-unknown-linux-gnu-simulation-mode.zip -O kinode.zip + #run: wget -q ${DOWNLOAD_URL} -O kinode.zip + #env: + # DOWNLOAD_URL: ${{ steps.get-latest-kinode-release.outputs.result }} + - name: Unzip the Kinode release + run: unzip kinode.zip + + - name: Run tests + run: ./kit t src/new/templates/test.toml diff --git a/src/new/templates/tests.toml b/src/new/templates/tests.toml new file mode 100644 index 00000000..83b9bab1 --- /dev/null +++ b/src/new/templates/tests.toml @@ -0,0 +1,207 @@ +# runtime = { FetchVersion = "latest" } +runtime = { RepoPath = "../../../kinode" } +persist_home = false +runtime_build_release = false + + +# [[tests]] +# dependency_package_paths = ["javascript/no-ui/chat"] +# setup_packages = [ +# { path = "javascript/no-ui/chat", run = true } +# ] +# setup_scripts = [] +# test_package_paths = ["javascript/no-ui/chat/test/chat_test"] +# test_scripts = [] +# timeout_secs = 5 +# fakechain_router = 8545 +# +# [[tests.nodes]] +# port = 8080 +# home = "home/first" +# fake_node_name = "first.dev" +# runtime_verbosity = 2 +# +# [[tests.nodes]] +# port = 8081 +# home = "home/second" +# fake_node_name = "second.dev" +# runtime_verbosity = 2 +# +# +# [[tests]] +# dependency_package_paths = [] +# setup_packages = [ +# { path = "javascript/no-ui/echo", run = true } +# ] +# setup_scripts = [] +# test_package_paths = ["javascript/no-ui/echo/test/echo_test"] +# test_scripts = [] +# timeout_secs = 5 +# fakechain_router = 8545 +# +# [[tests.nodes]] +# port = 8080 +# home = "home/first" +# fake_node_name = "first.dev" +# runtime_verbosity = 2 +# +# +# [[tests]] +# dependency_package_paths = ["javascript/no-ui/fibonacci"] +# setup_packages = [ +# { path = "javascript/no-ui/fibonacci", run = true } +# ] +# setup_scripts = [] +# test_package_paths = ["javascript/no-ui/fibonacci/test/fibonacci_test"] +# test_scripts = [] +# timeout_secs = 5 +# fakechain_router = 8545 +# +# [[tests.nodes]] +# port = 8080 +# home = "home/first" +# fake_node_name = "first.dev" +# runtime_verbosity = 2 +# +# +# [[tests]] +# dependency_package_paths = ["python/no-ui/chat"] +# setup_packages = [ +# { path = "python/no-ui/chat", run = true } +# ] +# setup_scripts = [] +# test_package_paths = ["python/no-ui/chat/test/chat_test"] +# test_scripts = [] +# timeout_secs = 5 +# fakechain_router = 8545 +# +# [[tests.nodes]] +# port = 8080 +# home = "home/first" +# fake_node_name = "first.dev" +# runtime_verbosity = 2 +# +# [[tests.nodes]] +# port = 8081 +# home = "home/second" +# fake_node_name = "second.dev" +# runtime_verbosity = 2 +# +# +# [[tests]] +# dependency_package_paths = [] +# setup_packages = [ +# { path = "python/no-ui/echo", run = true } +# ] +# setup_scripts = [] +# test_package_paths = ["python/no-ui/echo/test/echo_test"] +# test_scripts = [] +# timeout_secs = 5 +# fakechain_router = 8545 +# +# [[tests.nodes]] +# port = 8080 +# home = "home/first" +# fake_node_name = "first.dev" +# runtime_verbosity = 2 +# +# +# [[tests]] +# dependency_package_paths = ["python/no-ui/fibonacci"] +# setup_packages = [ +# { path = "python/no-ui/fibonacci", run = true } +# ] +# setup_scripts = [] +# test_package_paths = ["python/no-ui/fibonacci/test/fibonacci_test"] +# test_scripts = [] +# timeout_secs = 5 +# fakechain_router = 8545 +# +# [[tests.nodes]] +# port = 8080 +# home = "home/first" +# fake_node_name = "first.dev" +# runtime_verbosity = 2 + + +[[tests]] +dependency_package_paths = ["rust/no-ui/chat"] +setup_packages = [ + { path = "rust/no-ui/chat", run = true } +] +setup_scripts = [] +test_package_paths = ["rust/no-ui/chat/test/chat_test"] +test_scripts = [] +timeout_secs = 5 +fakechain_router = 8545 + +[[tests.nodes]] +port = 8080 +home = "home/first" +fake_node_name = "first.dev" +runtime_verbosity = 2 + +[[tests.nodes]] +port = 8081 +home = "home/second" +fake_node_name = "second.dev" +runtime_verbosity = 2 + + +[[tests]] +dependency_package_paths = [] +setup_packages = [ + { path = "rust/no-ui/echo", run = true } +] +setup_scripts = [] +test_package_paths = ["rust/no-ui/echo/test/echo_test"] +test_scripts = [] +timeout_secs = 5 +fakechain_router = 8545 + +[[tests.nodes]] +port = 8080 +home = "home/first" +fake_node_name = "first.dev" +runtime_verbosity = 2 + + +[[tests]] +dependency_package_paths = ["rust/no-ui/fibonacci"] +setup_packages = [ + { path = "rust/no-ui/fibonacci", run = true } +] +setup_scripts = [] +test_package_paths = ["rust/no-ui/fibonacci/test/fibonacci_test"] +test_scripts = [] +timeout_secs = 5 +fakechain_router = 8545 + +[[tests.nodes]] +port = 8080 +home = "home/first" +fake_node_name = "first.dev" +runtime_verbosity = 2 + + +# [[tests]] +# setup_packages = [ +# { path = "rust/no-ui/file_transfer", run = true } +# ] +# setup_scripts = [] +# test_package_paths = ["rust/no-ui/file_transfer/test/file_transfer_test"] +# test_scripts = [] +# timeout_secs = 5 +# fakechain_router = 8545 +# +# [[tests.nodes]] +# port = 8080 +# home = "home/first" +# fake_node_name = "first.dev" +# runtime_verbosity = 2 +# +# [[tests.nodes]] +# port = 8081 +# home = "home/second" +# fake_node_name = "second.dev" +# runtime_verbosity = 2 From 631bef410a8b1500b6c317a37f13b11194c2f88f Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Wed, 11 Sep 2024 20:27:57 -0700 Subject: [PATCH 02/17] add some debugging prints --- .github/workflows/mdbook.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index 2eb5d6f5..108f2cca 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -45,4 +45,7 @@ jobs: run: unzip kinode.zip - name: Run tests - run: ./kit t src/new/templates/test.toml + run: | + pwd + ls -la + ./kit t src/new/templates/test.toml From bdc351b6139bc810cdf4a5bc58d6da2cde3aa1d2 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Wed, 11 Sep 2024 20:34:28 -0700 Subject: [PATCH 03/17] fix the workflow --- .github/workflows/mdbook.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index 108f2cca..f96a4631 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -45,7 +45,4 @@ jobs: run: unzip kinode.zip - name: Run tests - run: | - pwd - ls -la - ./kit t src/new/templates/test.toml + run: ./kit t src/new/templates/tests.toml From 8747bc910b489f493be1f9a1902b0b744c2d3f1b Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Wed, 11 Sep 2024 20:44:01 -0700 Subject: [PATCH 04/17] add deps to workflow --- .github/workflows/mdbook.yml | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index f96a4631..b05d92de 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -13,6 +13,63 @@ jobs: runs-on: ubuntu-latest steps: + - name: Set up nvm, node, npm p0 + run: | + echo "$HOME" >> $GITHUB_PATH + echo "NVM_DIR=$HOME/.nvm" >> $GITHUB_ENV + - name: Set up nvm, node, npm p1 + run: | + source $NVM_DIR/nvm.sh + nvm install 20.0.0 + nvm --version + - name: Set up cargo + run: | + curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf -y | sh + rustup update + cargo install wasm-tools + rustup install nightly + rustup target add wasm32-wasi + rustup target add wasm32-wasi --toolchain nightly + cargo install cargo-wasi + #- name: Get latest release from foundry-rs/foundry + # id: get-latest-foundry-release + # uses: actions/github-script@v6 + # with: + # script: | + # const repo = { + # owner: 'foundry-rs', + # repo: 'foundry', + # per_page: 1, + # page: 1, + # }; + # const releases = await github.rest.repos.listReleases(repo); + # const preReleases = releases.data.filter(release => release.prerelease); + + # // Sort pre-releases by created_at date in descending order + # preReleases.sort((a, b) => new Date(b.created_at) - new Date(a.created_at)); + + # if (preReleases.length === 0) { + # throw new Error('No pre-releases found'); + # } + + # const latestPreRelease = preReleases[0]; + # const asset = latestPreRelease.assets.find(asset => asset.name.match(/foundry_nightly_linux_amd64\.tar\.gz/)); + + # if (!asset) { + # throw new Error('Asset not found'); + # } + # return asset.browser_download_url; + # result-encoding: string + - name: Download the Foundry release + run: wget -q https://github.com/foundry-rs/foundry/releases/download/nightly-de596a4db781933f0c95805bd1c8c05e65f03d4f/foundry_nightly_linux_amd64.tar.gz -O foundry.tar.gz + #run: wget -q ${DOWNLOAD_URL} -O foundry.tar.gz + #env: + # DOWNLOAD_URL: ${{ steps.get-latest-foundry-release.outputs.result }} + - name: Untar the release + run: tar zxf foundry.tar.gz + - name: Add Foundry to path + run: echo "$PWD" >> $GITHUB_PATH + - name: Check out repository uses: actions/checkout@v3 - name: Build the release From 6bb32813b5a55a75b4c95a32061fcb4b91759a9a Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Wed, 11 Sep 2024 20:59:41 -0700 Subject: [PATCH 05/17] add debugging prints --- .github/workflows/mdbook.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index b05d92de..4d3fedf7 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -13,6 +13,8 @@ jobs: runs-on: ubuntu-latest steps: + - name: Check out repository + uses: actions/checkout@v3 - name: Set up nvm, node, npm p0 run: | echo "$HOME" >> $GITHUB_PATH @@ -70,8 +72,6 @@ jobs: - name: Add Foundry to path run: echo "$PWD" >> $GITHUB_PATH - - name: Check out repository - uses: actions/checkout@v3 - name: Build the release run: ./scripts/build-release.py - name: Unzip the build output @@ -102,4 +102,9 @@ jobs: run: unzip kinode.zip - name: Run tests - run: ./kit t src/new/templates/tests.toml + run: | + pwd + ls -la + echo $PATHA + echo $NVM_DIR + { ./kit t src/new/templates/tests.toml; } 2>&1 From 4c85bf8c80de8ec3aab1ebc4129f3cca16f615e0 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Wed, 11 Sep 2024 21:17:59 -0700 Subject: [PATCH 06/17] update when to run workflow --- .github/workflows/mdbook.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index 4d3fedf7..fb7650b0 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -1,9 +1,9 @@ name: Deploy kit Create Release on: - # Runs on pushes targeting the default branch + # Runs on pushes targeting prod or dev branches push: - branches: ["main", "v0.7.4"] + branches: ["master", "v*"] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: From 53ffc46989eaa472e871240f5e421e70f6aaef22 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Wed, 11 Sep 2024 21:18:40 -0700 Subject: [PATCH 07/17] remove debugging prints --- .github/workflows/mdbook.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index fb7650b0..9e67935f 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -103,8 +103,4 @@ jobs: - name: Run tests run: | - pwd - ls -la - echo $PATHA - echo $NVM_DIR { ./kit t src/new/templates/tests.toml; } 2>&1 From ee58b272413b11a654d1bdb682c0ec4d9f0f5826 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Thu, 12 Sep 2024 14:52:50 -0700 Subject: [PATCH 08/17] build,setup: use wasm32-wasip1 target --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/build/mod.rs | 4 ++-- src/setup/mod.rs | 14 +++++++------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d2cfb1e4..9d5041a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2099,7 +2099,7 @@ dependencies = [ [[package]] name = "kit" -version = "0.7.3" +version = "0.7.4" dependencies = [ "alloy", "alloy-sol-macro", diff --git a/Cargo.toml b/Cargo.toml index 5e6c6143..4fa27552 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kit" -version = "0.7.3" +version = "0.7.4" edition = "2021" [build-dependencies] diff --git a/src/build/mod.rs b/src/build/mod.rs index d9da5a2a..7be3dcdc 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -602,7 +602,7 @@ async fn compile_rust_wasm_process( "--release", "--no-default-features", "--target", - "wasm32-wasi", + "wasm32-wasip1", "--target-dir", "target", "--color=always", @@ -649,7 +649,7 @@ async fn compile_rust_wasm_process( .unwrap() .replace("-", "_"); - let wasm_file_prefix = Path::new("target/wasm32-wasi/release"); + let wasm_file_prefix = Path::new("target/wasm32-wasip1/release"); let wasm_file = wasm_file_prefix.join(&format!("{}.wasm", wasm_file_name)); let wasm_path = format!("../pkg/{}.wasm", wasm_file_name); diff --git a/src/setup/mod.rs b/src/setup/mod.rs index 26697281..8d221639 100644 --- a/src/setup/mod.rs +++ b/src/setup/mod.rs @@ -43,8 +43,8 @@ impl std::fmt::Display for Dependency { Dependency::Node => write!(f, "node {}.{}", REQUIRED_NODE_MAJOR, MINIMUM_NODE_MINOR), Dependency::Rust => write!(f, "rust"), Dependency::RustNightly => write!(f, "rust nightly"), - Dependency::RustWasm32Wasi => write!(f, "rust wasm32-wasi target"), - Dependency::RustNightlyWasm32Wasi => write!(f, "rust nightly wasm32-wasi target"), + Dependency::RustWasm32Wasi => write!(f, "rust wasm32-wasip1 target"), + Dependency::RustNightlyWasm32Wasi => write!(f, "rust nightly wasm32-wasip1 target"), Dependency::WasmTools => write!(f, "wasm-tools"), } } @@ -272,7 +272,7 @@ fn check_rust_toolchains_targets() -> Result> { let has_wasm32_wasi = output .split('\n') - .fold(false, |acc, item| acc || item == "wasm32-wasi"); + .fold(false, |acc, item| acc || item == "wasm32-wasip1"); if !has_wasm32_wasi { missing_deps.push(Dependency::RustWasm32Wasi); } @@ -287,7 +287,7 @@ fn check_rust_toolchains_targets() -> Result> { Dependency::RustNightlyWasm32Wasi, ]); } else { - // check for nightly wasm32-wasi + // check for nightly wasm32-wasip1 run_command( Command::new("rustup") .args(&["default", "nightly"]) @@ -300,7 +300,7 @@ fn check_rust_toolchains_targets() -> Result> { let has_wasm32_wasi = output .split('\n') - .fold(false, |acc, item| acc || item == "wasm32-wasi"); + .fold(false, |acc, item| acc || item == "wasm32-wasip1"); if !has_wasm32_wasi { missing_deps.push(Dependency::RustNightlyWasm32Wasi); } @@ -468,9 +468,9 @@ pub fn get_deps(deps: Vec, verbose: bool) -> Result<()> { )?, Dependency::Rust => install_rust(verbose)?, Dependency::RustNightly => call_rustup("install nightly", verbose)?, - Dependency::RustWasm32Wasi => call_rustup("target add wasm32-wasi", verbose)?, + Dependency::RustWasm32Wasi => call_rustup("target add wasm32-wasip1", verbose)?, Dependency::RustNightlyWasm32Wasi => { - call_rustup("target add wasm32-wasi --toolchain nightly", verbose)? + call_rustup("target add wasm32-wasip1 --toolchain nightly", verbose)? } Dependency::WasmTools => call_cargo("install wasm-tools", verbose)?, Dependency::Forge | Dependency::Anvil => install_foundry()?, From 917ebb069e30752391747cae9bc059706c83a537 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Thu, 12 Sep 2024 15:47:12 -0700 Subject: [PATCH 09/17] rename workflow files --- .github/workflows/{mdbook.yml => build_and_test.yml} | 0 .github/{main.yml => workflows/rustfmt.yml} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{mdbook.yml => build_and_test.yml} (100%) rename .github/{main.yml => workflows/rustfmt.yml} (100%) diff --git a/.github/workflows/mdbook.yml b/.github/workflows/build_and_test.yml similarity index 100% rename from .github/workflows/mdbook.yml rename to .github/workflows/build_and_test.yml diff --git a/.github/main.yml b/.github/workflows/rustfmt.yml similarity index 100% rename from .github/main.yml rename to .github/workflows/rustfmt.yml From d93645a709d4d55f5ddd2966dbaf1098d5b96f18 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 12 Sep 2024 22:47:36 +0000 Subject: [PATCH 10/17] Format Rust code using rustfmt --- src/build/mod.rs | 141 +++++++++++++++++++++------------------ src/main.rs | 7 +- src/publish/mod.rs | 119 ++++++++++++++------------------- src/run_tests/cleanup.rs | 4 +- src/run_tests/mod.rs | 40 +++++------ src/start_package/mod.rs | 29 +++++--- src/view_api/mod.rs | 54 ++++++++++----- 7 files changed, 202 insertions(+), 192 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 7be3dcdc..fbe8c5d2 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -18,7 +18,7 @@ use tracing::{debug, info, instrument, warn}; use walkdir::WalkDir; use zip::write::FileOptions; -use kinode_process_lib::{PackageId, kernel_types::Erc721Metadata}; +use kinode_process_lib::{kernel_types::Erc721Metadata, PackageId}; use crate::setup::{ check_js_deps, check_py_deps, check_rust_deps, get_deps, get_newest_valid_node_version, @@ -58,7 +58,10 @@ pub fn make_pkg_publisher(metadata: &Erc721Metadata) -> String { } pub fn make_zip_filename(package_dir: &Path, pkg_publisher: &str) -> PathBuf { - let zip_filename = package_dir.join("target").join(pkg_publisher).with_extension("zip"); + let zip_filename = package_dir + .join("target") + .join(pkg_publisher) + .with_extension("zip"); zip_filename } @@ -132,10 +135,7 @@ pub fn has_feature(cargo_toml_path: &str, feature: &str) -> Result { } #[instrument(level = "trace", skip_all)] -pub fn remove_missing_features( - cargo_toml_path: &Path, - features: Vec<&str>, -) -> Result> { +pub fn remove_missing_features(cargo_toml_path: &Path, features: Vec<&str>) -> Result> { let cargo_toml_content = fs::read_to_string(cargo_toml_path)?; let cargo_toml: toml::Value = cargo_toml_content.parse()?; let Some(cargo_features) = cargo_toml.get("features").and_then(|f| f.as_table()) else { @@ -152,8 +152,7 @@ pub fn remove_missing_features( None } }) - .collect() - ) + .collect()) } /// Check if the first element is empty and there are no more elements @@ -207,8 +206,7 @@ pub async fn download_file(url: &str, path: &Path) -> Result<()> { let mut hasher = Sha256::new(); hasher.update(url.as_bytes()); let hashed_url = hasher.finalize(); - let hashed_url_path = Path::new(KIT_CACHE) - .join(format!("{hashed_url:x}")); + let hashed_url_path = Path::new(KIT_CACHE).join(format!("{hashed_url:x}")); let content = if hashed_url_path.exists() { fs::read(hashed_url_path)? @@ -339,7 +337,10 @@ fn parse_version_from_url(url: &str) -> Result { let re = regex::Regex::new(r"\?tag=v([0-9]+\.[0-9]+\.[0-9]+)$").unwrap(); if let Some(caps) = re.captures(url) { if let Some(version) = caps.get(1) { - return Ok(semver::VersionReq::parse(&format!("^{}", version.as_str()))?); + return Ok(semver::VersionReq::parse(&format!( + "^{}", + version.as_str() + ))?); } } Err(eyre!("No valid version found in the URL")) @@ -389,19 +390,19 @@ fn check_process_lib_version(cargo_toml_path: &Path) -> Result<()> { .collect(); let versions = find_crate_versions(KINODE_PROCESS_LIB_CRATE_NAME, &packages)?; if versions.len() > 1 { - return Err( - eyre!( - "Found different versions of {} in different crates:{}", - KINODE_PROCESS_LIB_CRATE_NAME, - versions.iter().fold(String::new(), |s, (version, crates)| { - format!("{s}\n{version}\t{crates:?}") - }) - ) - .with_suggestion(|| format!( + return Err(eyre!( + "Found different versions of {} in different crates:{}", + KINODE_PROCESS_LIB_CRATE_NAME, + versions.iter().fold(String::new(), |s, (version, crates)| { + format!("{s}\n{version}\t{crates:?}") + }) + ) + .with_suggestion(|| { + format!( "Set all {} versions to be the same to avoid hard-to-debug errors.", KINODE_PROCESS_LIB_CRATE_NAME, - )) - ); + ) + })); } Ok(()) } @@ -420,16 +421,25 @@ fn get_most_recent_modified_time( let entry = entry?; let path = entry.path(); - let file_name = path.file_name().unwrap_or_default().to_str().unwrap_or_default(); + let file_name = path + .file_name() + .unwrap_or_default() + .to_str() + .unwrap_or_default(); if exclude_files.contains(file_name) { let file_time = get_file_modified_time(&path)?; - most_recent_excluded = Some(most_recent_excluded.map_or(file_time, |t| t.max(file_time))); + most_recent_excluded = + Some(most_recent_excluded.map_or(file_time, |t| t.max(file_time))); continue; } if path.is_dir() { - let dir_name = path.file_name().unwrap_or_default().to_str().unwrap_or_default(); + let dir_name = path + .file_name() + .unwrap_or_default() + .to_str() + .unwrap_or_default(); if exclude_dirs.contains(dir_name) { continue; } @@ -451,7 +461,8 @@ fn get_most_recent_modified_time( if let Some(extension) = path.extension() { if exclude_extensions.contains(&extension.to_str().unwrap_or_default()) { let file_time = get_file_modified_time(&path)?; - most_recent_excluded = Some(most_recent_excluded.map_or(file_time, |t| t.max(file_time))); + most_recent_excluded = + Some(most_recent_excluded.map_or(file_time, |t| t.max(file_time))); continue; } } @@ -614,12 +625,12 @@ async fn compile_rust_wasm_process( } else { features.len() }; - let features = remove_missing_features( - &process_dir.join("Cargo.toml"), - features, - )?; + let features = remove_missing_features(&process_dir.join("Cargo.toml"), features)?; if !test_only && original_length != features.len() { - info!("process {:?} missing features; using {:?}", process_dir, features); + info!( + "process {:?} missing features; using {:?}", + process_dir, features + ); }; let features = features.join(","); if !features.is_empty() { @@ -879,18 +890,16 @@ async fn fetch_dependencies( url.clone(), download_from, default_world, - vec![], // TODO: what about deps-of-deps? + vec![], // TODO: what about deps-of-deps? vec![], force, verbose, true, - )).await { + )) + .await + { debug!("Failed to build self as dependency: {e:?}"); - } else if let Err(e) = fetch_local_built_dependency( - apis, - wasm_paths, - package_dir, - ) { + } else if let Err(e) = fetch_local_built_dependency(apis, wasm_paths, package_dir) { debug!("Failed to fetch self as dependency: {e:?}"); }; let canon_package_dir = package_dir.canonicalize()?; @@ -915,7 +924,8 @@ async fn fetch_dependencies( force, verbose, false, - )).await?; + )) + .await?; fetch_local_built_dependency(apis, wasm_paths, &local_dependency)?; } let Some(ref url) = url else { @@ -935,13 +945,9 @@ async fn fetch_dependencies( if local_dependencies.contains(dep.package()) { continue; } - let Some(zip_dir) = view_api::execute( - None, - Some(dependency), - url, - download_from, - false, - ).await? else { + let Some(zip_dir) = + view_api::execute(None, Some(dependency), url, download_from, false).await? + else { return Err(eyre!( "Got unexpected result from fetching API for {dependency}" )); @@ -968,12 +974,14 @@ async fn fetch_dependencies( fn extract_imports_exports_from_wit(input: &str) -> (Vec, Vec) { let import_re = regex::Regex::new(r"import\s+([^\s;]+)").unwrap(); let export_re = regex::Regex::new(r"export\s+([^\s;]+)").unwrap(); - let imports: Vec = import_re.captures_iter(input) + let imports: Vec = import_re + .captures_iter(input) .map(|cap| cap[1].to_string()) .filter(|s| !(s.contains("wasi") || s.contains("kinode:process/standard"))) .collect(); - let exports: Vec = export_re.captures_iter(input) + let exports: Vec = export_re + .captures_iter(input) .map(|cap| cap[1].to_string()) .filter(|s| !s.contains("init")) .collect(); @@ -989,8 +997,7 @@ fn get_imports_exports_from_wasm( should_move_export: bool, ) -> Result<()> { let wit = run_command( - Command::new("wasm-tools") - .args(["component", "wit", path.to_str().unwrap()]), + Command::new("wasm-tools").args(["component", "wit", path.to_str().unwrap()]), false, )?; let Some((ref wit, _)) = wit else { @@ -1176,13 +1183,16 @@ async fn compile_package( default_world, force, verbose, - ).await?; + ) + .await?; } - let wit_world = default_world.unwrap_or_else(|| match metadata.properties.wit_version { - None => DEFAULT_WORLD_0_7_0, - Some(0) | _ => DEFAULT_WORLD_0_8_0, - }).to_string(); + let wit_world = default_world + .unwrap_or_else(|| match metadata.properties.wit_version { + None => DEFAULT_WORLD_0_7_0, + Some(0) | _ => DEFAULT_WORLD_0_8_0, + }) + .to_string(); let mut tasks = tokio::task::JoinSet::new(); let features = features.to_string(); @@ -1225,15 +1235,14 @@ async fn compile_package( for import_path in import_paths { let import_path_str = import_path.to_str().unwrap(); run_command( - Command::new("wasm-tools") - .args([ - "compose", - import_path_str, - "-d", - export_path, - "-o", - import_path_str, - ]), + Command::new("wasm-tools").args([ + "compose", + import_path_str, + "-d", + export_path, + "-o", + import_path_str, + ]), false, )?; } @@ -1245,7 +1254,7 @@ async fn compile_package( path, package_dir .join("pkg") - .join(path.file_name().and_then(|f| f.to_str()).unwrap()) + .join(path.file_name().and_then(|f| f.to_str()).unwrap()), )?; } } @@ -1296,7 +1305,7 @@ pub async fn execute( add_paths_to_api: Vec, force: bool, verbose: bool, - ignore_deps: bool, // for internal use; may cause problems when adding recursive deps + ignore_deps: bool, // for internal use; may cause problems when adding recursive deps ) -> Result<()> { if !package_dir.join("pkg").exists() { if Some(".DS_Store") == package_dir.file_name().and_then(|s| s.to_str()) { diff --git a/src/main.rs b/src/main.rs index 8799c5cf..7ea1761f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,9 @@ struct Commit { fn parse_u128_with_underscores(s: &str) -> Result { let clean_string = s.replace('_', ""); - clean_string.parse::().map_err(|_| "Invalid number format") + clean_string + .parse::() + .map_err(|_| "Invalid number format") } async fn get_latest_commit_sha_from_branch( @@ -366,7 +368,8 @@ async fn execute( *gas_limit, max_priority_fee, max_fee_per_gas, - ).await + ) + .await } Some(("remove-package", matches)) => { let package_name = matches diff --git a/src/publish/mod.rs b/src/publish/mod.rs index 5a20cd93..024f312e 100644 --- a/src/publish/mod.rs +++ b/src/publish/mod.rs @@ -79,11 +79,7 @@ const FAKE_CHAIN_ID: u64 = 31337; const MULTICALL_ADDRESS: &str = "0xcA11bde05977b3631167028862bE2a173976CA11"; pub fn make_local_file_link(path: &str, text: &str) -> String { - format!( - "\x1B]8;;file://{}\x1B\\{}\x1B]8;;\x1B\\", - path, - text, - ) + format!("\x1B]8;;file://{}\x1B\\{}\x1B]8;;\x1B\\", path, text,) } #[instrument(level = "trace", skip_all)] @@ -97,15 +93,12 @@ pub fn make_local_file_link_path(path: &Path, text: &str) -> Result { } pub fn make_remote_link(url: &str, text: &str) -> String { - format!( - "\x1B]8;;{}\x1B\\{}\x1B]8;;\x1B\\", - url, - text, - ) + format!("\x1B]8;;{}\x1B\\{}\x1B]8;;\x1B\\", url, text,) } fn is_valid_kimap_package_name(s: &str) -> bool { - s.chars().all(|c| c.is_ascii_lowercase() || c == '-' || c.is_ascii_digit()) + s.chars() + .all(|c| c.is_ascii_lowercase() || c == '-' || c.is_ascii_digit()) } #[instrument(level = "trace", skip_all)] @@ -126,10 +119,7 @@ fn read_keystore(keystore_path: &Path) -> Result<(Address, EthereumWallet)> { #[instrument(level = "trace", skip_all)] async fn read_ledger(chain_id: u64) -> Result<(Address, EthereumWallet)> { - let signer = ledger::LedgerSigner::new( - ledger::HDPath::LedgerLive(0), - Some(chain_id), - ).await?; + let signer = ledger::LedgerSigner::new(ledger::HDPath::LedgerLive(0), Some(chain_id)).await?; let address = signer.get_address().await?; let wallet = EthereumWallet::from(signer); Ok((address, wallet)) @@ -137,10 +127,7 @@ async fn read_ledger(chain_id: u64) -> Result<(Address, EthereumWallet)> { #[instrument(level = "trace", skip_all)] async fn read_trezor(chain_id: u64) -> Result<(Address, EthereumWallet)> { - let signer = trezor::TrezorSigner::new( - trezor::HDPath::TrezorLive(0), - Some(chain_id), - ).await?; + let signer = trezor::TrezorSigner::new(trezor::HDPath::TrezorLive(0), Some(chain_id)).await?; let address = signer.get_address().await?; let wallet = EthereumWallet::from(signer); Ok((address, wallet)) @@ -162,7 +149,11 @@ fn namehash(name: &str) -> [u8; 32] { } #[instrument(level = "trace", skip_all)] -async fn check_remote_metadata(metadata: &Erc721Metadata, metadata_uri: &str, package_dir: &Path) -> Result { +async fn check_remote_metadata( + metadata: &Erc721Metadata, + metadata_uri: &str, + package_dir: &Path, +) -> Result { let remote_metadata_dir = PathBuf::from(format!( "/tmp/kinode-kit-cache/{}", metadata.name.as_ref().unwrap(), @@ -178,7 +169,8 @@ async fn check_remote_metadata(metadata: &Erc721Metadata, metadata_uri: &str, pa if serde_json::to_string(&metadata)? != serde_json::to_string(&remote_metadata)? { return Err(eyre!( "{} and {} metadata do not match", - make_local_file_link_path(&package_dir.join("metadata.json"), "Local").unwrap_or_default(), + make_local_file_link_path(&package_dir.join("metadata.json"), "Local") + .unwrap_or_default(), make_remote_link(metadata_uri, "remote"), )); } @@ -259,13 +251,9 @@ async fn kimap_get( provider: &RootProvider, ) -> Result<(Address, Address, Option)> { let node = namehash(&node); - let get_tx = TransactionRequest::default().to(kimap).input( - getCall { - node: node.into(), - } - .abi_encode() - .into(), - ); + let get_tx = TransactionRequest::default() + .to(kimap) + .input(getCall { node: node.into() }.abi_encode().into()); let get_call = provider.call(&get_tx).await?; let decoded = getCall::abi_decode_returns(&get_call, false)?; @@ -292,24 +280,14 @@ async fn prepare_kimap_put( ) -> Result<(Address, Vec)> { // if app_tba exists, update existing state; // else mint it & add new state - let (app_tba, owner, _) = kimap_get( - &format!("{}.{}", name, publisher), - kimap, - &provider, - ).await?; + let (app_tba, owner, _) = + kimap_get(&format!("{}.{}", name, publisher), kimap, &provider).await?; let is_update = app_tba != Address::default() && owner == wallet_address; let (to, call) = if is_update { - ( - app_tba, - multicall, - ) + (app_tba, multicall) } else { - let (publisher_tba, _, _) = kimap_get( - &publisher, - kimap, - &provider, - ).await?; + let (publisher_tba, _, _) = kimap_get(&publisher, kimap, &provider).await?; let mint_call = mintCall { who: wallet_address, label: name.into(), @@ -325,10 +303,7 @@ async fn prepare_kimap_put( operation: 0, } .abi_encode(); - ( - publisher_tba, - call, - ) + (publisher_tba, call) }; Ok((to, call)) } @@ -359,7 +334,11 @@ pub async fn execute( (Some(ref kp), false, false) => read_keystore(kp)?, (None, true, false) => read_ledger(chain_id).await?, (None, false, true) => read_trezor(chain_id).await?, - _ => return Err(eyre!("Must supply one and only one of `--keystore_path`, `--ledger`, or `--trezor`")), + _ => { + return Err(eyre!( + "Must supply one and only one of `--keystore_path`, `--ledger`, or `--trezor`" + )) + } }; let metadata = read_metadata(package_dir)?; @@ -368,7 +347,9 @@ pub async fn execute( let publisher = metadata.properties.publisher.clone(); if !is_valid_kimap_package_name(&name) { - return Err(eyre!("The App Store requires package names have only lowercase letters, digits, and `-`s")); + return Err(eyre!( + "The App Store requires package names have only lowercase letters, digits, and `-`s" + )); } let metadata_hash = check_remote_metadata(&metadata, metadata_uri, package_dir).await?; @@ -377,29 +358,21 @@ pub async fn execute( let ws = WsConnect::new(rpc_uri); let provider: RootProvider = ProviderBuilder::default().on_ws(ws).await?; - let kimap = Address::from_str( - if *real { - REAL_KIMAP_ADDRESS - } else { - FAKE_KIMAP_ADDRESS - } - )?; + let kimap = Address::from_str(if *real { + REAL_KIMAP_ADDRESS + } else { + FAKE_KIMAP_ADDRESS + })?; let multicall_address = Address::from_str(MULTICALL_ADDRESS)?; - let kino_account_impl = Address::from_str( - if *real { - REAL_KINO_ACCOUNT_IMPL - } else { - FAKE_KINO_ACCOUNT_IMPL - } - )?; + let kino_account_impl = Address::from_str(if *real { + REAL_KINO_ACCOUNT_IMPL + } else { + FAKE_KINO_ACCOUNT_IMPL + })?; let (to, call) = if *unpublish { let app_node = format!("{}.{}", name, publisher); - let (app_tba, owner, _) = kimap_get( - &app_node, - kimap, - &provider, - ).await?; + let (app_tba, owner, _) = kimap_get(&app_node, kimap, &provider).await?; let exists = app_tba != Address::default() && owner == wallet_address; if !exists { return Err(eyre!("Can't find {app_node} to unpublish.")); @@ -418,7 +391,8 @@ pub async fn execute( &provider, wallet_address, kino_account_impl, - ).await? + ) + .await? }; let nonce = provider.get_transaction_count(wallet_address).await?; @@ -434,7 +408,9 @@ pub async fn execute( .nonce(nonce) .with_chain_id(chain_id) .with_gas_limit(gas_limit) - .with_max_priority_fee_per_gas(max_priority_fee_per_gas.unwrap_or_else(|| suggested_max_priority_fee_per_gas)) + .with_max_priority_fee_per_gas( + max_priority_fee_per_gas.unwrap_or_else(|| suggested_max_priority_fee_per_gas), + ) .with_max_fee_per_gas(max_fee_per_gas.unwrap_or_else(|| suggested_max_fee_per_gas)); let tx_envelope = tx.build(&wallet).await?; @@ -445,6 +421,9 @@ pub async fn execute( &format!("https://optimistic.etherscan.io/tx/{tx_hash}"), &tx_hash, ); - info!("{} {name} tx sent: {link}", if *unpublish { "unpublish" } else { "publish" }); + info!( + "{} {name} tx sent: {link}", + if *unpublish { "unpublish" } else { "publish" } + ); Ok(()) } diff --git a/src/run_tests/cleanup.rs b/src/run_tests/cleanup.rs index 44695f0a..e7c54c94 100644 --- a/src/run_tests/cleanup.rs +++ b/src/run_tests/cleanup.rs @@ -88,9 +88,7 @@ pub async fn cleanup( } }; - let _ = send_to_kill.send( - should_print_std.is_none() || should_print_std.is_some_and(|b| b) - ); + let _ = send_to_kill.send(should_print_std.is_none() || should_print_std.is_some_and(|b| b)); for NodeCleanupInfo { master_fd, diff --git a/src/run_tests/mod.rs b/src/run_tests/mod.rs index 3c57293b..b6289fa8 100644 --- a/src/run_tests/mod.rs +++ b/src/run_tests/mod.rs @@ -30,12 +30,10 @@ impl Config { self.runtime = match self.runtime { Runtime::FetchVersion(version) => Runtime::FetchVersion(version), Runtime::RepoPath(runtime_path) => { - Runtime::RepoPath(expand_home_path(&runtime_path) - .unwrap_or_else(|| { - fs::canonicalize(config_path.join(&runtime_path)) - .unwrap_or_else(|_| runtime_path) - }) - ) + Runtime::RepoPath(expand_home_path(&runtime_path).unwrap_or_else(|| { + fs::canonicalize(config_path.join(&runtime_path)) + .unwrap_or_else(|_| runtime_path) + })) } }; for test in self.tests.iter_mut() { @@ -45,11 +43,10 @@ impl Config { .map(|p| expand_home_path(&p).unwrap_or_else(|| p.clone())) .collect(); for node in test.nodes.iter_mut() { - node.home = expand_home_path(&node.home) - .unwrap_or_else(|| { - fs::canonicalize(config_path.join(&node.home)) - .unwrap_or_else(|_| node.home.clone()) - }); + node.home = expand_home_path(&node.home).unwrap_or_else(|| { + fs::canonicalize(config_path.join(&node.home)) + .unwrap_or_else(|_| node.home.clone()) + }); } } self @@ -287,11 +284,9 @@ async fn build_packages( .dependency_package_paths .iter() .cloned() - .map(|p| { - match expand_home_path(&p) { - Some(p) => p, - None => 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 = test @@ -355,9 +350,11 @@ async fn build_packages( let url = format!("http://localhost:{port}"); for dependency_package_path in &test.dependency_package_paths { - let path = match expand_home_path(&dependency_package_path) { + let path = match expand_home_path(&dependency_package_path) { Some(p) => p, - None => test_dir_path.join(&dependency_package_path).canonicalize()?, + None => test_dir_path + .join(&dependency_package_path) + .canonicalize()?, }; build::execute( &path, @@ -511,10 +508,9 @@ async fn load_process(path: &Path, drive: &str, port: &u16) -> Result<()> { path.to_str(), )?; - let response = inject_message::send_request( - &format!("http://localhost:{}", port), - request, - ).await?; + 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)), diff --git a/src/start_package/mod.rs b/src/start_package/mod.rs index ad4b901d..9333dccc 100644 --- a/src/start_package/mod.rs +++ b/src/start_package/mod.rs @@ -118,7 +118,8 @@ fn check_manifest(pkg_dir: &Path, manifest_file_name: &str) -> Result<()> { make_local_file_link_path( &pkg_dir.join(manifest_file_name), manifest_file_name, - ).unwrap(), + ) + .unwrap(), cab_file_path, ) })); @@ -139,15 +140,24 @@ fn check_manifest(pkg_dir: &Path, manifest_file_name: &str) -> Result<()> { make_local_file_link_path( &pkg_dir.join(manifest_file_name), manifest_file_name, - ).unwrap(), + ) + .unwrap(), hep_file_path, ) })); } } } - return Err(eyre!("Missing a .wasm file declared by {}.", manifest_file_name) - .with_suggestion(|| format!("Try `kit build`ing package first, or updating {}.", manifest_file_name))); + return Err( + eyre!("Missing a .wasm file declared by {}.", manifest_file_name).with_suggestion( + || { + format!( + "Try `kit build`ing package first, or updating {}.", + manifest_file_name + ) + }, + ), + ); } Ok(()) } @@ -168,8 +178,9 @@ pub async fn execute(package_dir: &Path, url: &str) -> Result<()> { let zip_filename = make_zip_filename(package_dir, &pkg_publisher); if !zip_filename.exists() { - return Err(eyre!("Missing pkg zip.") - .with_suggestion(|| "Try `kit build`ing package first.")); + return Err( + eyre!("Missing pkg zip.").with_suggestion(|| "Try `kit build`ing package first.") + ); } check_manifest(&pkg_dir, "manifest.json")?; @@ -207,11 +218,7 @@ pub async fn execute(package_dir: &Path, url: &str) -> Result<()> { )); } - let install_request = install( - None, - &hash_string, - &metadata, - )?; + let install_request = install(None, &hash_string, &metadata)?; let response = inject_message::send_request(url, install_request).await?; let inject_message::Response { ref body, .. } = inject_message::parse_response(response).await?; diff --git a/src/view_api/mod.rs b/src/view_api/mod.rs index 8c78a8fa..b6bf7939 100644 --- a/src/view_api/mod.rs +++ b/src/view_api/mod.rs @@ -105,7 +105,9 @@ async fn get_version_hash( let (body, _) = parse_response(response, url).await?; let body: serde_json::Value = serde_json::from_str(&body)?; let Some(result) = body.get("GetApp") else { - return Err(eyre!("Couldn't get version hash: bad response from node at {url}: {body}")); + return Err(eyre!( + "Couldn't get version hash: bad response from node at {url}: {body}" + )); }; return match result { serde_json::Value::String(s) => Ok(s.clone()), @@ -113,16 +115,17 @@ async fn get_version_hash( warn!("Couldn't get version hash: got Null from node at {url}: {body}"); Ok(String::new()) } - _ => { - Err(eyre!( - "Couldn't get version hash: got unexpected result from node at {url}: {body}" - )) - } + _ => Err(eyre!( + "Couldn't get version hash: got unexpected result from node at {url}: {body}" + )), }; } #[instrument(level = "trace", skip_all)] -async fn parse_response(response: reqwest::Response, url: &str) -> Result<(String, Option>)> { +async fn parse_response( + response: reqwest::Response, + url: &str, +) -> Result<(String, Option>)> { let inject_message::Response { body, lazy_load_blob, .. } = inject_message::parse_response(response) .await @@ -143,15 +146,20 @@ fn rewrite_list_apis(mut output: serde_json::Value) -> Result if let serde_json::Value::Object(ref mut obj) = output { if let Some(serde_json::Value::Object(apis_response)) = obj.get_mut("ApisResponse") { if let Some(serde_json::Value::Array(apis)) = apis_response.get_mut("apis") { - let transformed_apis: Vec<_> = apis.iter().map(|api| { - if let serde_json::Value::Object(api_map) = api { - let package_name = api_map.get("package_name").unwrap().as_str().unwrap(); - let publisher_node = api_map.get("publisher_node").unwrap().as_str().unwrap(); - serde_json::Value::String(format!("{package_name}:{publisher_node}")) - } else { - serde_json::Value::String(String::new()) - } - }).collect(); + let transformed_apis: Vec<_> = apis + .iter() + .map(|api| { + if let serde_json::Value::Object(api_map) = api { + let package_name = + api_map.get("package_name").unwrap().as_str().unwrap(); + let publisher_node = + api_map.get("publisher_node").unwrap().as_str().unwrap(); + serde_json::Value::String(format!("{package_name}:{publisher_node}")) + } else { + serde_json::Value::String(String::new()) + } + }) + .collect(); // Replace the old array with the new one *apis = transformed_apis; @@ -275,7 +283,15 @@ async fn get_api( if is_first_call && body.contains("Failure") { // try to download the package & try again download(node, url, package_id, download_from, None).await?; - Box::pin(get_api(node, url, package_id, download_from, verbose, false)).await? + Box::pin(get_api( + node, + url, + package_id, + download_from, + verbose, + false, + )) + .await? } else { // unexpected case let body = serde_json::from_str::(&body)?; @@ -295,7 +311,9 @@ pub async fn execute( verbose: bool, ) -> Result> { if let Some(package_id) = package_id { - Ok(Some(get_api(node, url, &package_id, download_from, verbose, true).await?)) + Ok(Some( + get_api(node, url, &package_id, download_from, verbose, true).await?, + )) } else { list_apis(node, url, verbose).await?; Ok(None) From 6dda58d28c1d32aac2c60fd357395d369152d7f2 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 16 Sep 2024 10:54:22 -0700 Subject: [PATCH 11/17] boot-fake-node: use linux aarch64 --- src/boot_fake_node/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/boot_fake_node/mod.rs b/src/boot_fake_node/mod.rs index cc3c49fc..847fe5ba 100644 --- a/src/boot_fake_node/mod.rs +++ b/src/boot_fake_node/mod.rs @@ -133,11 +133,12 @@ pub fn get_platform_runtime_name(is_simulation_mode: bool) -> Result { // TODO: update when have binaries let zip_name_midfix = match (os_name, architecture_name) { ("Linux", "x86_64") => "x86_64-unknown-linux-gnu", + ("Linux", "aarch64") => "aarch64-unknown-linux-gnu", ("Darwin", "arm64") => "arm64-apple-darwin", ("Darwin", "x86_64") => "x86_64-apple-darwin", _ => { return Err(eyre!( - "OS/Architecture {}/{} not amongst pre-built [Linux/x86_64, Apple/arm64, Apple/x86_64].", + "OS/Architecture {}/{} not amongst pre-built [Linux/x86_64, Linux/aarch64, Apple/arm64, Apple/x86_64].", os_name, architecture_name, ).with_suggestion(|| "Use the `--runtime-path` flag to build a local copy of the https://github.com/kinode-dao/kinode repo") From 1d8ac776661cb64ff17ae791b0a23148080b8abd Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 16 Sep 2024 13:07:47 -0700 Subject: [PATCH 12/17] build: output more on run_command() error --- src/build/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index fbe8c5d2..84960fe8 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -180,7 +180,19 @@ pub fn run_command(cmd: &mut Command, verbose: bool) -> Result o, + Err(e) => { + return Err(eyre!( + "Command `{} {:?}` failed with error {:?}", + cmd.get_program().to_str().unwrap(), + cmd.get_args() + .map(|a| a.to_str().unwrap()) + .collect::>(), + e, + )); + } + }; if output.status.success() { Ok(Some(( String::from_utf8_lossy(&output.stdout).to_string(), From bba6c3241cb9f40aa0f7e28f0ce0d1081e3e10a7 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 16 Sep 2024 11:25:58 -0700 Subject: [PATCH 13/17] workflow: update target --- .github/workflows/build_and_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 9e67935f..be2df596 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -30,8 +30,8 @@ jobs: rustup update cargo install wasm-tools rustup install nightly - rustup target add wasm32-wasi - rustup target add wasm32-wasi --toolchain nightly + rustup target add wasm32-wasip1 + rustup target add wasm32-wasip1 --toolchain nightly cargo install cargo-wasi #- name: Get latest release from foundry-rs/foundry # id: get-latest-foundry-release From a5926c396c5906cf2dc37da82cf41c99db104344 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 16 Sep 2024 11:26:23 -0700 Subject: [PATCH 14/17] build: refactor up-to-date check into `is_up_to_date()` --- src/build/mod.rs | 60 ++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 84960fe8..8784fff6 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -493,6 +493,39 @@ fn get_file_modified_time(file_path: &Path) -> Result { Ok(metadata.modified()?) } +#[instrument(level = "trace", skip_all)] +fn is_up_to_date( + build_with_features_path: &Path, + features: &str, + package_dir: &Path, +) -> Result { + let old_features = fs::read_to_string(&build_with_features_path).ok(); + if old_features == Some(features.to_string()) + && package_dir.join("Cargo.lock").exists() + && package_dir.join("pkg").exists() + && package_dir.join("pkg").join("api.zip").exists() + && file_with_extension_exists(&package_dir.join("pkg"), "wasm") + { + let (source_time, build_time) = get_most_recent_modified_time( + package_dir, + &HashSet::from(["Cargo.lock", "api.zip"]), + &HashSet::from(["wasm"]), + &HashSet::from(["target"]), + )?; + if let Some(source_time) = source_time { + if let Some(build_time) = build_time { + if build_time.duration_since(source_time).is_ok() { + // build_time - source_time >= 0 + // -> current build is up-to-date: don't rebuild + info!("Build up-to-date."); + return Ok(true); + } + } + } + } + Ok(false) +} + #[instrument(level = "trace", skip_all)] async fn compile_javascript_wasm_process( process_dir: &Path, @@ -1331,31 +1364,8 @@ pub async fn execute( .with_suggestion(|| "Please re-run targeting a package.")); } let build_with_features_path = package_dir.join("target").join("build_with_features.txt"); - if !force { - let old_features = fs::read_to_string(&build_with_features_path).ok(); - if old_features == Some(features.to_string()) - && package_dir.join("Cargo.lock").exists() - && package_dir.join("pkg").exists() - && package_dir.join("pkg").join("api.zip").exists() - && file_with_extension_exists(&package_dir.join("pkg"), "wasm") - { - let (source_time, build_time) = get_most_recent_modified_time( - package_dir, - &HashSet::from(["Cargo.lock", "api.zip"]), - &HashSet::from(["wasm"]), - &HashSet::from(["target"]), - )?; - if let Some(source_time) = source_time { - if let Some(build_time) = build_time { - if build_time.duration_since(source_time).is_ok() { - // build_time - source_time >= 0 - // -> current build is up-to-date: don't rebuild - info!("Build up-to-date."); - return Ok(()); - } - } - } - } + if !force && is_up_to_date(&build_with_features_path, features, package_dir)? { + return Ok(()); } fs::create_dir_all(package_dir.join("target"))?; fs::write(&build_with_features_path, features)?; From 90ae3eabac9194ba3ebe10230bb991361ea1fa08 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 16 Sep 2024 14:35:08 -0700 Subject: [PATCH 15/17] build: fix up-to-date detection wrt local deps --- src/build/mod.rs | 55 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 8784fff6..4b5dbaea 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -493,6 +493,14 @@ fn get_file_modified_time(file_path: &Path) -> Result { Ok(metadata.modified()?) } +#[instrument(level = "trace", skip_all)] +fn get_cargo_package_path(package: &cargo_metadata::Package) -> Result { + match package.manifest_path.parent().map(|p| p.as_std_path().to_path_buf()) { + Some(p) => Ok(p), + None => Err(eyre!("Cargo manifest path {} has no parent", package.manifest_path)), + } +} + #[instrument(level = "trace", skip_all)] fn is_up_to_date( build_with_features_path: &Path, @@ -506,26 +514,57 @@ fn is_up_to_date( && package_dir.join("pkg").join("api.zip").exists() && file_with_extension_exists(&package_dir.join("pkg"), "wasm") { - let (source_time, build_time) = get_most_recent_modified_time( + let (mut source_time, build_time) = get_most_recent_modified_time( package_dir, &HashSet::from(["Cargo.lock", "api.zip"]), &HashSet::from(["wasm"]), &HashSet::from(["target"]), )?; - if let Some(source_time) = source_time { - if let Some(build_time) = build_time { - if build_time.duration_since(source_time).is_ok() { - // build_time - source_time >= 0 - // -> current build is up-to-date: don't rebuild - info!("Build up-to-date."); - return Ok(true); + let Some(build_time) = build_time else { + return Ok(false); + }; + + // update source to most recent of package_dir + // or package_dir's local deps + let metadata = cargo_metadata::MetadataCommand::new() + .manifest_path(package_dir.join("Cargo.toml")) + .exec()?; + for package in metadata.packages.iter().filter(|p| p.source.is_none()) { + let dep_package_dir = get_cargo_package_path(&package)?; + let (dep_source_time, _) = get_most_recent_modified_time( + &dep_package_dir, + &HashSet::from(["Cargo.lock", "api.zip"]), + &HashSet::from(["wasm"]), + &HashSet::from(["target"]), + )?; + match source_time { + None => source_time = dep_source_time, + Some(ref st) => { + if let Some(ref dst) = dep_source_time { + if dst.duration_since(st.clone()).is_ok() { + // dep has more recent changes than source + // -> update source_time to dep_source_time + source_time = dep_source_time; + } + } } } } + + if let Some(source_time) = source_time { + if build_time.duration_since(source_time).is_ok() { + // build_time - source_time >= 0 + // -> current build is up-to-date: don't rebuild + info!("Build up-to-date."); + return Ok(true); + } + } } Ok(false) } + + #[instrument(level = "trace", skip_all)] async fn compile_javascript_wasm_process( process_dir: &Path, From d59d2b39adc557e991408d2bfebf36ab7f058264 Mon Sep 17 00:00:00 2001 From: hosted-fornet Date: Mon, 16 Sep 2024 14:51:23 -0700 Subject: [PATCH 16/17] boot-fake-node: fix offline cache-based-fallback --- src/boot_fake_node/mod.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/boot_fake_node/mod.rs b/src/boot_fake_node/mod.rs index 847fe5ba..0e8d1244 100644 --- a/src/boot_fake_node/mod.rs +++ b/src/boot_fake_node/mod.rs @@ -312,9 +312,7 @@ pub async fn find_releases_with_asset_if_online( fn get_local_versions_with_prefix(prefix: &str) -> Result> { let mut versions = Vec::new(); - let path = Path::new(prefix) - .parent() - .ok_or_else(|| eyre!("couldnt find directory with local runtimes"))?; + let path = Path::new(KIT_CACHE); for entry in fs::read_dir(&path)? { let entry = entry?; let path = entry.path(); From a89c829085e5616f2e255442d5cee318cdbb3c5d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 16 Sep 2024 21:52:44 +0000 Subject: [PATCH 17/17] Format Rust code using rustfmt --- src/build/mod.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/build/mod.rs b/src/build/mod.rs index 4b5dbaea..321bfa8d 100644 --- a/src/build/mod.rs +++ b/src/build/mod.rs @@ -495,9 +495,16 @@ fn get_file_modified_time(file_path: &Path) -> Result { #[instrument(level = "trace", skip_all)] fn get_cargo_package_path(package: &cargo_metadata::Package) -> Result { - match package.manifest_path.parent().map(|p| p.as_std_path().to_path_buf()) { + match package + .manifest_path + .parent() + .map(|p| p.as_std_path().to_path_buf()) + { Some(p) => Ok(p), - None => Err(eyre!("Cargo manifest path {} has no parent", package.manifest_path)), + None => Err(eyre!( + "Cargo manifest path {} has no parent", + package.manifest_path + )), } } @@ -563,8 +570,6 @@ fn is_up_to_date( Ok(false) } - - #[instrument(level = "trace", skip_all)] async fn compile_javascript_wasm_process( process_dir: &Path,