Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add host module for ww proc API. #111

Closed
wants to merge 3 commits into from
Closed
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
10 changes: 4 additions & 6 deletions api/process.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ $Go.import("github.com/wetware/ww/internal/api/process");


interface Executor {
spawn @0 (byteCode :Data, entryPoint :Text = "run") -> (process :Process);
# spawn a WASM based process from the binary module with the target
# entry function
exec @0 (bytecode :Data) -> (process :Process);
# exec a WASM based process
}

interface Process {
start @0 () -> ();
stop @1 () -> ();
wait @2 () -> (exitCode :UInt32);
wait @0 () -> (exitCode :UInt32);
kill @1 () -> ();
}
8 changes: 4 additions & 4 deletions cmd/ww/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/wetware/ww/internal/cmd/cluster"
"github.com/wetware/ww/internal/cmd/debug"
"github.com/wetware/ww/internal/cmd/run"
"github.com/wetware/ww/internal/cmd/start"
ww "github.com/wetware/ww/pkg"
)
Expand Down Expand Up @@ -58,11 +59,12 @@ var flags = []cli.Flag{
var commands = []*cli.Command{
start.Command(),
cluster.Command(),
run.Command(),
debug.Command(),
}

func main() {
run(&cli.App{
app := &cli.App{
Name: "wetware",
HelpName: "ww",
Usage: "simple, secure clusters",
Expand All @@ -75,10 +77,8 @@ func main() {
Metadata: map[string]interface{}{
"version": ww.Version,
},
})
}
}

func run(app *cli.App) {
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/wetware/ww

go 1.19
go 1.20

require (
capnproto.org/go/capnp/v3 v3.0.0-alpha.27
Expand Down Expand Up @@ -35,6 +35,7 @@ require (
github.com/ipfs/go-ds-badger2 v0.1.3
github.com/lthibault/go-libp2p-inproc-transport v0.4.0
github.com/multiformats/go-multistream v0.4.1
github.com/stealthrocket/wazergo v0.12.0
github.com/stretchr/testify v1.8.2
github.com/tetratelabs/wazero v1.0.1
github.com/thejerf/suture/v4 v4.0.2
Expand Down Expand Up @@ -126,7 +127,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_golang v1.15.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-19 v0.3.2 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
github.com/polydawn/refmt v0.89.0 h1:ADJTApkvkeBZsN0tBTx8QjpD9JkmxbKp0cxfr9qszm4=
github.com/polydawn/refmt v0.89.0/go.mod h1:/zvteZs/GwLtCgZ4BL6CBsk9IKIlexP43ObX9AxTqTw=
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
github.com/prometheus/client_golang v1.15.0 h1:5fCgGYogn0hFdhyhLbw7hEsWxufKtY9klyvdNfFlFhM=
github.com/prometheus/client_golang v1.15.0/go.mod h1:e9yaBhRPU2pPNsZwE+JdQl0KEt1N9XgF6zxWmaC0xOk=
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
Expand Down Expand Up @@ -472,6 +472,8 @@ github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tL
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DMA2s=
github.com/stealthrocket/wazergo v0.12.0 h1:H0FrKGPsNlIimYQobQDnvRS2XduTvQSCCH0IIp1LDA8=
github.com/stealthrocket/wazergo v0.12.0/go.mod h1:ONoLQpwgBDX9VGB+CCAbzTNDmJJi5kcnFLL+pWIGF5M=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
Expand Down
15 changes: 15 additions & 0 deletions guest/tinygo/imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build wasm || tinygo.wasm || wasi

package ww

//go:wasm-module ww
//export __host_read
func hostRead(offset, length uint32, n *uint32) int32

//go:wasm-module ww
//export __host_write
func hostWrite(offset, length uint32, n *uint32) int32

//go:wasm-module ww
//go:export __host_close
func hostClose() int32
22 changes: 22 additions & 0 deletions guest/tinygo/shims.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//go:build !purego && !appengine && !wasm && !tinygo.wasm && !wasi

package ww

/*

shims.go contains shim functions for WASM imports, which allows
symbol names to resolve on non-WASM architectures.

*/

func hostRead(offset, length uint32, n *uint32) int32 {
return 0
}

func hostWrite(offset, length uint32, n *uint32) int32 {
return 0
}

func hostClose() int32 {
return 0
}
11 changes: 11 additions & 0 deletions guest/tinygo/testdata/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import (
"fmt"

ww "github.com/wetware/ww/guest/tinygo"
)

func main() {
fmt.Println(ww.Boostrasp())
}
Binary file added guest/tinygo/testdata/main.wasm
Binary file not shown.
515,403 changes: 515,403 additions & 0 deletions guest/tinygo/testdata/main.wat

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions guest/tinygo/ww.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Package ww contains Wetware bindings for WASM guest-code.
package ww

import (
"context"
"unsafe"

"capnproto.org/go/capnp/v3/rpc"

"github.com/wetware/ww/internal/api/cluster"

"github.com/stealthrocket/wazergo/types"
)

var (
conn = rpc.NewConn(rpc.NewStreamTransport(hostPipe{}), nil)
h = cluster.Host(conn.Bootstrap(context.Background()))
)

type hostPipe struct{}

func (hostPipe) Read(b []byte) (int, error) {
var n uint32
err := hostRead(bytesToPointer(b), uint32(len(b)), &n)
return int(n), types.Errno(err)
}

func (hostPipe) Write(b []byte) (int, error) {
var n uint32
err := hostWrite(bytesToPointer(b), uint32(len(b)), &n)
return int(n), types.Errno(err)
}

func (hostPipe) Close() error {
return types.Errno(hostClose())
}

func Boostrasp() cluster.Host {
return h
}

// func Root(ctx context.Context) (anchor.Anchor, capnp.ReleaseFunc) {
// // FIXME: return the root anchor. Right now we just return the
// // local host anchor.
// f, release := host.Root(ctx, nil)
// return anchor.Anchor(f.Root()), release
// }

//go:inline
func bytesToPointer(b []byte) uint32 {
return *(*uint32)(unsafe.Pointer(unsafe.SliceData(b)))
}
Loading