From d6a4c3724a38b54892e24f5065d15d47d8de6fb9 Mon Sep 17 00:00:00 2001 From: Lann Martin Date: Fri, 19 Jul 2024 09:28:20 -0400 Subject: [PATCH 1/5] Add run-factors-tests.sh This is a temporary hack while the factors branch CI is broken during refactoring. Signed-off-by: Lann Martin --- crates/key-value/src/util.rs | 14 +++++++++----- run-factors-tests.sh | 5 +++++ 2 files changed, 14 insertions(+), 5 deletions(-) create mode 100755 run-factors-tests.sh diff --git a/crates/key-value/src/util.rs b/crates/key-value/src/util.rs index 0af704e62..c2aef7e4d 100644 --- a/crates/key-value/src/util.rs +++ b/crates/key-value/src/util.rs @@ -52,11 +52,15 @@ impl DelegatingStoreManager { #[async_trait] impl StoreManager for DelegatingStoreManager { async fn get(&self, name: &str) -> Result, Error> { - let store = match self.delegates.get(name) { - Some(store) => store, - None => &(self.default_manager)(name).ok_or(Error::NoSuchStore)?, - }; - store.get(name).await + match self.delegates.get(name) { + Some(store) => store.get(name).await, + None => { + (self.default_manager)(name) + .ok_or(Error::NoSuchStore)? + .get(name) + .await + } + } } fn is_defined(&self, store_name: &str) -> bool { diff --git a/run-factors-tests.sh b/run-factors-tests.sh new file mode 100755 index 000000000..a32175177 --- /dev/null +++ b/run-factors-tests.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +# TODO: Remove after enabling CI for factors branch + +cargo test -p '*factor*' \ No newline at end of file From eb3ebb224dad475396824439e75dccc3d36fefb0 Mon Sep 17 00:00:00 2001 From: Lann Martin Date: Fri, 19 Jul 2024 09:32:51 -0400 Subject: [PATCH 2/5] factors: Get factors tests passing with new spin-core Signed-off-by: Lann Martin --- crates/factor-variables/build.rs | 2 +- crates/factor-wasi/build.rs | 2 +- crates/factor-wasi/src/lib.rs | 1 - crates/factors/tests/smoke.rs | 2 +- crates/key-value/src/lib.rs | 4 ++-- crates/sqlite/src/lib.rs | 8 ++++---- run-factors-tests.sh | 5 ++--- 7 files changed, 11 insertions(+), 13 deletions(-) diff --git a/crates/factor-variables/build.rs b/crates/factor-variables/build.rs index bba8ce3c9..c96556b06 100644 --- a/crates/factor-variables/build.rs +++ b/crates/factor-variables/build.rs @@ -1,5 +1,5 @@ fn main() { - println!("cargo::rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=build.rs"); // Enable spin-factors-derive to emit expanded macro output. let out_dir = std::env::var("OUT_DIR").unwrap(); println!("cargo:rustc-env=SPIN_FACTORS_DERIVE_EXPAND_DIR={out_dir}"); diff --git a/crates/factor-wasi/build.rs b/crates/factor-wasi/build.rs index bba8ce3c9..c96556b06 100644 --- a/crates/factor-wasi/build.rs +++ b/crates/factor-wasi/build.rs @@ -1,5 +1,5 @@ fn main() { - println!("cargo::rerun-if-changed=build.rs"); + println!("cargo:rerun-if-changed=build.rs"); // Enable spin-factors-derive to emit expanded macro output. let out_dir = std::env::var("OUT_DIR").unwrap(); println!("cargo:rustc-env=SPIN_FACTORS_DERIVE_EXPAND_DIR={out_dir}"); diff --git a/crates/factor-wasi/src/lib.rs b/crates/factor-wasi/src/lib.rs index 82fdd802b..2579b15e6 100644 --- a/crates/factor-wasi/src/lib.rs +++ b/crates/factor-wasi/src/lib.rs @@ -157,7 +157,6 @@ impl<'a> MountFilesContext<'a> { guest_path: impl AsRef, writable: bool, ) -> anyhow::Result<()> { - use wasmtime_wasi::{DirPerms, FilePerms}; let (dir_perms, file_perms) = if writable { (DirPerms::all(), FilePerms::all()) } else { diff --git a/crates/factors/tests/smoke.rs b/crates/factors/tests/smoke.rs index 0a4cbde32..ee1bcb6b4 100644 --- a/crates/factors/tests/smoke.rs +++ b/crates/factors/tests/smoke.rs @@ -64,7 +64,7 @@ async fn smoke_test_works() -> anyhow::Result<()> { None, ) .await?; - let app = App::inert(locked); + let app = App::new("test-app", locked); let engine = wasmtime::Engine::new(wasmtime::Config::new().async_support(true))?; let mut linker = wasmtime::component::Linker::new(&engine); diff --git a/crates/key-value/src/lib.rs b/crates/key-value/src/lib.rs index 7caddf40a..08a656c5d 100644 --- a/crates/key-value/src/lib.rs +++ b/crates/key-value/src/lib.rs @@ -5,10 +5,10 @@ use spin_world::v2::key_value; use std::{collections::HashSet, sync::Arc}; use table::Table; -mod host_component; +// TODO: Code left for reference; remove after migration to factors +// mod host_component; mod util; -pub use host_component::{manager, KeyValueComponent}; pub use util::{ CachingStoreManager, DefaultManagerGetter, DelegatingStoreManager, EmptyStoreManager, }; diff --git a/crates/sqlite/src/lib.rs b/crates/sqlite/src/lib.rs index a9f589bf6..a56f40474 100644 --- a/crates/sqlite/src/lib.rs +++ b/crates/sqlite/src/lib.rs @@ -1,13 +1,13 @@ -mod host_component; +// TODO: Code left for reference; remove after migration to factors +// mod host_component; -use spin_app::{async_trait, MetadataKey}; +use spin_app::MetadataKey; use spin_core::wasmtime::component::Resource; +use spin_world::async_trait; use spin_world::v1::sqlite::Error as V1SqliteError; use spin_world::v2::sqlite; use std::{collections::HashSet, sync::Arc}; -pub use host_component::SqliteComponent; - pub const DATABASES_KEY: MetadataKey> = MetadataKey::new("databases"); /// A store of connections for all accessible databases for an application diff --git a/run-factors-tests.sh b/run-factors-tests.sh index a32175177..497a0f319 100755 --- a/run-factors-tests.sh +++ b/run-factors-tests.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash +# TODO(factors): Remove after enabling CI for factors branch -# TODO: Remove after enabling CI for factors branch - -cargo test -p '*factor*' \ No newline at end of file +cargo test -p '*factor*' From e863c8b5034d540e12b4e20ef9b9e08170899ed5 Mon Sep 17 00:00:00 2001 From: Lann Martin Date: Fri, 19 Jul 2024 09:40:33 -0400 Subject: [PATCH 3/5] factors: Add simple CI Signed-off-by: Lann Martin --- .github/workflows/factors.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/factors.yml diff --git a/.github/workflows/factors.yml b/.github/workflows/factors.yml new file mode 100644 index 000000000..e7b2c080c --- /dev/null +++ b/.github/workflows/factors.yml @@ -0,0 +1,20 @@ +# TODO: remove after factors branch passes regular CI +name: Factors +on: + push: + branches: ["factors"] + pull_request: + branches: ["factors"] +jobs: + factors-tests: + runs-on: ubuntu-22.04-4core-spin + steps: + - uses: actions/checkout@v3 + - name: setup dependencies + uses: ./.github/actions/spin-ci-dependencies + with: + rust: true + rust-wasm: true + rust-cache: true + - name: Run factors tests + run: ./run-factors-tests.sh From ab4d65c0103e993cd40a08676941411337aa2920 Mon Sep 17 00:00:00 2001 From: Lann Martin Date: Fri, 19 Jul 2024 09:56:05 -0400 Subject: [PATCH 4/5] Use TODO(factors) Signed-off-by: Lann Martin --- .github/workflows/factors.yml | 2 +- crates/key-value/src/lib.rs | 2 +- crates/sqlite/src/lib.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/factors.yml b/.github/workflows/factors.yml index e7b2c080c..68ecf8fb6 100644 --- a/.github/workflows/factors.yml +++ b/.github/workflows/factors.yml @@ -1,4 +1,4 @@ -# TODO: remove after factors branch passes regular CI +# TODO(factors): remove after factors branch passes regular CI name: Factors on: push: diff --git a/crates/key-value/src/lib.rs b/crates/key-value/src/lib.rs index 08a656c5d..78e494000 100644 --- a/crates/key-value/src/lib.rs +++ b/crates/key-value/src/lib.rs @@ -5,7 +5,7 @@ use spin_world::v2::key_value; use std::{collections::HashSet, sync::Arc}; use table::Table; -// TODO: Code left for reference; remove after migration to factors +// TODO(factors): Code left for reference; remove after migration to factors // mod host_component; mod util; diff --git a/crates/sqlite/src/lib.rs b/crates/sqlite/src/lib.rs index a56f40474..110dfaca0 100644 --- a/crates/sqlite/src/lib.rs +++ b/crates/sqlite/src/lib.rs @@ -1,4 +1,4 @@ -// TODO: Code left for reference; remove after migration to factors +// TODO(factors): Code left for reference; remove after migration to factors // mod host_component; use spin_app::MetadataKey; From 4ec282b1f6fbf9c3b6b281ace76b4df44194129b Mon Sep 17 00:00:00 2001 From: Lann Martin Date: Fri, 19 Jul 2024 11:12:20 -0400 Subject: [PATCH 5/5] factors: Add build script for factors smoke test app Signed-off-by: Lann Martin --- Cargo.lock | 1 + crates/factors/Cargo.toml | 3 +++ crates/factors/build.rs | 19 +++++++++++++++++++ crates/factors/tests/smoke-app/.gitignore | 1 + crates/factors/tests/smoke-app/spin.toml | 8 ++------ 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 crates/factors/build.rs diff --git a/Cargo.lock b/Cargo.lock index aa48f93f9..e4bd2fdc6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7631,6 +7631,7 @@ name = "spin-factors" version = "2.7.0-pre0" dependencies = [ "anyhow", + "cargo-target-dep", "http 1.1.0", "http-body-util", "serde 1.0.197", diff --git a/crates/factors/Cargo.toml b/crates/factors/Cargo.toml index 7306e5294..3efbb2e02 100644 --- a/crates/factors/Cargo.toml +++ b/crates/factors/Cargo.toml @@ -31,5 +31,8 @@ tokio = { version = "1", features = ["macros", "rt", "sync"] } toml = "0.8" wasmtime-wasi-http = { workspace = true } +[build-dependencies] +cargo-target-dep = { git = "https://github.com/fermyon/cargo-target-dep", rev = "482f269eceb7b1a7e8fc618bf8c082dd24979cf1" } + [lints] workspace = true diff --git a/crates/factors/build.rs b/crates/factors/build.rs new file mode 100644 index 000000000..923b145fe --- /dev/null +++ b/crates/factors/build.rs @@ -0,0 +1,19 @@ +use std::path::Path; + +use cargo_target_dep::build_target_dep; + +fn main() { + println!("cargo:rerun-if-changed=build.rs"); + // Enable spin-factors-derive to emit expanded macro output. + let out_dir = std::env::var("OUT_DIR").unwrap(); + println!("cargo:rustc-env=SPIN_FACTORS_DERIVE_EXPAND_DIR={out_dir}"); + + let root = "tests/smoke-app"; + build_target_dep(root, Path::new("tests/smoke-app/smoke_app.wasm")) + .release() + .target("wasm32-wasi") + .build(); + println!("cargo:rerun-if-changed={root}/Cargo.toml"); + println!("cargo:rerun-if-changed={root}/Cargo.lock"); + println!("cargo:rerun-if-changed={root}/src"); +} diff --git a/crates/factors/tests/smoke-app/.gitignore b/crates/factors/tests/smoke-app/.gitignore index 386474fa5..671b13b2a 100644 --- a/crates/factors/tests/smoke-app/.gitignore +++ b/crates/factors/tests/smoke-app/.gitignore @@ -1,2 +1,3 @@ target/ .spin/ +*.wasm diff --git a/crates/factors/tests/smoke-app/spin.toml b/crates/factors/tests/smoke-app/spin.toml index a800b49fe..a49ca70f8 100644 --- a/crates/factors/tests/smoke-app/spin.toml +++ b/crates/factors/tests/smoke-app/spin.toml @@ -15,11 +15,7 @@ route = "/..." component = "smoke-app" [component.smoke-app] -source = "target/wasm32-wasi/release/smoke_app.wasm" +source = "smoke_app.wasm" allowed_outbound_hosts = ["https://{{ host }}"] key_value_stores = ["default"] -variables = { "other" = "<{{ other }}>"} - -[component.smoke-app.build] -command = "cargo build --target wasm32-wasi --release" -watch = ["src/**/*.rs", "Cargo.toml"] +variables = { "other" = "<{{ other }}>"} \ No newline at end of file