Skip to content

Commit 1ffa0a7

Browse files
authored
Merge pull request #35 from dicej/multiple-sdks
support combining SDKs with multiple WIT worlds
2 parents f365a7a + 0f17434 commit 1ffa0a7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+4942
-2184
lines changed

.github/workflows/pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ jobs:
3636
go-version: 'stable'
3737
- uses: bytecodealliance/actions/wasmtime/setup@v1
3838
with:
39-
version: "40.0.2"
39+
version: "43.0.0"
4040
- run: rustup update stable --no-self-update && rustup default stable
4141
- run: cargo test --workspace

Cargo.lock

Lines changed: 56 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ allow_attributes_without_reason = 'warn'
3737
anyhow = { workspace = true}
3838
clap = { version = "4.5.60", features = ["derive"] }
3939
regex = "1.12.3"
40-
wat = { version = "1.245.1"}
40+
serde = { version = "1.0.228", features = ["derive"] }
41+
toml = "1.1.0"
4142
wit-bindgen-go = { git = "https://github.com/bytecodealliance/wit-bindgen", rev = "3ee9fe20a5bce398360d5d291e81a4224a6d7c76" }
4243
wit-component = "0.245.1"
4344
wit-parser = "0.245.1"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package export_wasi_http_handler
2+
3+
import (
4+
. "wit_component/wasi_http_types"
5+
6+
. "go.bytecodealliance.org/pkg/wit/types"
7+
)
8+
9+
// Handle the specified `Request`, returning a `Response`
10+
func Handle(request *Request) Result[*Response, ErrorCode] {
11+
method := request.GetMethod().Tag()
12+
path := request.GetPathWithQuery().SomeOr("/")
13+
14+
if method == MethodGet && path == "/hello" {
15+
// Say hello!
16+
17+
tx, rx := MakeStreamU8()
18+
19+
go func() {
20+
defer tx.Drop()
21+
tx.WriteAll([]uint8("Hello, world!"))
22+
}()
23+
24+
response, send := ResponseNew(
25+
FieldsFromList([]Tuple2[string, []byte]{
26+
{F0: "content-type", F1: []byte("text/plain")},
27+
}).Ok(),
28+
Some(rx),
29+
trailersFuture(),
30+
)
31+
send.Drop()
32+
33+
return Ok[*Response, ErrorCode](response)
34+
35+
} else {
36+
// Bad request
37+
38+
response, send := ResponseNew(
39+
MakeFields(),
40+
None[*StreamReader[uint8]](),
41+
trailersFuture(),
42+
)
43+
send.Drop()
44+
response.SetStatusCode(400).Ok()
45+
46+
return Ok[*Response, ErrorCode](response)
47+
48+
}
49+
}
50+
51+
func trailersFuture() *FutureReader[Result[Option[*Fields], ErrorCode]] {
52+
tx, rx := MakeFutureResultOptionFieldsErrorCode()
53+
go tx.Write(Ok[Option[*Fields], ErrorCode](None[*Fields]()))
54+
return rx
55+
}
56+
57+
func unitFuture() *FutureReader[Result[Unit, ErrorCode]] {
58+
tx, rx := MakeFutureResultUnitErrorCode()
59+
go tx.Write(Ok[Unit, ErrorCode](Unit{}))
60+
return rx
61+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package export_wit_world
2+
3+
func Foo() {}

0 commit comments

Comments
 (0)