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

deps: updates wazero to 1.0.2 #37

Merged
merged 1 commit into from
Apr 19, 2023
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ The following shows the techniqual details:
|---|---|---|---|
|wasmtime|:heavy_check_mark:|:heavy_check_mark:||
|wamr(wasm-micro-runtime)|:heavy_check_mark:|:heavy_check_mark:||
|wazero|:construction: (stdin unsupported)|:heavy_check_mark:|non-blocking stdin doesn't seem to work|
|wazero|:heavy_check_mark:|:heavy_check_mark:||
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks to @ktock @evacchi and @achille-roussel for collaboration on this check mark!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your great work!

|wasmer|:construction: (stdin unsupported)|:heavy_check_mark:|non-blocking stdin doesn't seem to work|
|wasmedge|:construction: (stdin unsupported)|:heavy_check_mark:|non-blocking stdin doesn't seem to work|

Expand Down
2 changes: 1 addition & 1 deletion tests/wazero/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/ktock/container2wasm/examples/wazero

go 1.19

require github.com/tetratelabs/wazero v1.0.1
require github.com/tetratelabs/wazero v1.0.2
4 changes: 2 additions & 2 deletions tests/wazero/go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/tetratelabs/wazero v1.0.1 h1:xyWBoGyMjYekG3mEQ/W7xm9E05S89kJ/at696d/9yuc=
github.com/tetratelabs/wazero v1.0.1/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
github.com/tetratelabs/wazero v1.0.2 h1:lpwL5zczFHk2mxKur98035Gig+Z3vd9JURk6lUdZxXY=
github.com/tetratelabs/wazero v1.0.2/go.mod h1:wYx2gNRg8/WihJfSDxA1TIL8H+GkfLYm+bIfbblu9VQ=
43 changes: 1 addition & 42 deletions tests/wazero/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package main

import (
"bytes"
"context"
crand "crypto/rand"
"flag"
"io"
"os"
"strings"

Expand Down Expand Up @@ -45,48 +43,9 @@ func main() {
}
// we forcibly enable non-blocking read of stdin.
_, err = r.InstantiateModule(ctx, compiled,
wazero.NewModuleConfig().WithSysWalltime().WithSysNanotime().WithSysNanosleep().WithRandSource(crand.Reader).WithStdout(os.Stdout).WithStderr(os.Stderr).WithStdin(newNonBlockReader(os.Stdin)).WithFSConfig(fsConfig).WithArgs(append([]string{"arg0"}, args[1:]...)...))
wazero.NewModuleConfig().WithSysWalltime().WithSysNanotime().WithSysNanosleep().WithRandSource(crand.Reader).WithStdout(os.Stdout).WithStderr(os.Stderr).WithStdin(os.Stdin).WithFSConfig(fsConfig).WithArgs(append([]string{"arg0"}, args[1:]...)...))
if err != nil {
panic(err)
}
return
}

type nonBlockReader struct {
buf *bytes.Buffer
closed bool
}

func newNonBlockReader(r io.Reader) io.Reader {
buf := new(bytes.Buffer) // TODO: FIXME: handle the situation where written bytes exceed the buffer size
br := &nonBlockReader{buf: buf}
go func() {
defer func() {
br.closed = true
}()
var p [1]byte
for {
n, err := r.Read(p[:])
if err != nil {
if err == io.EOF {
return
}
return
}
if n > 0 {
buf.Write(p[:])
}

}
}()
return br
}

func (r *nonBlockReader) Read(p []byte) (int, error) {
n, err := r.buf.Read(p)
if err == io.EOF && !r.closed {
// TinyEMU requires n < -1 if the reader isn't closed yet
n, err = -1, nil
}
return n, err
}