Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions boot/components/runtime/wasm/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ func TestDefaultHostProfiles(t *testing.T) {
"funcs", "wasi1",
"wasi:io", "wasi:poll", "wasi:clocks", "wasi:cli",
"wasi:filesystem", "wasi:random", "wasi:sockets", "wasi:http",
// Core modules cannot import wasi:sockets or wasi:http, both of which are
// component-only, so they get outbound TCP through this one instead.
"wippy:sock/tcp",
}
if len(profiles) != len(want) {
t.Fatalf("DefaultHostProfiles() len = %d, want %d", len(profiles), len(want))
Expand Down
53 changes: 53 additions & 0 deletions boot/components/runtime/wasm/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ package wasm
import (
"context"

"github.com/tetratelabs/wazero/api"

"github.com/wippyai/runtime/api/dispatcher"
runtimewasm "github.com/wippyai/runtime/runtime/wasm"
wasmcomponent "github.com/wippyai/runtime/runtime/wasm/component"
"github.com/wippyai/runtime/runtime/wasm/host/wippy/hosts/coresock"
wasmrt "github.com/wippyai/wasm-runtime/runtime"
"github.com/wippyai/wasm-runtime/wasi/preview2"
"go.uber.org/zap"
Expand All @@ -29,6 +32,7 @@ func DefaultHostProfiles(log *zap.Logger, disp dispatcher.Dispatcher) []wasmcomp
wasiRandomProfile(log),
wasiSocketsProfile(log),
wasiHTTPProfile(disp, log),
coreSockProfile(log),
}
}

Expand Down Expand Up @@ -151,3 +155,52 @@ func wasiHTTPProfile(d dispatcher.Dispatcher, log *zap.Logger) wasmcomponent.Hos
},
}
}

// coreSockProfile exposes outbound TCP to core modules.
//
// Deliberately not ComponentOnly: wasi:sockets and wasi:http both are, so a core
// module has no way to reach the network at all. The signatures are raw integers
// because that is what a core import can express, and the calls are async so the
// guest yields while the host waits on the connection.
func coreSockProfile(log *zap.Logger) wasmcomponent.HostProfile {
return wasmcomponent.HostProfile{
Name: coresock.Namespace,
Aliases: []string{coresock.Namespace, "wippy:sock"},
Register: func(_ context.Context, rt *wasmrt.Runtime) error {
host := coresock.New(log)
i32, i64 := api.ValueTypeI32, api.ValueTypeI64

// Registered synchronous on purpose. Declaring them async makes the
// engine asyncify-transform the whole guest, and instrumenting a 10 MB
// interpreter pushes wazero's compile past the runtime's 30s entry-load
// timeout. The guest call is synchronous anyway, so the host blocking on
// the socket is exactly the required behavior.
register := func(name string, params, results []api.ValueType, fn api.GoModuleFunc) error {
if err := rt.RegisterCoreFunc(coresock.Namespace, name, params, results, fn, false); err != nil {
return runtimewasm.NewRegisterHostError(coresock.Namespace, err)
}
return nil
}

if err := register("connect",
[]api.ValueType{i32, i32, i32, i32}, []api.ValueType{i64}, host.Connect); err != nil {
return err
}
if err := register("send",
[]api.ValueType{i32, i32, i32}, []api.ValueType{i64}, host.Send); err != nil {
return err
}
if err := register("recv",
[]api.ValueType{i32, i32, i32}, []api.ValueType{i64}, host.Recv); err != nil {
return err
}
if err := register("close",
[]api.ValueType{i32}, []api.ValueType{i32}, host.Close); err != nil {
return err
}

log.Info("wasm host profile registered", zap.String("profile", coresock.Namespace))
return nil
},
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ require (
github.com/wippyai/tree-sitter-markdown v0.0.3
github.com/wippyai/tree-sitter-sql v0.0.4
github.com/wippyai/wapp v0.1.2
github.com/wippyai/wasm-runtime v0.0.0-20260719152804-ec6962b31c64
github.com/wippyai/wasm-runtime v0.0.0-20260731193643-289ea709d8e8
github.com/xuri/excelize/v2 v2.11.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.69.0
go.opentelemetry.io/otel v1.44.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ github.com/wippyai/wapp v0.1.2 h1:fCoxKr9s3gk+pWx4XcnIQmOVgPiuimXf3QcE9mHbdmw=
github.com/wippyai/wapp v0.1.2/go.mod h1:ndCkYR80+osLGbd7AFWlP+3DxwooR+R6cxQYPZhksg4=
github.com/wippyai/wasm-runtime v0.0.0-20260719152804-ec6962b31c64 h1:ETP3ZooZzg4hUZYnfz/ZPdqvpWAduQ9nHK+XqkOBkj8=
github.com/wippyai/wasm-runtime v0.0.0-20260719152804-ec6962b31c64/go.mod h1:81IhzsGQBNRyLqynOAYK9WLsMx9CoqtwsEf0B6PwL5k=
github.com/wippyai/wasm-runtime v0.0.0-20260731193643-289ea709d8e8 h1:ELbGKx6QgYh1TUw7rLEv7AqndO9deBbGzmXhBb6Vvpw=
github.com/wippyai/wasm-runtime v0.0.0-20260731193643-289ea709d8e8/go.mod h1:81IhzsGQBNRyLqynOAYK9WLsMx9CoqtwsEf0B6PwL5k=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=
Expand Down
Loading