Skip to content

Commit

Permalink
πŸš‘ bugfix: missing wazero default system resource functions (#42)
Browse files Browse the repository at this point in the history
* πŸš‘ fix: default critical system function missing

Signed-off-by: Gaukas Wang <[email protected]>

* ⬆️ deps: bump wazero to v1.6.5-w

Signed-off-by: Gaukas Wang <[email protected]>

* πŸ”› update: add commented wazero logging via ctx

Signed-off-by: Gaukas Wang <[email protected]>

---------

Signed-off-by: Gaukas Wang <[email protected]>
  • Loading branch information
gaukas authored Jan 31, 2024
1 parent 1acc17f commit 9111551
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
7 changes: 6 additions & 1 deletion examples/v0/listener/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ func main() {
config.ModuleConfig().InheritStdout()
config.ModuleConfig().InheritStderr()

lis, err := config.ListenContext(context.Background(), "tcp", *localAddr)
ctx := context.Background()
// // optional: enable wazero logging
// ctx = context.WithValue(ctx, experimental.FunctionListenerFactoryKey{},
// logging.NewHostLoggingListenerFactory(os.Stderr, logging.LogScopeFilesystem|logging.LogScopePoll|logging.LogScopeSock))

lis, err := config.ListenContext(ctx, "tcp", *localAddr)
if err != nil {
panic(fmt.Sprintf("failed to listen: %v", err))
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module github.com/gaukas/water

go 1.20

replace github.com/tetratelabs/wazero v1.6.0 => github.com/gaukas/wazero v1.6.4-w
replace github.com/tetratelabs/wazero v1.6.0 => github.com/gaukas/wazero v1.6.5-w

require (
github.com/tetratelabs/wazero v1.6.0
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
google.golang.org/protobuf v1.32.0
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
github.com/gaukas/wazero v1.6.4-w h1:HgAulM1u4jdkMJMn5GFuA/2CB/IMmsEFQTo2EUxvzgI=
github.com/gaukas/wazero v1.6.4-w/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
github.com/gaukas/wazero v1.6.5-w h1:tSQbdHJjYcH9GmQ/5aObsTdbsw44pRT2eqw8HXIuWKg=
github.com/gaukas/wazero v1.6.5-w/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b h1:kLiC65FbiHWFAOu+lxwNPujcsl8VYyTYYEZnsOO1WK4=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
6 changes: 4 additions & 2 deletions wazero_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"io"
"os"

rand "crypto/rand"

"github.com/tetratelabs/wazero"
)

Expand All @@ -17,7 +19,7 @@ type WazeroModuleConfigFactory struct {
// NewWazeroModuleConfigFactory creates a new WazeroModuleConfigFactory.
func NewWazeroModuleConfigFactory() *WazeroModuleConfigFactory {
return &WazeroModuleConfigFactory{
moduleConfig: wazero.NewModuleConfig(),
moduleConfig: wazero.NewModuleConfig().WithSysWalltime().WithSysNanotime().WithSysNanosleep().WithRandSource(rand.Reader),
fsconfig: wazero.NewFSConfig(),
}
}
Expand All @@ -36,7 +38,7 @@ func (wmcf *WazeroModuleConfigFactory) Clone() *WazeroModuleConfigFactory {
// GetConfig returns the latest wazero.ModuleConfig.
func (wmcf *WazeroModuleConfigFactory) GetConfig() wazero.ModuleConfig {
if wmcf == nil {
return wazero.NewModuleConfig()
return wazero.NewModuleConfig().WithSysWalltime().WithSysNanotime().WithSysNanosleep().WithRandSource(rand.Reader)
}

return wmcf.moduleConfig.WithFSConfig(wmcf.fsconfig)
Expand Down

0 comments on commit 9111551

Please sign in to comment.