Skip to content

Commit

Permalink
Add wazergo-based host module for ww. Change process schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
lthibault committed Apr 16, 2023
1 parent 7273263 commit c9f3f16
Show file tree
Hide file tree
Showing 19 changed files with 4,554 additions and 666 deletions.
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
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.11.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
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
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.11.0 h1:uei6jlnTQxjpuhzW31QgSkHi4eVKUaQmOf7WVytOCq8=
github.com/stealthrocket/wazergo v0.11.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
7 changes: 7 additions & 0 deletions guest/tinygo/imports.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//go:build wasm || tinygo.wasm || wasi

package ww

//go:wasm-module ww
//go:export __test
func test(a, b uint32) uint32
14 changes: 14 additions & 0 deletions guest/tinygo/shims.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//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 test(a, b uint32) uint32 {
return a + b
}
18 changes: 18 additions & 0 deletions guest/tinygo/testdata/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"fmt"

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

func main() {
// it, release := ww.Ls(context.Background())
// defer release()

// for name := it.Next(); name != ""; name = it.Next() {
// fmt.Println(name)
// }

fmt.Println(ww.Test(40, 2))
}
Binary file added guest/tinygo/testdata/main.wasm
Binary file not shown.
Loading

0 comments on commit c9f3f16

Please sign in to comment.