-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2887 from itowlson/world3
Spin 3 world
- Loading branch information
Showing
15 changed files
with
76 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ wasmtime::component::bindgen!({ | |
world host { | ||
include fermyon:spin/host; | ||
include fermyon:spin/[email protected]; | ||
include fermyon:spin/[email protected]; | ||
} | ||
"#, | ||
path: "../../wit", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/[email protected]-rc-2023-10-18": super::Component | ||
"wasi:http/[email protected]": 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<ResponseOutparam> for $crate::bindings::wasi::http0_2_0_rc_2023_10_18::types::ResponseOutparam { | ||
impl From<ResponseOutparam> for $crate::bindings::wasi::http0_2_0::types::ResponseOutparam { | ||
fn from(value: ResponseOutparam) -> Self { | ||
unsafe { Self::from_handle(value.into_handle()) } | ||
} | ||
|
@@ -50,27 +50,31 @@ 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(); | ||
} | ||
} | ||
} | ||
|
||
#[cfg(feature = "define-component")] | ||
pub fn outgoing_body(body: OutgoingBody, buffer: Vec<u8>) -> Result<(), Error> { | ||
pub fn outgoing_body(body: OutgoingBody, buffer: Vec<u8>) -> 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<u8>) -> 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}")))), | ||
} | ||
} | ||
} | ||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
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 fermyon:spin/platform@2.0.0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1 @@ | ||
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; | ||
} | ||
package spin:top-level; |