Skip to content

Commit

Permalink
Update to 27.0.0 (#235)
Browse files Browse the repository at this point in the history
Also update various C APIs that changed in the last release.
  • Loading branch information
alexcrichton authored Nov 20, 2024
1 parent a1a8116 commit b1b478c
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 51 deletions.
2 changes: 1 addition & 1 deletion BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ go_library(
],
"//conditions:default": [],
}),
importpath = "github.com/bytecodealliance/wasmtime-go/v25",
importpath = "github.com/bytecodealliance/wasmtime-go/v27",
visibility = ["//visibility:public"],
)

Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<a href="https://github.com/bytecodealliance/wasmtime-go/actions?query=workflow%3ACI">
<img src="https://github.com/bytecodealliance/wasmtime-go/workflows/CI/badge.svg" alt="CI status"/>
</a>
<a href="https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go/v25">
<img src="https://godoc.org/github.com/bytecodealliance/wasmtime-go/v25?status.svg" alt="Documentation"/>
<a href="https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go/v27">
<img src="https://godoc.org/github.com/bytecodealliance/wasmtime-go/v27?status.svg" alt="Documentation"/>
</a>
<a href="https://bytecodealliance.github.io/wasmtime-go/coverage.html">
<img src="https://img.shields.io/badge/coverage-main-green" alt="Code Coverage"/>
Expand All @@ -25,7 +25,7 @@
## Installation

```sh
go get -u github.com/bytecodealliance/wasmtime-go/v25@v25.0.0
go get -u github.com/bytecodealliance/wasmtime-go/v27@v27.0.0
```

Be sure to check out the [API documentation][api]!
Expand All @@ -39,16 +39,16 @@ need to arrange to build Wasmtime and use `CGO_*` env vars to compile correctly.

This project has been tested with Go 1.13 or later.

[api]: https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go/v25
[api]: https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go/v27
[wasmtime]: https://github.com/bytecodealliance/wasmtime

If you are a bazel user, add following to your WORKSPACE file:

```
go_repository(
name = "com_github_bytecodealliance_wasmtime_go",
importpath = "github.com/bytecodealliance/wasmtime-go/v25",
version = "v25.0.0",
importpath = "github.com/bytecodealliance/wasmtime-go/v27",
version = "v27.0.0",
)
```

Expand All @@ -61,7 +61,7 @@ package main

import (
"fmt"
"github.com/bytecodealliance/wasmtime-go/v25"
"github.com/bytecodealliance/wasmtime-go/v27"
)

func main() {
Expand Down Expand Up @@ -179,8 +179,8 @@ Once merged checkout `main` and do:
$ rm .gitignore
$ python3 ci/download-wasmtime.py
$ git add .
$ git commit -m 'v25.0.0 release artifacts'
$ git tag v25.0.0
$ git commit -m 'v27.0.0 release artifacts'
$ git tag v27.0.0
```

and push up the tag
2 changes: 1 addition & 1 deletion ci/download-wasmtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import glob


version = 'v25.0.0'
version = 'v27.0.0'
urls = [
['wasmtime-{}-x86_64-mingw-c-api.zip', 'windows-x86_64'],
['wasmtime-{}-x86_64-linux-c-api.tar.xz', 'linux-x86_64'],
Expand Down
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"
"time"

"github.com/bytecodealliance/wasmtime-go/v25"
"github.com/bytecodealliance/wasmtime-go/v27"
)

// Example of limiting a WebAssembly function's runtime using "fuel consumption".
Expand Down Expand Up @@ -422,7 +422,7 @@ func ExampleMemory() {

// Finally we can also create standalone memories to get imported by
// wasm modules too.
memorytype := wasmtime.NewMemoryType(5, true, 5)
memorytype := wasmtime.NewMemoryType(5, true, 5, false)
memory2, err := wasmtime.NewMemory(store, memorytype)
assert(err == nil)
assert(memory2.Size(store) == 5)
Expand Down
2 changes: 1 addition & 1 deletion exporttype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestExportType(t *testing.T) {
et := NewExportType("x", NewMemoryType(0, false, 0))
et := NewExportType("x", NewMemoryType(0, false, 0, false))
require.Equal(t, et.Name(), "x", "bad name")
require.NotNil(t, et.Type().MemoryType(), "bad type")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/bytecodealliance/wasmtime-go/v25
module github.com/bytecodealliance/wasmtime-go/v27

go 1.18

Expand Down
14 changes: 7 additions & 7 deletions includebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
// included in vendored dependencies.
// Cf. https://github.com/golang/go/issues/26366

_ "github.com/bytecodealliance/wasmtime-go/v25/build/include"
_ "github.com/bytecodealliance/wasmtime-go/v25/build/include/wasmtime"
_ "github.com/bytecodealliance/wasmtime-go/v25/build/linux-aarch64"
_ "github.com/bytecodealliance/wasmtime-go/v25/build/linux-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/v25/build/macos-aarch64"
_ "github.com/bytecodealliance/wasmtime-go/v25/build/macos-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/v25/build/windows-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/v27/build/include"
_ "github.com/bytecodealliance/wasmtime-go/v27/build/include/wasmtime"
_ "github.com/bytecodealliance/wasmtime-go/v27/build/linux-aarch64"
_ "github.com/bytecodealliance/wasmtime-go/v27/build/linux-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/v27/build/macos-aarch64"
_ "github.com/bytecodealliance/wasmtime-go/v27/build/macos-x86_64"
_ "github.com/bytecodealliance/wasmtime-go/v27/build/windows-x86_64"
)
2 changes: 1 addition & 1 deletion linker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestLinker(t *testing.T) {
g, err := NewGlobal(store, NewGlobalType(NewValType(KindI32), false), ValI32(0))
require.NoError(t, err)
require.NoError(t, linker.Define(store, "", "g", g))
m, err := NewMemory(store, NewMemoryType(1, true, 300))
m, err := NewMemory(store, NewMemoryType(1, true, 300, false))
require.NoError(t, err)
require.NoError(t, linker.Define(store, "", "m", m))
require.NoError(t, linker.Define(store, "other", "m", m))
Expand Down
15 changes: 11 additions & 4 deletions memorytype.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ type MemoryType struct {
//
// Note that this will create a 32-bit memory type, the default outside of the
// memory64 proposal.
func NewMemoryType(min uint32, has_max bool, max uint32) *MemoryType {
func NewMemoryType(min uint32, has_max bool, max uint32, shared bool) *MemoryType {
if min > (1<<16) || max > (1<<16) {
panic("provided sizes are too large")
}
ptr := C.wasmtime_memorytype_new(C.uint64_t(min), C._Bool(has_max), C.uint64_t(max), false)
ptr := C.wasmtime_memorytype_new(C.uint64_t(min), C._Bool(has_max), C.uint64_t(max), false, C._Bool(shared))
return mkMemoryType(ptr, nil)
}

Expand All @@ -34,11 +34,11 @@ func NewMemoryType(min uint32, has_max bool, max uint32) *MemoryType {
// `max` is used as the maximum size of memory, in wasm pages.
//
// Note that 64-bit memories are part of the memory64 WebAssembly proposal.
func NewMemoryType64(min uint64, has_max bool, max uint64) *MemoryType {
func NewMemoryType64(min uint64, has_max bool, max uint64, shared bool) *MemoryType {
if min > (1<<48) || max > (1<<48) {
panic("provided sizes are too large")
}
ptr := C.wasmtime_memorytype_new(C.uint64_t(min), C._Bool(has_max), C.uint64_t(max), true)
ptr := C.wasmtime_memorytype_new(C.uint64_t(min), C._Bool(has_max), C.uint64_t(max), true, C._Bool(shared))
return mkMemoryType(ptr, nil)
}

Expand Down Expand Up @@ -106,6 +106,13 @@ func (ty *MemoryType) Is64() bool {
return bool(ok)
}

// IsShared returns whether this is a shared memory or not.
func (ty *MemoryType) IsShared() bool {
ok := C.wasmtime_memorytype_isshared(ty.ptr())
runtime.KeepAlive(ty)
return bool(ok)
}

// AsExternType converts this type to an instance of `ExternType`
func (ty *MemoryType) AsExternType() *ExternType {
ptr := C.wasm_memorytype_as_externtype_const(ty.ptr())
Expand Down
6 changes: 4 additions & 2 deletions memorytype_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func TestMemoryType(t *testing.T) {
ty := NewMemoryType(0, true, 100)
ty := NewMemoryType(0, true, 100, false)
ty.Minimum()
ty.Maximum()

Expand All @@ -19,8 +19,10 @@ func TestMemoryType(t *testing.T) {
}

func TestMemoryType64(t *testing.T) {
ty := NewMemoryType64(0x100000000, true, 0x100000001)
ty := NewMemoryType64(0x100000000, true, 0x100000001, false)
require.Equal(t, uint64(0x100000000), ty.Minimum())
require.True(t, ty.Is64())
require.False(t, ty.IsShared())

present, max := ty.Maximum()
require.Equal(t, uint64(0x100000001), max)
Expand Down
4 changes: 2 additions & 2 deletions multi_memory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func TestMultiMemoryImported(t *testing.T) {
require.NoError(t, err)
store := multiMemoryStore()

mem0, err := NewMemory(store, NewMemoryType(1, true, 3))
mem0, err := NewMemory(store, NewMemoryType(1, true, 3, false))
require.NoError(t, err)
mem1, err := NewMemory(store, NewMemoryType(2, true, 4))
mem1, err := NewMemory(store, NewMemoryType(2, true, 4, false))
require.NoError(t, err)

module, err := NewModule(store.Engine, wasm)
Expand Down
12 changes: 6 additions & 6 deletions reftypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,20 @@ func TestRefTypesTable(t *testing.T) {
require.NoError(t, err)

for i := 0; i < 10; i++ {
val, err := table.Get(store, uint32(i))
val, err := table.Get(store, uint64(i))
require.NoError(t, err)
require.Equal(t, "init", val.Get().(string))
}

_, err = table.Grow(store, 2, ValExternref("grown"))
require.NoError(t, err)
for i := 0; i < 10; i++ {
val, err := table.Get(store, uint32(i))
val, err := table.Get(store, uint64(i))
require.NoError(t, err)
require.Equal(t, "init", val.Get().(string))
}
for i := 10; i < 12; i++ {
val, err := table.Get(store, uint32(i))
val, err := table.Get(store, uint64(i))
require.NoError(t, err)
require.Equal(t, "grown", val.Get().(string))
}
Expand All @@ -95,7 +95,7 @@ func TestRefTypesTable(t *testing.T) {
require.NoError(t, err)

for i := 0; i < 7; i++ {
val, err := table.Get(store, uint32(i))
val, err := table.Get(store, uint64(i))
require.NoError(t, err)
require.Equal(t, "init", val.Get().(string))
}
Expand All @@ -104,12 +104,12 @@ func TestRefTypesTable(t *testing.T) {
require.Equal(t, "lucky", val.Get().(string))

for i := 8; i < 10; i++ {
val, err := table.Get(store, uint32(i))
val, err := table.Get(store, uint64(i))
require.NoError(t, err)
require.Equal(t, "init", val.Get().(string))
}
for i := 10; i < 12; i++ {
val, err := table.Get(store, uint32(i))
val, err := table.Get(store, uint64(i))
require.NoError(t, err)
require.Equal(t, "grown", val.Get().(string))
}
Expand Down
20 changes: 10 additions & 10 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,39 @@ func mkTable(val C.wasmtime_table_t) *Table {
}

// Size returns the size of this table in units of elements.
func (t *Table) Size(store Storelike) uint32 {
func (t *Table) Size(store Storelike) uint64 {
ret := C.wasmtime_table_size(store.Context(), &t.val)
runtime.KeepAlive(store)
return uint32(ret)
return uint64(ret)
}

// Grow grows this table by the number of units specified, using the
// specified initializer value for new slots.
//
// Returns an error if the table failed to grow, or the previous size of the
// table if growth was successful.
func (t *Table) Grow(store Storelike, delta uint32, init Val) (uint32, error) {
var prev C.uint32_t
func (t *Table) Grow(store Storelike, delta uint64, init Val) (uint64, error) {
var prev C.uint64_t
var raw_val C.wasmtime_val_t
init.initialize(store, &raw_val)
err := C.wasmtime_table_grow(store.Context(), &t.val, C.uint32_t(delta), &raw_val, &prev)
err := C.wasmtime_table_grow(store.Context(), &t.val, C.uint64_t(delta), &raw_val, &prev)
C.wasmtime_val_unroot(store.Context(), &raw_val)
runtime.KeepAlive(store)
if err != nil {
return 0, mkError(err)
}

return uint32(prev), nil
return uint64(prev), nil
}

// Get gets an item from this table from the specified index.
//
// Returns an error if the index is out of bounds, or returns a value (which
// may be internally null) if the index is in bounds corresponding to the entry
// at the specified index.
func (t *Table) Get(store Storelike, idx uint32) (Val, error) {
func (t *Table) Get(store Storelike, idx uint64) (Val, error) {
var val C.wasmtime_val_t
ok := C.wasmtime_table_get(store.Context(), &t.val, C.uint32_t(idx), &val)
ok := C.wasmtime_table_get(store.Context(), &t.val, C.uint64_t(idx), &val)
runtime.KeepAlive(store)
if !ok {
return Val{}, errors.New("index out of bounds")
Expand All @@ -83,10 +83,10 @@ func (t *Table) Get(store Storelike, idx uint32) (Val, error) {
// Set sets an item in this table at the specified index.
//
// Returns an error if the index is out of bounds.
func (t *Table) Set(store Storelike, idx uint32, val Val) error {
func (t *Table) Set(store Storelike, idx uint64, val Val) error {
var raw_val C.wasmtime_val_t
val.initialize(store, &raw_val)
err := C.wasmtime_table_set(store.Context(), &t.val, C.uint32_t(idx), &raw_val)
err := C.wasmtime_table_set(store.Context(), &t.val, C.uint64_t(idx), &raw_val)
C.wasmtime_val_unroot(store.Context(), &raw_val)
runtime.KeepAlive(store)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func TestTable(t *testing.T) {
ty := NewTableType(NewValType(KindFuncref), 1, true, 3)
table, err := NewTable(store, ty, ValFuncref(nil))
require.NoError(t, err)
require.Equal(t, uint32(1), table.Size(store))
require.Equal(t, uint64(1), table.Size(store))

f, err := table.Get(store, 0)
require.NoError(t, err)
Expand All @@ -32,7 +32,7 @@ func TestTable(t *testing.T) {

prevSize, err := table.Grow(store, 1, ValFuncref(nil))
require.NoError(t, err)
require.Equal(t, uint32(1), prevSize)
require.Equal(t, uint64(1), prevSize)

f, err = table.Get(store, 1)
require.NoError(t, err)
Expand Down
15 changes: 13 additions & 2 deletions wasi.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,21 @@ func (c *WasiConfig) InheritStderr() {
runtime.KeepAlive(c)
}

func (c *WasiConfig) PreopenDir(path, guestPath string) error {
type WasiDirPerms uint8
type WasiFilePerms uint8

const (
DIR_READ WasiDirPerms = C.WASMTIME_WASI_DIR_PERMS_READ
DIR_WRITE WasiDirPerms = C.WASMTIME_WASI_DIR_PERMS_WRITE
FILE_READ WasiFilePerms = C.WASMTIME_WASI_FILE_PERMS_READ
FILE_WRITE WasiFilePerms = C.WASMTIME_WASI_FILE_PERMS_WRITE
)

func (c *WasiConfig) PreopenDir(path, guestPath string, dirPerms WasiDirPerms, filePerms WasiFilePerms) error {
pathC := C.CString(path)
guestPathC := C.CString(guestPath)
ok := C.wasi_config_preopen_dir(c.ptr(), pathC, guestPathC)
ok := C.wasi_config_preopen_dir(c.ptr(), pathC, guestPathC,
C.wasi_dir_perms(dirPerms), C.wasi_file_perms(filePerms))
runtime.KeepAlive(c)
C.free(unsafe.Pointer(pathC))
C.free(unsafe.Pointer(guestPathC))
Expand Down
6 changes: 6 additions & 0 deletions wasi_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package wasmtime

import "testing"
import "github.com/stretchr/testify/require"

func TestWasiConfig(t *testing.T) {
config := NewWasiConfig()
defer config.Close()
config.SetEnv([]string{"WASMTIME"}, []string{"GO"})
err := config.PreopenDir(".", ".", DIR_READ, FILE_READ)
require.Nil(t, err)
err = config.PreopenDir(".", ".", DIR_READ|DIR_WRITE, FILE_READ|FILE_WRITE)
require.Nil(t, err)

}

0 comments on commit b1b478c

Please sign in to comment.