Skip to content

Commit

Permalink
Merge pull request #17 from golemcloud/wasmtime-17
Browse files Browse the repository at this point in the history
GOL-183 Updated examples for final WASI Preview2
  • Loading branch information
vigoo authored Feb 2, 2024
2 parents 01aaf23 + 47676e2 commit 5fb25d1
Show file tree
Hide file tree
Showing 26 changed files with 843 additions and 841 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ once_cell = { version = "1.19.0" }
fancy-regex = { version = "0.13.0" }
serde = { version = "1.0.195", features = ["derive"] }
serde_json = { version = "1.0.111" }
strum = "0.25.0"
strum_macros = "0.25.3"
strum = "0.26.1"
strum_macros = "0.26.1"

clap = { version = "4.4.17", features = ["derive"], optional = true }

Expand Down
66 changes: 33 additions & 33 deletions examples/go/go-actor-full/roundtrip/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,41 @@ type WasiHttpTransport struct {

func (t WasiHttpTransport) RoundTrip(request *http.Request) (*http.Response, error) {

var headerKeyValues []go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesTuple2FieldKeyFieldValueT
var headerKeyValues []go_wasi_http.WasiHttp0_2_0_TypesTuple2FieldKeyFieldValueT
for key, values := range request.Header {
for _, value := range values {
headerKeyValues = append(headerKeyValues, go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesTuple2FieldKeyFieldValueT{
headerKeyValues = append(headerKeyValues, go_wasi_http.WasiHttp0_2_0_TypesTuple2FieldKeyFieldValueT{
F0: key,
F1: []byte(value),
})
}
}
headers := go_wasi_http.StaticFieldsFromList(headerKeyValues).Unwrap()

var method go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethod
var method go_wasi_http.WasiHttp0_2_0_TypesMethod
switch strings.ToUpper(request.Method) {
case "":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodGet()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodGet()
case "GET":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodGet()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodGet()
case "HEAD":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodHead()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodHead()
case "POST":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodPost()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodPost()
case "PUT":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodPut()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodPut()
case "DELETE":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodDelete()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodDelete()
case "CONNECT":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodConnect()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodConnect()
case "OPTIONS":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodOptions()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodOptions()
case "TRACE":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodTrace()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodTrace()
case "PATCH":
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodPatch()
method = go_wasi_http.WasiHttp0_2_0_TypesMethodPatch()
default:
method = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesMethodOther(request.Method)
method = go_wasi_http.WasiHttp0_2_0_TypesMethodOther(request.Method)
}

path := request.URL.Path
Expand All @@ -60,14 +60,14 @@ func (t WasiHttpTransport) RoundTrip(request *http.Request) (*http.Response, err
pathAndQuery += "?" + query
}

var scheme go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesScheme
var scheme go_wasi_http.WasiHttp0_2_0_TypesScheme
switch strings.ToLower(request.URL.Scheme) {
case "http":
scheme = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesSchemeHttp()
scheme = go_wasi_http.WasiHttp0_2_0_TypesSchemeHttp()
case "https":
scheme = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesSchemeHttps()
scheme = go_wasi_http.WasiHttp0_2_0_TypesSchemeHttps()
default:
scheme = go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesSchemeOther(request.URL.Scheme)
scheme = go_wasi_http.WasiHttp0_2_0_TypesSchemeOther(request.URL.Scheme)
}

userPassword := request.URL.User.String()
Expand Down Expand Up @@ -118,20 +118,20 @@ func (t WasiHttpTransport) RoundTrip(request *http.Request) (*http.Response, err
}

requestStream.Drop()
go_wasi_http.StaticOutgoingBodyFinish(requestBody, go_wasi_http.None[go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesTrailers]())
go_wasi_http.StaticOutgoingBodyFinish(requestBody, go_wasi_http.None[go_wasi_http.WasiHttp0_2_0_TypesTrailers]())
// requestBody.Drop() // TODO: this fails with "unknown handle index 0"
}

// TODO: timeouts
connectTimeoutMs := go_wasi_http.None[uint64]()
firstByteTimeoutMs := go_wasi_http.None[uint64]()
betweenBytesTimeoutMs := go_wasi_http.None[uint64]()
connectTimeoutNanos := go_wasi_http.None[uint64]()
firstByteTimeoutNanos := go_wasi_http.None[uint64]()
betweenBytesTimeoutNanos := go_wasi_http.None[uint64]()
options := go_wasi_http.NewRequestOptions()
options.SetConnectTimeoutMs(connectTimeoutMs)
options.SetFirstByteTimeoutMs(firstByteTimeoutMs)
options.SetBetweenBytesTimeoutMs(betweenBytesTimeoutMs)
options.SetConnectTimeout(connectTimeoutNanos)
options.SetFirstByteTimeout(firstByteTimeoutNanos)
options.SetBetweenBytesTimeout(betweenBytesTimeoutNanos)

futureResult := go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_OutgoingHandlerHandle(requestHandle, go_wasi_http.Some(options))
futureResult := go_wasi_http.WasiHttp0_2_0_OutgoingHandlerHandle(requestHandle, go_wasi_http.Some(options))
if futureResult.IsErr() {
return nil, errors.New("Failed to send request")
}
Expand Down Expand Up @@ -205,7 +205,7 @@ func (t WasiHttpTransport) RoundTrip(request *http.Request) (*http.Response, err
return &response, nil
}

func GetIncomingResponse(future go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_OutgoingHandlerFutureIncomingResponse) (go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesIncomingResponse, error) {
func GetIncomingResponse(future go_wasi_http.WasiHttp0_2_0_OutgoingHandlerFutureIncomingResponse) (go_wasi_http.WasiHttp0_2_0_TypesIncomingResponse, error) {
result := future.Get()
if result.IsSome() {
result2 := result.Unwrap()
Expand All @@ -225,17 +225,17 @@ func GetIncomingResponse(future go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_Outgoin
}

type WasiStreamReader struct {
Stream go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesInputStream
Body go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesIncomingBody
OutgoingRequest go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesOutgoingRequest
IncomingResponse go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesIncomingResponse
Future go_wasi_http.WasiHttp0_2_0_rc_2023_11_10_TypesFutureIncomingResponse
Stream go_wasi_http.WasiHttp0_2_0_TypesInputStream
Body go_wasi_http.WasiHttp0_2_0_TypesIncomingBody
OutgoingRequest go_wasi_http.WasiHttp0_2_0_TypesOutgoingRequest
IncomingResponse go_wasi_http.WasiHttp0_2_0_TypesIncomingResponse
Future go_wasi_http.WasiHttp0_2_0_TypesFutureIncomingResponse
}

func (reader WasiStreamReader) Read(p []byte) (int, error) {
c := cap(p)
result := reader.Stream.BlockingRead(uint64(c))
isEof := result.IsErr() && result.UnwrapErr() == go_wasi_http.WasiIo0_2_0_rc_2023_11_10_StreamsStreamErrorClosed()
isEof := result.IsErr() && result.UnwrapErr() == go_wasi_http.WasiIo0_2_0_StreamsStreamErrorClosed()
if isEof {
return 0, io.EOF
} else if result.IsErr() {
Expand Down
8 changes: 4 additions & 4 deletions examples/go/go-actor-full/wit/component-name.wit
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ interface api {

world component-name {
import golem:api/host;
import wasi:io/poll@0.2.0-rc-2023-11-10;
import wasi:io/streams@0.2.0-rc-2023-11-10;
import wasi:http/types@0.2.0-rc-2023-11-10;
import wasi:http/outgoing-handler@0.2.0-rc-2023-11-10;
import wasi:io/poll@0.2.0;
import wasi:io/streams@0.2.0;
import wasi:http/types@0.2.0;
import wasi:http/outgoing-handler@0.2.0;

export api;
}
46 changes: 23 additions & 23 deletions examples/js/js-actor-minimal/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions examples/js/js-actor-minimal/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"type": "module",
"devDependencies": {
"@bytecodealliance/jco": "0.14.1",
"@bytecodealliance/componentize-js": "0.5.0"
"@bytecodealliance/jco": "1.0.0",
"@bytecodealliance/componentize-js": "0.7.0"
},
"scripts": {
"build": "node componentize.js"
Expand Down
4 changes: 2 additions & 2 deletions examples/rust/rust-actor-full/Cargo.toml._
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ lto = true
opt-level = 's'

[dependencies]
cargo-component-bindings = { version = "0.5.0" }
wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"] }

fs = "0.0.5"
rand = "0.8.5"
reqwest = { git = "https://github.com/zivergetech/reqwest", branch = "update-jan-2024", features = ["json"] }
reqwest = { git = "https://github.com/zivergetech/reqwest", branch = "update-feb-2024", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
time = { version = "0.3.21", features = ["formatting"] }
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/rust-actor-full/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cargo_component_bindings::generate!();
mod bindings;

use crate::bindings::exports::pack::name::api::*;
use crate::bindings::golem::api::host::*;
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/rust-actor-minimal/Cargo.toml._
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ lto = true
opt-level = 's'

[dependencies]
cargo-component-bindings = { version = "0.5.0" }
wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"] }

[package.metadata.component.target]
path = "wit"
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/rust-actor-minimal/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cargo_component_bindings::generate!();
mod bindings;

use crate::bindings::exports::pack::name::api::*;

Expand Down
1 change: 1 addition & 0 deletions examples/rust/rust-auction/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"

members = [
"auction",
Expand Down
4 changes: 2 additions & 2 deletions examples/rust/rust-auction/auction-registry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ crate-type = ["cdylib"]
once_cell = "1.17.1"
rand = "0.8.5"
uuid = { version = "1.4.1", features = ["v4", "serde"] }
cargo-component-bindings = { version = "0.5.0" }
reqwest = { git = "https://github.com/zivergetech/reqwest", branch = "update-jan-2024", features = ["json"] }
wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"] }
reqwest = { git = "https://github.com/zivergetech/reqwest", branch = "update-feb-2024", features = ["json"] }
serde = { version = "1.0.130", features = ["derive"] }

[package.metadata.component.target]
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/rust-auction/auction-registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod auction;
mod auction_registry_logic;
mod model;

cargo_component_bindings::generate!();
mod bindings;

use bindings::*;
use exports::pack::name::api::{
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/rust-auction/auction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crate-type = ["cdylib"]
once_cell = "1.17.1"
rand = "0.8.5"
uuid = { version = "1.4.1", features = ["v4"] }
cargo-component-bindings = { version = "0.5.0" }
wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"] }

[package.metadata.component.target]
path = "wit"
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/rust-auction/auction/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod auction_logic;
mod model;

cargo_component_bindings::generate!();
mod bindings;

use bindings::*;
use exports::pack::name::api::{
Expand Down
1 change: 1 addition & 0 deletions examples/rust/rust-hello-tests/Cargo.toml._
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"

members = [
"app",
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/rust-hello-tests/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ path = "wit"

[dependencies]
lib = { path = "../lib" }
cargo-component-bindings = { version = "0.5.0" }
wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"] }
2 changes: 1 addition & 1 deletion examples/rust/rust-hello-tests/wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cargo_component_bindings::generate!();
mod bindings;

use crate::bindings::exports::pack::name::api::*;
use lib::core;
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/rust-shopping-cart/Cargo.toml._
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ opt-level = 's'
[dependencies]
once_cell = "1.17.1"
rand = "0.8.5"
cargo-component-bindings = { version = "0.5.0" }
wit-bindgen = { version = "0.16.0", default-features = false, features = ["realloc"] }

[package.metadata.component.target]
path = "wit"
Expand Down
Loading

0 comments on commit 5fb25d1

Please sign in to comment.