diff --git a/cmd/internal/run/run.go b/cmd/internal/run/run.go index 5e37ac5..7365b19 100644 --- a/cmd/internal/run/run.go +++ b/cmd/internal/run/run.go @@ -79,12 +79,15 @@ func run() cli.ActionFunc { } defer d.Close() + // fetches for `ww run ` + bootloader := unixFSNode{ + Name: c.Args().First(), + Unix: ipfs.Unixfs()} + return ww.Env{ IPFS: ipfs, Host: h, - Boot: unixFSNode{ - Name: c.Args().Get(1), - Unix: ipfs.Unixfs()}, + Boot: bootloader, WASM: wazero.NewRuntimeConfig(). WithDebugInfoEnabled(c.Bool("debug")). WithCloseOnContextDone(true), diff --git a/examples/hello-world/main.go b/examples/echo/main.go similarity index 75% rename from examples/hello-world/main.go rename to examples/echo/main.go index 980bee5..ac12d3f 100644 --- a/examples/hello-world/main.go +++ b/examples/echo/main.go @@ -3,9 +3,10 @@ package main import ( + "io" "os" ) func main() { - os.Exit(0) + io.Copy(os.Stdout, os.Stdin) } diff --git a/examples/echo/main.wasm b/examples/echo/main.wasm new file mode 100755 index 0000000..0ac007d Binary files /dev/null and b/examples/echo/main.wasm differ diff --git a/examples/hello-world/main.wasm b/examples/hello-world/main.wasm deleted file mode 100755 index 13f4c72..0000000 Binary files a/examples/hello-world/main.wasm and /dev/null differ diff --git a/testdata/main.go b/testdata/main.go deleted file mode 100644 index 3097d65..0000000 --- a/testdata/main.go +++ /dev/null @@ -1,20 +0,0 @@ -//go:generate env GOOS=wasip1 GOARCH=wasm go build -o main.wasm - -package main - -import ( - "fmt" - "io" - "os" -) - -func main() { - n, err := io.Copy(os.Stdout, os.Stdin) - fmt.Fprintf(os.Stderr, "copied %d bytes", n) - if err != nil { - fmt.Println(err) - os.Exit(1) - } else { - os.Exit(0) - } -} diff --git a/testdata/main.wasm b/testdata/main.wasm deleted file mode 100755 index 92eb4b9..0000000 Binary files a/testdata/main.wasm and /dev/null differ diff --git a/ww_test.go b/ww_test.go index dd87df1..dabc498 100644 --- a/ww_test.go +++ b/ww_test.go @@ -14,7 +14,7 @@ import ( ww "github.com/wetware/go" ) -//go:embed testdata/main.wasm +//go:embed examples/echo/main.wasm var fileContent []byte func TestEcho(t *testing.T) { @@ -42,12 +42,12 @@ func TestEcho(t *testing.T) { // WithDebugInfoEnabled(true). WithCloseOnContextDone(true), Module: wazero.NewModuleConfig(). - WithArgs("/testdata/main.wasm"). + WithArgs("/examples/echo/main.wasm"). WithStdin(stdin). WithStdout(stdout). WithStderr(stderr). WithFSConfig(wazero.NewFSConfig(). - WithDirMount("testdata", "/testdata/")), + WithDirMount("examples/echo", "/examples/echo/")), }.Serve(ctx) require.NoError(t, err, "server failed")