From fca5d32b88915e6db84a09116a1ee6b395995189 Mon Sep 17 00:00:00 2001 From: itowlson Date: Mon, 14 Oct 2024 14:02:09 +1300 Subject: [PATCH 1/3] Spin 3.0 package Signed-off-by: itowlson --- crates/world/src/lib.rs | 1 + wit/{ => deps/spin@2.0.0}/key-value.wit | 0 wit/{ => deps/spin@2.0.0}/llm.wit | 0 wit/{ => deps/spin@2.0.0}/mqtt.wit | 0 wit/{ => deps/spin@2.0.0}/mysql.wit | 0 wit/{ => deps/spin@2.0.0}/postgres.wit | 0 wit/{ => deps/spin@2.0.0}/rdbms-types.wit | 0 wit/{ => deps/spin@2.0.0}/redis.wit | 0 wit/{ => deps/spin@2.0.0}/sqlite.wit | 0 wit/{ => deps/spin@2.0.0}/variables.wit | 0 wit/deps/spin@2.0.0/world.wit | 41 +++++++++++++++++++++++ wit/world.wit | 34 +++++++++---------- 12 files changed, 59 insertions(+), 17 deletions(-) rename wit/{ => deps/spin@2.0.0}/key-value.wit (100%) rename wit/{ => deps/spin@2.0.0}/llm.wit (100%) rename wit/{ => deps/spin@2.0.0}/mqtt.wit (100%) rename wit/{ => deps/spin@2.0.0}/mysql.wit (100%) rename wit/{ => deps/spin@2.0.0}/postgres.wit (100%) rename wit/{ => deps/spin@2.0.0}/rdbms-types.wit (100%) rename wit/{ => deps/spin@2.0.0}/redis.wit (100%) rename wit/{ => deps/spin@2.0.0}/sqlite.wit (100%) rename wit/{ => deps/spin@2.0.0}/variables.wit (100%) create mode 100644 wit/deps/spin@2.0.0/world.wit diff --git a/crates/world/src/lib.rs b/crates/world/src/lib.rs index d7adeb19f0..0ecb57ee1d 100644 --- a/crates/world/src/lib.rs +++ b/crates/world/src/lib.rs @@ -8,6 +8,7 @@ wasmtime::component::bindgen!({ world host { include fermyon:spin/host; include fermyon:spin/platform@2.0.0; + include fermyon:spin/platform@3.0.0; } "#, path: "../../wit", diff --git a/wit/key-value.wit b/wit/deps/spin@2.0.0/key-value.wit similarity index 100% rename from wit/key-value.wit rename to wit/deps/spin@2.0.0/key-value.wit diff --git a/wit/llm.wit b/wit/deps/spin@2.0.0/llm.wit similarity index 100% rename from wit/llm.wit rename to wit/deps/spin@2.0.0/llm.wit diff --git a/wit/mqtt.wit b/wit/deps/spin@2.0.0/mqtt.wit similarity index 100% rename from wit/mqtt.wit rename to wit/deps/spin@2.0.0/mqtt.wit diff --git a/wit/mysql.wit b/wit/deps/spin@2.0.0/mysql.wit similarity index 100% rename from wit/mysql.wit rename to wit/deps/spin@2.0.0/mysql.wit diff --git a/wit/postgres.wit b/wit/deps/spin@2.0.0/postgres.wit similarity index 100% rename from wit/postgres.wit rename to wit/deps/spin@2.0.0/postgres.wit diff --git a/wit/rdbms-types.wit b/wit/deps/spin@2.0.0/rdbms-types.wit similarity index 100% rename from wit/rdbms-types.wit rename to wit/deps/spin@2.0.0/rdbms-types.wit diff --git a/wit/redis.wit b/wit/deps/spin@2.0.0/redis.wit similarity index 100% rename from wit/redis.wit rename to wit/deps/spin@2.0.0/redis.wit diff --git a/wit/sqlite.wit b/wit/deps/spin@2.0.0/sqlite.wit similarity index 100% rename from wit/sqlite.wit rename to wit/deps/spin@2.0.0/sqlite.wit diff --git a/wit/variables.wit b/wit/deps/spin@2.0.0/variables.wit similarity index 100% rename from wit/variables.wit rename to wit/deps/spin@2.0.0/variables.wit diff --git a/wit/deps/spin@2.0.0/world.wit b/wit/deps/spin@2.0.0/world.wit new file mode 100644 index 0000000000..b16e429054 --- /dev/null +++ b/wit/deps/spin@2.0.0/world.wit @@ -0,0 +1,41 @@ +package fermyon:spin@2.0.0; + +/// The full world of a guest targeting an http-trigger +world http-trigger { + include platform; + export wasi:http/incoming-handler@0.2.0; +} + +/// Like `http-trigger`, but using WASI 0.2.0-rc-2023-10-18 +world http-trigger-rc20231018 { + include platform-rc20231018; + export wasi:http/incoming-handler@0.2.0-rc-2023-10-18; +} + +/// The imports needed for a guest to run on a Spin host +world platform { + include wasi:cli/imports@0.2.0; + import wasi:http/outgoing-handler@0.2.0; + import llm; + import redis; + import mqtt; + import postgres; + import mysql; + import sqlite; + import key-value; + import variables; +} + +/// Like `platform`, but using WASI 0.2.0-rc-2023-10-18 +world platform-rc20231018 { + include wasi:cli/reactor@0.2.0-rc-2023-10-18; + import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; + import llm; + import redis; + import mqtt; + import postgres; + import mysql; + import sqlite; + import key-value; + import variables; +} diff --git a/wit/world.wit b/wit/world.wit index b16e429054..f85ffdc194 100644 --- a/wit/world.wit +++ b/wit/world.wit @@ -1,4 +1,4 @@ -package fermyon:spin@2.0.0; +package fermyon:spin@3.0.0; /// The full world of a guest targeting an http-trigger world http-trigger { @@ -16,26 +16,26 @@ world http-trigger-rc20231018 { world platform { include wasi:cli/imports@0.2.0; import wasi:http/outgoing-handler@0.2.0; - import llm; - import redis; - import mqtt; - import postgres; - import mysql; - import sqlite; - import key-value; - import variables; + import fermyon:spin/llm@2.0.0; + import fermyon:spin/redis@2.0.0; + import fermyon:spin/mqtt@2.0.0; + import fermyon:spin/postgres@2.0.0; + import fermyon:spin/mysql@2.0.0; + import fermyon:spin/sqlite@2.0.0; + import fermyon:spin/key-value@2.0.0; + import fermyon:spin/variables@2.0.0; } /// Like `platform`, but using WASI 0.2.0-rc-2023-10-18 world platform-rc20231018 { include wasi:cli/reactor@0.2.0-rc-2023-10-18; import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; - import llm; - import redis; - import mqtt; - import postgres; - import mysql; - import sqlite; - import key-value; - import variables; + import fermyon:spin/llm@2.0.0; + import fermyon:spin/redis@2.0.0; + import fermyon:spin/mqtt@2.0.0; + import fermyon:spin/postgres@2.0.0; + import fermyon:spin/mysql@2.0.0; + import fermyon:spin/sqlite@2.0.0; + import fermyon:spin/key-value@2.0.0; + import fermyon:spin/variables@2.0.0; } From 53256cb95ec824e92d2d0d50a8a13c5935c45ca1 Mon Sep 17 00:00:00 2001 From: itowlson Date: Tue, 15 Oct 2024 11:11:53 +1300 Subject: [PATCH 2/3] Investigating having the Spin 3 package alongside others instead of top level Signed-off-by: itowlson --- wit/deps/spin@3.0.0/world.wit | 21 ++++++++++++++++++ wit/world.wit | 42 +---------------------------------- 2 files changed, 22 insertions(+), 41 deletions(-) create mode 100644 wit/deps/spin@3.0.0/world.wit diff --git a/wit/deps/spin@3.0.0/world.wit b/wit/deps/spin@3.0.0/world.wit new file mode 100644 index 0000000000..a959cb002c --- /dev/null +++ b/wit/deps/spin@3.0.0/world.wit @@ -0,0 +1,21 @@ +package fermyon:spin@3.0.0; + +/// The full world of a guest targeting an http-trigger +world http-trigger { + include platform; + export wasi:http/incoming-handler@0.2.0; +} + +/// The imports needed for a guest to run on a Spin host +world platform { + include wasi:cli/imports@0.2.0; + import wasi:http/outgoing-handler@0.2.0; + import fermyon:spin/llm@2.0.0; + import fermyon:spin/redis@2.0.0; + import fermyon:spin/mqtt@2.0.0; + import fermyon:spin/postgres@2.0.0; + import fermyon:spin/mysql@2.0.0; + import fermyon:spin/sqlite@2.0.0; + import fermyon:spin/key-value@2.0.0; + import fermyon:spin/variables@2.0.0; +} diff --git a/wit/world.wit b/wit/world.wit index f85ffdc194..9bfa3f0d77 100644 --- a/wit/world.wit +++ b/wit/world.wit @@ -1,41 +1 @@ -package fermyon:spin@3.0.0; - -/// The full world of a guest targeting an http-trigger -world http-trigger { - include platform; - export wasi:http/incoming-handler@0.2.0; -} - -/// Like `http-trigger`, but using WASI 0.2.0-rc-2023-10-18 -world http-trigger-rc20231018 { - include platform-rc20231018; - export wasi:http/incoming-handler@0.2.0-rc-2023-10-18; -} - -/// The imports needed for a guest to run on a Spin host -world platform { - include wasi:cli/imports@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import fermyon:spin/llm@2.0.0; - import fermyon:spin/redis@2.0.0; - import fermyon:spin/mqtt@2.0.0; - import fermyon:spin/postgres@2.0.0; - import fermyon:spin/mysql@2.0.0; - import fermyon:spin/sqlite@2.0.0; - import fermyon:spin/key-value@2.0.0; - import fermyon:spin/variables@2.0.0; -} - -/// Like `platform`, but using WASI 0.2.0-rc-2023-10-18 -world platform-rc20231018 { - include wasi:cli/reactor@0.2.0-rc-2023-10-18; - import wasi:http/outgoing-handler@0.2.0-rc-2023-10-18; - import fermyon:spin/llm@2.0.0; - import fermyon:spin/redis@2.0.0; - import fermyon:spin/mqtt@2.0.0; - import fermyon:spin/postgres@2.0.0; - import fermyon:spin/mysql@2.0.0; - import fermyon:spin/sqlite@2.0.0; - import fermyon:spin/key-value@2.0.0; - import fermyon:spin/variables@2.0.0; -} +package spin:top-level; From fd4c89e5209fe25e59d9e570bc6bb0ccf11a2e09 Mon Sep 17 00:00:00 2001 From: itowlson Date: Wed, 16 Oct 2024 13:17:14 +1300 Subject: [PATCH 3/3] Move tests to platform 3 instead of platform-rc Signed-off-by: itowlson --- .../components/tcp-sockets/src/lib.rs | 6 ++-- tests/test-components/helper/src/lib.rs | 32 +++++++++++-------- wit/deps/spin@3.0.0/world.wit | 11 +------ 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/tests/test-components/components/tcp-sockets/src/lib.rs b/tests/test-components/components/tcp-sockets/src/lib.rs index a2a682348d..541cd4c94e 100644 --- a/tests/test-components/components/tcp-sockets/src/lib.rs +++ b/tests/test-components/components/tcp-sockets/src/lib.rs @@ -1,6 +1,6 @@ use bindings::wasi::{ - io0_2_0_rc_2023_10_18::poll, - sockets0_2_0_rc_2023_10_18::{ + io0_2_0::poll, + sockets0_2_0::{ instance_network, network::{ ErrorCode, IpAddressFamily, IpSocketAddress, Ipv4SocketAddress, Ipv6SocketAddress, @@ -43,7 +43,7 @@ impl Component { let (rx, tx) = loop { match client.finish_connect() { - Err(ErrorCode::WouldBlock) => poll::poll_one(&client.subscribe()), + Err(ErrorCode::WouldBlock) => { poll::poll(&[&client.subscribe()]); }, result => break ensure_ok!(result), } }; diff --git a/tests/test-components/helper/src/lib.rs b/tests/test-components/helper/src/lib.rs index a9cb230980..bcf056f47f 100644 --- a/tests/test-components/helper/src/lib.rs +++ b/tests/test-components/helper/src/lib.rs @@ -1,18 +1,18 @@ #[cfg(feature = "define-component")] pub mod bindings { wit_bindgen::generate!({ - world: "platform-rc20231018", + world: "fermyon:spin/platform@3.0.0", path: "../../../wit", runtime_path: "::wit_bindgen::rt" }); } #[cfg(feature = "define-component")] -use bindings::wasi::http0_2_0_rc_2023_10_18::types::{ - Error, Headers, OutgoingBody, OutgoingResponse, ResponseOutparam, +use bindings::wasi::http0_2_0::types::{ + ErrorCode, Fields, OutgoingBody, OutgoingResponse, ResponseOutparam, }; #[cfg(feature = "define-component")] -use bindings::wasi::io0_2_0_rc_2023_10_18::streams::OutputStream; +use bindings::wasi::io0_2_0::streams::OutputStream; #[cfg(feature = "define-component")] #[macro_export] @@ -23,15 +23,15 @@ macro_rules! define_component { // For now, this assumes the crate using this macro has `wit-bindgen` as a dependency mod bindings { $crate::wit_bindgen::generate!({ - world: "http-trigger-rc20231018", + world: "fermyon:spin/http-trigger@3.0.0", path: "../../../../wit", exports: { - "wasi:http/incoming-handler@0.2.0-rc-2023-10-18": super::Component + "wasi:http/incoming-handler@0.2.0": super::Component }, }); } - use bindings::exports::wasi::http0_2_0_rc_2023_10_18::incoming_handler::{Guest, IncomingRequest, ResponseOutparam}; + use bindings::exports::wasi::http0_2_0::incoming_handler::{Guest, IncomingRequest, ResponseOutparam}; struct $name; impl Guest for $name { @@ -40,7 +40,7 @@ macro_rules! define_component { } } - impl From for $crate::bindings::wasi::http0_2_0_rc_2023_10_18::types::ResponseOutparam { + impl From for $crate::bindings::wasi::http0_2_0::types::ResponseOutparam { fn from(value: ResponseOutparam) -> Self { unsafe { Self::from_handle(value.into_handle()) } } @@ -50,12 +50,16 @@ macro_rules! define_component { #[cfg(feature = "define-component")] pub fn handle(response_out: ResponseOutparam, result: Result<(), String>) { - let response = |status| OutgoingResponse::new(status, &Headers::new(&[])); + let response = |status| { + let resp = OutgoingResponse::new(Fields::new()); + resp.set_status_code(status).expect("should have set status code"); + resp + }; match result { Ok(()) => ResponseOutparam::set(response_out, Ok(response(200))), Err(err) => { let resp = response(500); - let body = resp.write().expect("response body was already taken"); + let body = resp.body().unwrap(); ResponseOutparam::set(response_out, Ok(resp)); outgoing_body(body, err.into_bytes()).unwrap(); } @@ -63,14 +67,14 @@ pub fn handle(response_out: ResponseOutparam, result: Result<(), String>) { } #[cfg(feature = "define-component")] -pub fn outgoing_body(body: OutgoingBody, buffer: Vec) -> Result<(), Error> { +pub fn outgoing_body(body: OutgoingBody, buffer: Vec) -> Result<(), ErrorCode> { struct Outgoing(Option<(OutputStream, OutgoingBody)>); impl Drop for Outgoing { fn drop(&mut self) { if let Some((stream, body)) = self.0.take() { drop(stream); - OutgoingBody::finish(body, None); + OutgoingBody::finish(body, None).expect("should have finished OutgoingBody"); } } } @@ -101,11 +105,11 @@ pub fn outgoing_body(body: OutgoingBody, buffer: Vec) -> Result<(), Error> { Ok(()) => { offset += count; } - Err(e) => return Err(Error::ProtocolError(format!("I/O error: {e}"))), + Err(e) => return Err(ErrorCode::InternalError(Some(format!("I/O error: {e}")))), } } } - Err(e) => return Err(Error::ProtocolError(format!("I/O error: {e}"))), + Err(e) => return Err(ErrorCode::InternalError(Some(format!("I/O error: {e}")))), } } } diff --git a/wit/deps/spin@3.0.0/world.wit b/wit/deps/spin@3.0.0/world.wit index a959cb002c..e920055a9a 100644 --- a/wit/deps/spin@3.0.0/world.wit +++ b/wit/deps/spin@3.0.0/world.wit @@ -8,14 +8,5 @@ world http-trigger { /// The imports needed for a guest to run on a Spin host world platform { - include wasi:cli/imports@0.2.0; - import wasi:http/outgoing-handler@0.2.0; - import fermyon:spin/llm@2.0.0; - import fermyon:spin/redis@2.0.0; - import fermyon:spin/mqtt@2.0.0; - import fermyon:spin/postgres@2.0.0; - import fermyon:spin/mysql@2.0.0; - import fermyon:spin/sqlite@2.0.0; - import fermyon:spin/key-value@2.0.0; - import fermyon:spin/variables@2.0.0; + include fermyon:spin/platform@2.0.0; }