Skip to content

Commit

Permalink
Add some missing configuration flags (bytecodealliance#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobappleyard committed Dec 3, 2024
1 parent b1b478c commit db3d601
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
67 changes: 67 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,73 @@ 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)
}

// 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))
Expand Down
9 changes: 9 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ 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)
if runtime.GOARCH == "amd64" && runtime.GOOS == "linux" {
NewConfig().SetTarget("x86_64-unknown-linux-gnu")
}
Expand Down

0 comments on commit db3d601

Please sign in to comment.