Skip to content
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ jobs:
shell: bash
run: ./ci/test-vendoring.sh
if: runner.os != 'Windows'
- name: Test the minimal runtime
shell: bash
run: ./ci/test-minimal-runtime/test.sh
if: runner.os != 'Windows'

coverage:
runs-on: ubuntu-latest
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
/bazel-*
test-vendoring-project
test-vendoring-project
ci/test-minimal-runtime/module.cwasm
3 changes: 2 additions & 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 = 'v42.0.0'
version = 'v43.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 Expand Up @@ -51,6 +51,7 @@
shutil.copytree(src + '/include', 'build/include', dirs_exist_ok=True)

shutil.copytree(src + '/lib', 'build/' + dirname, dirs_exist_ok=True)
shutil.copytree(src + '/min/lib', 'build/' + dirname + '-min', dirs_exist_ok=True)
shutil.rmtree(src)

for dylib in glob.glob("build/**/*.dll"):
Expand Down
35 changes: 35 additions & 0 deletions ci/test-minimal-runtime/create_cwasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//go:build ignore

package main

import (
"log"
"os"

"github.com/bytecodealliance/wasmtime-go/v42"
)

func main() {
wasm, err := wasmtime.Wat2Wasm(`(module (func (export "test") (result i32) (i32.const 1)))`)
check(err)

cfg := wasmtime.NewConfig()
cfg.SetGCSupport(false)
cfg.SetWasmThreads(false)
cfg.SetWasmComponentModel(false)
engine := wasmtime.NewEngineWithConfig(cfg)
module, err := wasmtime.NewModule(engine, wasm)
check(err)
defer module.Close()

artifact, err := module.Serialize()
check(err)

check(os.WriteFile("module.cwasm", artifact, 0o644))
}

func check(err error) {
if err != nil {
log.Fatal(err)
}
}
31 changes: 31 additions & 0 deletions ci/test-minimal-runtime/min_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//go:build min

package testminimalruntime_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/bytecodealliance/wasmtime-go/v42"
)

func TestMinimalRuntime(t *testing.T) {
cfg := wasmtime.NewConfig()
cfg.SetGCSupport(false)
engine := wasmtime.NewEngineWithConfig(cfg)
module, err := wasmtime.NewModuleDeserializeFile(engine, "module.cwasm")
require.NoError(t, err)
defer module.Close()

store := wasmtime.NewStore(engine)
instance, err := wasmtime.NewInstance(store, module, []wasmtime.AsExtern{})
require.NoError(t, err)

fn := instance.GetFunc(store, "test")
require.NotNil(t, fn)

result, err := fn.Call(store)
require.NoError(t, err)
require.Equal(t, int32(1), result)
}
7 changes: 7 additions & 0 deletions ci/test-minimal-runtime/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")"

rm -f module.cwasm
go run create_cwasm.go
go test -count=1 -tags min .
111 changes: 4 additions & 107 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ func (cfg *Config) SetMaxWasmStack(size int) {
runtime.KeepAlive(cfg)
}

// SetWasmThreads configures whether the wasm threads proposal is enabled
func (cfg *Config) SetWasmThreads(enabled bool) {
C.wasmtime_config_wasm_threads_set(cfg.ptr(), C.bool(enabled))
runtime.KeepAlive(cfg)
}

// SetWasmReferenceTypes configures whether the wasm reference types proposal is enabled
func (cfg *Config) SetWasmReferenceTypes(enabled bool) {
C.wasmtime_config_wasm_reference_types_set(cfg.ptr(), C.bool(enabled))
Expand Down Expand Up @@ -143,10 +137,10 @@ func (cfg *Config) SetWasmGC(enabled bool) {
runtime.KeepAlive(cfg)
}

// SetWasmComponentModel configures whether the wasm component model proposal is
// enabled.
func (cfg *Config) SetWasmComponentModel(enabled bool) {
C.wasmtime_config_wasm_component_model_set(cfg.ptr(), C.bool(enabled))
// SetGCSupport configures whether GC support is enabled in Wasmtime at all.
// When false, engines can be used without a GC collector (e.g. minimal Wasmtime builds).
func (cfg *Config) SetGCSupport(enabled bool) {
C.wasmtime_config_gc_support_set(cfg.ptr(), C.bool(enabled))
runtime.KeepAlive(cfg)
}

Expand All @@ -162,24 +156,6 @@ func (cfg *Config) SetConsumeFuel(enabled bool) {
runtime.KeepAlive(cfg)
}

// SetParallelCompilation configures whether compilation should use multiple threads
func (cfg *Config) SetParallelCompilation(enabled bool) {
C.wasmtime_config_parallel_compilation_set(cfg.ptr(), C.bool(enabled))
runtime.KeepAlive(cfg)
}

// SetCraneliftNanCanonicalization configures whether whether Cranelift should perform a
// NaN-canonicalization pass.
//
// When Cranelift is used as a code generation backend this will configure it to replace NaNs with a single
// canonical value. This is useful for users requiring entirely deterministic WebAssembly computation.
//
// This is not required by the WebAssembly spec, so it is not enabled by default.
func (cfg *Config) SetCraneliftNanCanonicalization(enabled bool) {
C.wasmtime_config_cranelift_nan_canonicalization_set(cfg.ptr(), C.bool(enabled))
runtime.KeepAlive(cfg)
}

// SetNativeUnwindInfo whether to generate native unwind information (e.g. .eh_frame on Linux).
func (cfg *Config) SetNativeUnwindInfo(enabled bool) {
C.wasmtime_config_native_unwind_info_set(cfg.ptr(), C.bool(enabled))
Expand All @@ -205,61 +181,12 @@ func (cfg *Config) SetMemoryInitCOWSet(enabled bool) {
runtime.KeepAlive(cfg)
}

// SetStrategy configures what compilation strategy is used to compile wasm code
func (cfg *Config) SetStrategy(strat Strategy) {
C.wasmtime_config_strategy_set(cfg.ptr(), C.wasmtime_strategy_t(strat))
runtime.KeepAlive(cfg)
}

// SetCraneliftDebugVerifier configures whether the cranelift debug verifier will be active when
// cranelift is used to compile wasm code.
func (cfg *Config) SetCraneliftDebugVerifier(enabled bool) {
C.wasmtime_config_cranelift_debug_verifier_set(cfg.ptr(), C.bool(enabled))
runtime.KeepAlive(cfg)
}

// SetCraneliftOptLevel configures the cranelift optimization level for generated code
func (cfg *Config) SetCraneliftOptLevel(level OptLevel) {
C.wasmtime_config_cranelift_opt_level_set(cfg.ptr(), C.wasmtime_opt_level_t(level))
runtime.KeepAlive(cfg)
}

// SetProfiler configures what profiler strategy to use for generated code
func (cfg *Config) SetProfiler(profiler ProfilingStrategy) {
C.wasmtime_config_profiler_set(cfg.ptr(), C.wasmtime_profiling_strategy_t(profiler))
runtime.KeepAlive(cfg)
}

// CacheConfigLoadDefault enables compiled code caching for this `Config` using the default settings
// configuration can be found.
//
// For more information about caching see
// https://bytecodealliance.github.io/wasmtime/cli-cache.html
func (cfg *Config) CacheConfigLoadDefault() error {
err := C.wasmtime_config_cache_config_load(cfg.ptr(), nil)
runtime.KeepAlive(cfg)
if err != nil {
return mkError(err)
}
return nil
}

// CacheConfigLoad enables compiled code caching for this `Config` using the settings specified
// in the configuration file `path`.
//
// For more information about caching and configuration options see
// https://bytecodealliance.github.io/wasmtime/cli-cache.html
func (cfg *Config) CacheConfigLoad(path string) error {
cstr := C.CString(path)
err := C.wasmtime_config_cache_config_load(cfg.ptr(), cstr)
C.free(unsafe.Pointer(cstr))
runtime.KeepAlive(cfg)
if err != nil {
return mkError(err)
}
return nil
}

// SetEpochInterruption enables epoch-based instrumentation of generated code to
// interrupt WebAssembly execution when the current engine epoch exceeds a
// defined threshold.
Expand Down Expand Up @@ -289,36 +216,6 @@ func (cfg *Config) SetTarget(target string) error {
return nil
}

// EnableCraneliftFlag enables a target-specific flag in Cranelift.
//
// This can be used, for example, to enable SSE4.2 on x86_64 hosts. Settings can
// be explored with `wasmtime settings` on the CLI.
//
// For more information see the Rust documentation at
// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.cranelift_flag_enable
func (cfg *Config) EnableCraneliftFlag(flag string) {
cstr := C.CString(flag)
C.wasmtime_config_cranelift_flag_enable(cfg.ptr(), cstr)
C.free(unsafe.Pointer(cstr))
runtime.KeepAlive(cfg)
}

// SetCraneliftFlag sets a target-specific flag in Cranelift to the specified value.
//
// This can be used, for example, to enable SSE4.2 on x86_64 hosts. Settings can
// be explored with `wasmtime settings` on the CLI.
//
// For more information see the Rust documentation at
// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.cranelift_flag_set
func (cfg *Config) SetCraneliftFlag(name string, value string) {
cstrName := C.CString(name)
cstrValue := C.CString(value)
C.wasmtime_config_cranelift_flag_set(cfg.ptr(), cstrName, cstrValue)
C.free(unsafe.Pointer(cstrName))
C.free(unsafe.Pointer(cstrValue))
runtime.KeepAlive(cfg)
}

// See comments in `ffi.go` for what's going on here
func (cfg *Config) ptr() *C.wasm_config_t {
ret := cfg._ptr
Expand Down
41 changes: 41 additions & 0 deletions config_feat_cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//go:build !min

package wasmtime

// #include <wasmtime.h>
// #include <stdlib.h>
import "C"
import (
"runtime"
"unsafe"
)

// CacheConfigLoadDefault enables compiled code caching for this `Config` using the default settings
// configuration can be found.
//
// For more information about caching see
// https://bytecodealliance.github.io/wasmtime/cli-cache.html
func (cfg *Config) CacheConfigLoadDefault() error {
err := C.wasmtime_config_cache_config_load(cfg.ptr(), nil)
runtime.KeepAlive(cfg)
if err != nil {
return mkError(err)
}
return nil
}

// CacheConfigLoad enables compiled code caching for this `Config` using the settings specified
// in the configuration file `path`.
//
// For more information about caching and configuration options see
// https://bytecodealliance.github.io/wasmtime/cli-cache.html
func (cfg *Config) CacheConfigLoad(path string) error {
cstr := C.CString(path)
err := C.wasmtime_config_cache_config_load(cfg.ptr(), cstr)
C.free(unsafe.Pointer(cstr))
runtime.KeepAlive(cfg)
if err != nil {
return mkError(err)
}
return nil
}
14 changes: 14 additions & 0 deletions config_feat_component_model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//go:build !min

package wasmtime

// #include <wasmtime.h>
import "C"
import "runtime"

// SetWasmComponentModel configures whether the wasm component model proposal is
// enabled.
func (cfg *Config) SetWasmComponentModel(enabled bool) {
C.wasmtime_config_wasm_component_model_set(cfg.ptr(), C.bool(enabled))
runtime.KeepAlive(cfg)
}
72 changes: 72 additions & 0 deletions config_feat_cranelift.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//go:build !min

package wasmtime

// #include <wasmtime.h>
// #include <stdlib.h>
import "C"
import (
"runtime"
"unsafe"
)

// SetStrategy configures what compilation strategy is used to compile wasm code
func (cfg *Config) SetStrategy(strat Strategy) {
C.wasmtime_config_strategy_set(cfg.ptr(), C.wasmtime_strategy_t(strat))
runtime.KeepAlive(cfg)
}

// SetCraneliftDebugVerifier configures whether the cranelift debug verifier will be active when
// cranelift is used to compile wasm code.
func (cfg *Config) SetCraneliftDebugVerifier(enabled bool) {
C.wasmtime_config_cranelift_debug_verifier_set(cfg.ptr(), C.bool(enabled))
runtime.KeepAlive(cfg)
}

// SetCraneliftOptLevel configures the cranelift optimization level for generated code
func (cfg *Config) SetCraneliftOptLevel(level OptLevel) {
C.wasmtime_config_cranelift_opt_level_set(cfg.ptr(), C.wasmtime_opt_level_t(level))
runtime.KeepAlive(cfg)
}

// SetCraneliftNanCanonicalization configures whether whether Cranelift should perform a
// NaN-canonicalization pass.
//
// When Cranelift is used as a code generation backend this will configure it to replace NaNs with a single
// canonical value. This is useful for users requiring entirely deterministic WebAssembly computation.
//
// This is not required by the WebAssembly spec, so it is not enabled by default.
func (cfg *Config) SetCraneliftNanCanonicalization(enabled bool) {
C.wasmtime_config_cranelift_nan_canonicalization_set(cfg.ptr(), C.bool(enabled))
runtime.KeepAlive(cfg)
}

// EnableCraneliftFlag enables a target-specific flag in Cranelift.
//
// This can be used, for example, to enable SSE4.2 on x86_64 hosts. Settings can
// be explored with `wasmtime settings` on the CLI.
//
// For more information see the Rust documentation at
// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.cranelift_flag_enable
func (cfg *Config) EnableCraneliftFlag(flag string) {
cstr := C.CString(flag)
C.wasmtime_config_cranelift_flag_enable(cfg.ptr(), cstr)
C.free(unsafe.Pointer(cstr))
runtime.KeepAlive(cfg)
}

// SetCraneliftFlag sets a target-specific flag in Cranelift to the specified value.
//
// This can be used, for example, to enable SSE4.2 on x86_64 hosts. Settings can
// be explored with `wasmtime settings` on the CLI.
//
// For more information see the Rust documentation at
// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.cranelift_flag_set
func (cfg *Config) SetCraneliftFlag(name string, value string) {
cstrName := C.CString(name)
cstrValue := C.CString(value)
C.wasmtime_config_cranelift_flag_set(cfg.ptr(), cstrName, cstrValue)
C.free(unsafe.Pointer(cstrName))
C.free(unsafe.Pointer(cstrValue))
runtime.KeepAlive(cfg)
}
Loading
Loading