Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spin core refactor #763

Merged
merged 28 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0de1d49
Replace log with tracing in spin-redis
lann Sep 12, 2022
216a5f7
Copy spin-core and spin-app crates from prototype
lann Sep 12, 2022
fa434a9
Create spin-trigger-new crate
lann Sep 12, 2022
2be489f
Migrate spin-config to new core
lann Sep 12, 2022
ad71a33
Migrate outbound-http to new core
lann Sep 12, 2022
81a3629
Migrate outbound-pg to new core
lann Sep 12, 2022
a9de5f2
Migrate outbound-redis to new core
lann Sep 12, 2022
548efa3
Migrate spin-http to new core
lann Sep 13, 2022
24eebf4
Migrate spin-redis to new core
lann Sep 13, 2022
d3e48dd
Migrate spin-timer example to new core
lann Sep 13, 2022
6f4e0e6
Rename spin-trigger-new crate to spin-trigger
lann Sep 13, 2022
a41c40c
Remove 'allow_transient_write' from spin-loader
lann Sep 13, 2022
eea88f9
Update `spin up` to use new spin-trigger semantics
lann Sep 13, 2022
db22636
Remove spin-engine crate
lann Sep 13, 2022
be8d94d
Canonicalize file paths in spin-trigger
lann Sep 13, 2022
b0edd46
Print failed response body in integration tests
lann Sep 13, 2022
f9a8219
Improve error reporting in spin_app::Error
lann Sep 13, 2022
b1873d4
Improve TriggerLoader::load_module error
lann Sep 13, 2022
a9f7f5f
Use 'url' crate to manage file URLs
lann Sep 14, 2022
ce6f0ef
Replace OwnedApp Deref with explicit 'borrowed' method
lann Sep 14, 2022
85bab18
Add ValuesMapBuilder::take
lann Sep 14, 2022
b21f185
Add documentation to spin-core crate
lann Sep 15, 2022
ddd85b7
Add docs to spin-app crate
lann Sep 15, 2022
c1f831d
Remove '--include-ignored' from Makefile
lann Sep 16, 2022
6934177
Deduplicate App::get_metadata, AppComponent::get_metadata
lann Sep 16, 2022
47a89c7
Deduplicate App::get_metadata, AppComponent::get_metadata
lann Sep 16, 2022
4ee7dc7
Add tests to spin-core crate
lann Sep 19, 2022
c12caa5
Fix `--temp`
lann Sep 27, 2022
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
358 changes: 147 additions & 211 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ serde_json = "1.0.82"
sha2 = "0.10.2"
spin-build = { path = "crates/build" }
spin-config = { path = "crates/config" }
spin-engine = { path = "crates/engine" }
spin-http = { path = "crates/http" }
spin-loader = { path = "crates/loader" }
spin-manifest = { path = "crates/manifest" }
Expand Down Expand Up @@ -71,9 +70,10 @@ e2e-tests = []
[workspace]
members = [
"crates/abi-conformance",
"crates/app",
"crates/build",
"crates/config",
"crates/engine",
"crates/core",
"crates/http",
"crates/loader",
"crates/manifest",
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ check-rust-examples:

.PHONY: test-unit
test-unit:
RUST_LOG=$(LOG_LEVEL) cargo test --all --no-fail-fast -- --skip integration_tests --nocapture --include-ignored
RUST_LOG=$(LOG_LEVEL) cargo test --all --no-fail-fast -- --skip integration_tests --nocapture

.PHONY: test-integration
test-integration:
RUST_LOG=$(LOG_LEVEL) cargo test --test integration --no-fail-fast -- --nocapture --include-ignored
RUST_LOG=$(LOG_LEVEL) cargo test --test integration --no-fail-fast -- --nocapture

.PHONY: test-e2e
test-e2e:
RUST_LOG=$(LOG_LEVEL) cargo test --test integration --features e2e-tests --no-fail-fast -- integration_tests::test_dependencies --nocapture
RUST_LOG=$(LOG_LEVEL) cargo test --test integration --features e2e-tests --no-fail-fast -- --skip integration_tests::test_dependencies --nocapture --include-ignored
RUST_LOG=$(LOG_LEVEL) cargo test --test integration --features e2e-tests --no-fail-fast -- --skip integration_tests::test_dependencies --nocapture

.PHONY: test-sdk-go
test-sdk-go:
Expand Down
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ error: the `wasm32-wasi` target is not installed

std::fs::create_dir_all("target/test-programs").unwrap();

build_wasm_test_program("core-wasi-test.wasm", "crates/core/tests/core-wasi-test");
build_wasm_test_program("rust-http-test.wasm", "crates/http/tests/rust-http-test");
build_wasm_test_program("redis-rust.wasm", "crates/redis/tests/rust");
build_wasm_test_program("wagi-test.wasm", "crates/http/tests/wagi-test");
Expand Down
13 changes: 13 additions & 0 deletions crates/app/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "spin-app"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0"
async-trait = "0.1"
ouroboros = "0.15"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
spin-core = { path = "../core" }
thiserror = "1.0"
59 changes: 59 additions & 0 deletions crates/app/src/host_component.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use std::sync::Arc;

use spin_core::{EngineBuilder, HostComponent, HostComponentsData};

use crate::AppComponent;

/// A trait for "dynamic" Spin host components.
///
/// This extends [`HostComponent`] to support per-[`AppComponent`] dynamic
/// runtime configuration.
pub trait DynamicHostComponent: HostComponent {
/// Called on [`AppComponent`] instance initialization.
///
/// The `data` returned by [`HostComponent::build_data`] is passed, along
/// with a reference to the `component` being instantiated.
fn update_data(&self, data: &mut Self::Data, component: &AppComponent) -> anyhow::Result<()>;
}

impl<DHC: DynamicHostComponent> DynamicHostComponent for Arc<DHC> {
fn update_data(&self, data: &mut Self::Data, component: &AppComponent) -> anyhow::Result<()> {
(**self).update_data(data, component)
}
}

type DataUpdater =
Box<dyn Fn(&mut HostComponentsData, &AppComponent) -> anyhow::Result<()> + Send + Sync>;

#[derive(Default)]
pub struct DynamicHostComponents {
data_updaters: Vec<DataUpdater>,
}

impl DynamicHostComponents {
pub fn add_dynamic_host_component<T: Send + Sync, DHC: DynamicHostComponent>(
&mut self,
engine_builder: &mut EngineBuilder<T>,
host_component: DHC,
) -> anyhow::Result<()> {
let host_component = Arc::new(host_component);
let handle = engine_builder.add_host_component(host_component.clone())?;
self.data_updaters
.push(Box::new(move |host_components_data, component| {
let data = host_components_data.get_or_insert(handle);
host_component.update_data(data, component)
}));
Ok(())
}

pub fn update_data(
&self,
host_components_data: &mut HostComponentsData,
component: &AppComponent,
) -> anyhow::Result<()> {
for data_updater in &self.data_updaters {
data_updater(host_components_data, component)?;
}
Ok(())
}
}
Loading