Skip to content

Commit

Permalink
Renames wasi package to wasi_snapshot_preview1
Browse files Browse the repository at this point in the history
The componentized successor to wasi_snapshot_preview1 is not compatible
with the prior imports or even error numbers. Before releasing wazero
1.0 we need to change this package to reflect that WASI 2 is effectively
  a different API.

Fixes #263

Signed-off-by: Adrian Cole <adrian@tetrate.io>
  • Loading branch information
Adrian Cole committed Jun 1, 2022
1 parent 41a3dd3 commit 7b4d862
Show file tree
Hide file tree
Showing 25 changed files with 209 additions and 211 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ space :=
space +=

goimports := golang.org/x/tools/cmd/goimports@v0.1.10
golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.0
golangci_lint := github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
# sync this with netlify.toml!
hugo := github.com/gohugoio/hugo@v0.99.0
hugo := github.com/gohugoio/hugo@v0.100.0

# Make 3.81 doesn't support '**' globbing: Set explicitly instead of recursion.
all_sources := $(wildcard *.go */*.go */*/*.go */*/*/*.go */*/*/*.go */*/*/*/*.go)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bundles an implementation. That way, you don't have to write these functions.
For example, here's how you can allow WebAssembly modules to read
"/work/home/a.txt" as "/a.txt" or "./a.txt":
```go
_, err := wasi.InstantiateSnapshotPreview1(ctx, r)
_, err := wasi_snapshot_preview1.Instantiate(ctx, r)
if err != nil {
log.Panicln(err)
}
Expand Down
2 changes: 1 addition & 1 deletion assemblyscript/assemblyscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// Relationship to WASI
//
// A program compiled to use WASI, via "import wasi" in any file, won't import these functions.
// See wasi.InstantiateSnapshotPreview1
// See wasi_snapshot_preview1.InstantiateSnapshotPreview1
//
// See https://www.assemblyscript.org/concepts.html#special-imports
package assemblyscript
Expand Down
2 changes: 1 addition & 1 deletion builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type ModuleBuilder interface {
//
// Parameters
//
// * name - the name to export. Ex "memory" for wasi.ModuleSnapshotPreview1
// * name - the name to export. Ex "memory" for wasi_snapshot_preview1.ModuleSnapshotPreview1
// * minPages - the possibly zero initial size in pages (65536 bytes per page).
//
// For example, the WebAssembly 1.0 Text Format below is the equivalent of this builder method:
Expand Down
4 changes: 2 additions & 2 deletions examples/allocation/tinygo/greet.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
)

// greetWasm was compiled using `tinygo build -o greet.wasm -scheduler=none --no-debug -target=wasi greet.go`
Expand Down Expand Up @@ -39,7 +39,7 @@ func main() {

// Note: testdata/greet.go doesn't use WASI, but TinyGo needs it to
// implement functions such as panic.
if _, err = wasi.InstantiateSnapshotPreview1(ctx, r); err != nil {
if _, err = wasi_snapshot_preview1.Instantiate(ctx, r); err != nil {
log.Panicln(err)
}

Expand Down
4 changes: 2 additions & 2 deletions examples/wasi/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
)

// catFS is an embedded filesystem limited to test.txt
Expand Down Expand Up @@ -42,7 +42,7 @@ func main() {
config := wazero.NewModuleConfig().WithStdout(os.Stdout).WithFS(rooted)

// Instantiate WASI, which implements system I/O such as console output.
if _, err = wasi.InstantiateSnapshotPreview1(ctx, r); err != nil {
if _, err = wasi_snapshot_preview1.Instantiate(ctx, r); err != nil {
log.Panicln(err)
}

Expand Down
4 changes: 2 additions & 2 deletions experimental/fs_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
)

// This is a basic example of overriding the file system via WithFS. The main goal is to show how it is configured.
Expand All @@ -18,7 +18,7 @@ func Example_withFS() {
r := wazero.NewRuntime()
defer r.Close(ctx) // This closes everything this Runtime created.

if _, err := wasi.InstantiateSnapshotPreview1(ctx, r); err != nil {
if _, err := wasi_snapshot_preview1.Instantiate(ctx, r); err != nil {
log.Panicln(err)
}

Expand Down
4 changes: 2 additions & 2 deletions experimental/listener_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
)

// loggerFactory implements experimental.FunctionListenerFactory to log all function calls to the console.
Expand Down Expand Up @@ -62,7 +62,7 @@ func Example_listener() {
r := wazero.NewRuntimeWithConfig(wazero.NewRuntimeConfigInterpreter())
defer r.Close(ctx) // This closes everything this Runtime created.

if _, err := wasi.InstantiateSnapshotPreview1(ctx, r); err != nil {
if _, err := wasi_snapshot_preview1.Instantiate(ctx, r); err != nil {
log.Panicln(err)
}

Expand Down
4 changes: 2 additions & 2 deletions experimental/time_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/experimental"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
)

const epochNanos = uint64(1640995200000000000) // midnight UTC 2022-01-01
Expand All @@ -20,7 +20,7 @@ func Example_withTimeNowUnixNano() {
r := wazero.NewRuntime()
defer r.Close(ctx) // This closes everything this Runtime created.

if _, err := wasi.InstantiateSnapshotPreview1(ctx, r); err != nil {
if _, err := wasi_snapshot_preview1.Instantiate(ctx, r); err != nil {
log.Panicln(err)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/integration_test/bench/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
)

// testCtx is an arbitrary, non-default context. Non-nil also prevents linter errors.
Expand Down Expand Up @@ -190,7 +190,7 @@ func createRuntime(b *testing.B, config wazero.RuntimeConfig) wazero.Runtime {

// Note: host_func.go doesn't directly use WASI, but TinyGo needs to be initialized as a WASI Command.
// Add WASI to satisfy import tests
_, err = wasi.InstantiateSnapshotPreview1(testCtx, r)
_, err = wasi_snapshot_preview1.Instantiate(testCtx, r)
if err != nil {
b.Fatal(err)
}
Expand Down
20 changes: 10 additions & 10 deletions internal/integration_test/fs/fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import (
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/internal/testing/require"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
)

var testCtx = context.Background()

//go:embed testdata/animals.txt
var animals []byte

// wasiFs is an implementation of fs.Fs calling into wasi. Not thread-safe because we use
// wasiFs is an implementation of fs.Fs calling into wasiWASI. Not thread-safe because we use
// fixed Memory offsets for transferring data with wasm.
type wasiFs struct {
t *testing.T
Expand Down Expand Up @@ -57,16 +57,16 @@ func (fs *wasiFs) Open(name string) (fs.File, error) {
uint64(fd), uint64(dirflags), uint64(pathPtr), uint64(pathLen), uint64(oflags),
fsRightsBase, fsRightsInheriting, uint64(fdflags), uint64(resultOpenedFd))
require.NoError(fs.t, err)
require.Equal(fs.t, uint64(wasi.ErrnoSuccess), res[0])
require.Equal(fs.t, uint64(wasi_snapshot_preview1.ErrnoSuccess), res[0])

resFd, ok := fs.memory.ReadUint32Le(testCtx, resultOpenedFd)
require.True(fs.t, ok)

return &wasiFile{fd: resFd, fs: fs}, nil
}

// wasiFile implements io.Reader and io.Seeker using wasi functions. It does not
// implement io.ReaderAt because there is no wasi function for directly reading
// wasiFile implements io.Reader and io.Seeker using wasiWASI functions. It does not
// implement io.ReaderAt because there is no wasiWASI function for directly reading
// from an offset.
type wasiFile struct {
fd uint32
Expand Down Expand Up @@ -98,7 +98,7 @@ func (f *wasiFile) Read(bytes []byte) (int, error) {
res, err := f.fs.fdRead.Call(testCtx, uint64(f.fd), uint64(iovsOff), uint64(iovsCount), uint64(resultSizeOff))
require.NoError(f.fs.t, err)

require.NotEqual(f.fs.t, uint64(wasi.ErrnoFault), res[0])
require.NotEqual(f.fs.t, uint64(wasi_snapshot_preview1.ErrnoFault), res[0])

numRead, ok := f.fs.memory.ReadUint32Le(testCtx, resultSizeOff)
require.True(f.fs.t, ok)
Expand All @@ -107,7 +107,7 @@ func (f *wasiFile) Read(bytes []byte) (int, error) {
if len(bytes) == 0 {
return 0, nil
}
if wasi.Errno(res[0]) == wasi.ErrnoSuccess {
if wasi_snapshot_preview1.Errno(res[0]) == wasi_snapshot_preview1.ErrnoSuccess {
return 0, io.EOF
} else {
return 0, fmt.Errorf("could not read from file")
Expand All @@ -123,7 +123,7 @@ func (f *wasiFile) Read(bytes []byte) (int, error) {
func (f *wasiFile) Close() error {
res, err := f.fs.fdClose.Call(testCtx, uint64(f.fd))
require.NoError(f.fs.t, err)
require.NotEqual(f.fs.t, uint64(wasi.ErrnoFault), res[0])
require.NotEqual(f.fs.t, uint64(wasi_snapshot_preview1.ErrnoFault), res[0])
return nil
}

Expand All @@ -133,7 +133,7 @@ func (f *wasiFile) Seek(offset int64, whence int) (int64, error) {

res, err := f.fs.fdSeek.Call(testCtx, uint64(f.fd), uint64(offset), uint64(whence), uint64(resultNewoffsetOff))
require.NoError(f.fs.t, err)
require.NotEqual(f.fs.t, uint64(wasi.ErrnoFault), res[0])
require.NotEqual(f.fs.t, uint64(wasi_snapshot_preview1.ErrnoFault), res[0])

newOffset, ok := f.fs.memory.ReadUint32Le(testCtx, resultNewoffsetOff)
require.True(f.fs.t, ok)
Expand All @@ -145,7 +145,7 @@ func TestReader(t *testing.T) {
r := wazero.NewRuntime()
defer r.Close(testCtx)

_, err := wasi.InstantiateSnapshotPreview1(testCtx, r)
_, err := wasi_snapshot_preview1.Instantiate(testCtx, r)
require.NoError(t, err)

realFs := fstest.MapFS{"animals.txt": &fstest.MapFile{Data: animals}}
Expand Down
4 changes: 2 additions & 2 deletions internal/integration_test/vs/codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/tetratelabs/wazero/internal/wasm"
"github.com/tetratelabs/wazero/internal/wasm/binary"
"github.com/tetratelabs/wazero/internal/wasm/text"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
)

func TestExampleUpToDate(t *testing.T) {
Expand All @@ -29,7 +29,7 @@ func TestExampleUpToDate(t *testing.T) {
r := wazero.NewRuntimeWithConfig(wazero.NewRuntimeConfig().WithWasmCore2())

// Add WASI to satisfy import tests
wm, err := wasi.InstantiateSnapshotPreview1(testCtx, r)
wm, err := wasi_snapshot_preview1.Instantiate(testCtx, r)
require.NoError(t, err)
defer wm.Close(testCtx)

Expand Down
4 changes: 2 additions & 2 deletions internal/integration_test/vs/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
"github.com/tetratelabs/wazero/wasi"
"github.com/tetratelabs/wazero/wasi_snapshot_preview1"
)

type RuntimeConfig struct {
Expand Down Expand Up @@ -96,7 +96,7 @@ func (r *wazeroRuntime) Instantiate(ctx context.Context, cfg *RuntimeConfig) (mo

// Instantiate WASI, if configured.
if cfg.NeedsWASI {
if m.wasi, err = wasi.InstantiateSnapshotPreview1(ctx, r.runtime); err != nil {
if m.wasi, err = wasi_snapshot_preview1.Instantiate(ctx, r.runtime); err != nil {
return
}
}
Expand Down
2 changes: 0 additions & 2 deletions internal/sys/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
type FSKey struct{}

// FileEntry maps a path to an open file in a file system.
//
// Note: This does not introduce cycles because the types here are in the package "wasi" not "internalwasi".
type FileEntry struct {
Path string
FS fs.FS
Expand Down
2 changes: 1 addition & 1 deletion namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Namespace interface {
// defer n.CloseWithExitCode(ctx, 2) // This closes all modules in this Namespace.
//
// Everything below here can be closed, but will anyway due to above.
// _, _ = wasi.InstantiateSnapshotPreview1(ctx, n)
// _, _ = wasi_snapshot_preview1.InstantiateSnapshotPreview1(ctx, n)
// mod, _ := n.InstantiateModuleFromCode(ctx, source)
//
// See Closer
Expand Down
2 changes: 1 addition & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
publish = "public"

[build.environment]
HUGO_VERSION = "0.99.0"
HUGO_VERSION = "0.100.0"

[context.production]
command = "git submodule update --init && hugo --gc --minify"
Expand Down
2 changes: 1 addition & 1 deletion runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ type Runtime interface {
// defer r.CloseWithExitCode(ctx, 2) // This closes everything this Runtime created.
//
// // Everything below here can be closed, but will anyway due to above.
// _, _ = wasi.InstantiateSnapshotPreview1(ctx, r)
// _, _ = wasi_snapshot_preview1.InstantiateSnapshotPreview1(ctx, r)
// mod, _ := r.InstantiateModuleFromCode(ctx, source)
CloseWithExitCode(ctx context.Context, exitCode uint32) error

Expand Down
2 changes: 1 addition & 1 deletion wasi/errno.go → wasi_snapshot_preview1/errno.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi
package wasi_snapshot_preview1

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi
package wasi_snapshot_preview1

import (
"context"
Expand All @@ -21,7 +21,7 @@ func Example() {
r := wazero.NewRuntime()

// Instantiate WASI, which implements system I/O such as console output.
wm, err := InstantiateSnapshotPreview1(ctx, r)
wm, err := Instantiate(ctx, r)
if err != nil {
log.Panicln(err)
}
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions wasi/usage_test.go → wasi_snapshot_preview1/usage_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wasi
package wasi_snapshot_preview1

import (
"bytes"
Expand All @@ -20,7 +20,7 @@ func TestInstantiateModule(t *testing.T) {

// Configure WASI to write stdout to a buffer, so that we can verify it later.
sys := wazero.NewModuleConfig().WithStdout(stdout)
wm, err := InstantiateSnapshotPreview1(testCtx, r)
wm, err := Instantiate(testCtx, r)
require.NoError(t, err)
defer wm.Close(testCtx)

Expand Down
Loading

0 comments on commit 7b4d862

Please sign in to comment.