From 04003d99c30fd62243eba29763eb4e009ee8cc47 Mon Sep 17 00:00:00 2001 From: Bob Appleyard Date: Tue, 3 Dec 2024 20:52:57 +0000 Subject: [PATCH] Add some missing configuration flags (#227) --- config.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ config_test.go | 10 +++++++ 2 files changed, 85 insertions(+) diff --git a/config.go b/config.go index 15c9801..bcf89da 100644 --- a/config.go +++ b/config.go @@ -131,6 +131,81 @@ func (cfg *Config) SetConsumeFuel(enabled bool) { runtime.KeepAlive(cfg) } +// SetTailCall configures whether tail calls are enabled +func (cfg *Config) SetTailCall(enabled bool) { + C.wasmtime_config_wasm_tail_call_set(cfg.ptr(), C.bool(enabled)) + runtime.KeepAlive(cfg) +} + +// SetFunctionReferences configures whether function references are enabled +func (cfg *Config) SetFunctionReferences(enabled bool) { + C.wasmtime_config_wasm_function_references_set(cfg.ptr(), C.bool(enabled)) + runtime.KeepAlive(cfg) +} + +// SetGC configures whether GC is enabled +func (cfg *Config) SetGC(enabled bool) { + C.wasmtime_config_wasm_gc_set(cfg.ptr(), C.bool(enabled)) + runtime.KeepAlive(cfg) +} + +// SetWideArithmetic configures whether wide arithmetic is enabled +func (cfg *Config) SetWideArithmetic(enabled bool) { + C.wasmtime_config_wasm_wide_arithmetic_set(cfg.ptr(), C.bool(enabled)) + 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)) + runtime.KeepAlive(cfg) +} + +// SetMacOSUseMachPorts configures whether, when on macOS, Mach ports are used for exception handling instead +// of traditional Unix-based signal handling. +func (cfg *Config) SetMacOSUseMachPorts(enabled bool) { + C.wasmtime_config_macos_use_mach_ports_set(cfg.ptr(), C.bool(enabled)) + runtime.KeepAlive(cfg) +} + +// Configures the “static” style of memory to always be used. +// For more information see the Rust documentation at +// https://bytecodealliance.github.io/wasmtime/api/wasmtime/struct.Config.html#method.static_memory_forced. +func (cfg *Config) SetStaticMemoryForced(enabled bool) { + C.wasmtime_config_static_memory_forced_set(cfg.ptr(), C.bool(enabled)) + runtime.KeepAlive(cfg) +} + +// SetMemoryInitCOWSet Configures whether copy-on-write memory-mapped data is used to initialize a linear memory. +// +// Initializing linear memory via a copy-on-write mapping can drastically improve instantiation costs of a +// WebAssembly module because copying memory is deferred. Additionally if a page of memory is only ever read from +// WebAssembly and never written too then the same underlying page of data will be reused between all +// instantiations of a module meaning that if a module is instantiated many times this can lower the overall +// memory required needed to run that module. +func (cfg *Config) SetMemoryInitCOWSet(enabled bool) { + C.wasmtime_config_memory_init_cow_set(cfg.ptr(), C.bool(enabled)) + 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)) diff --git a/config_test.go b/config_test.go index 2580e70..d6325b2 100644 --- a/config_test.go +++ b/config_test.go @@ -26,6 +26,16 @@ func TestConfig(t *testing.T) { NewConfig().SetCraneliftOptLevel(OptLevelSpeed) NewConfig().SetCraneliftOptLevel(OptLevelSpeedAndSize) NewConfig().SetProfiler(ProfilingStrategyNone) + NewConfig().SetTailCall(true) + NewConfig().SetFunctionReferences(true) + NewConfig().SetGC(true) + NewConfig().SetWideArithmetic(true) + NewConfig().SetParallelCompilation(true) + NewConfig().SetCraneliftNanCanonicalization(true) + NewConfig().SetNativeUnwindInfo(true) + NewConfig().SetMacOSUseMachPorts(false) + NewConfig().SetMemoryInitCOWSet(true) + NewConfig().SetStaticMemoryForced(true) if runtime.GOARCH == "amd64" && runtime.GOOS == "linux" { NewConfig().SetTarget("x86_64-unknown-linux-gnu") }