From 641f9bbf7c480ac5498d8a231acccd7cf3a2a754 Mon Sep 17 00:00:00 2001 From: Li Jie Date: Wed, 9 Apr 2025 09:27:49 +0800 Subject: [PATCH] select WASM runtime by LLGO_WASM_RUNTIME --- internal/build/build.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/internal/build/build.go b/internal/build/build.go index d29b130d..c478b691 100644 --- a/internal/build/build.go +++ b/internal/build/build.go @@ -580,9 +580,17 @@ func linkMainPkg(ctx *context, pkg *packages.Package, pkgs []*aPackage, linkArgs args := make([]string, 0, len(conf.RunArgs)+1) copy(args, conf.RunArgs) if isWasmTarget(conf.Goos) { - args = append(args, app, "--wasm", "multi-memory=true") - args = append(args, conf.RunArgs...) - app = "wasmtime" + wasmer := WasmRuntime() + switch wasmer { + case "wasmtime": + args = append(args, app, "--wasm", "multi-memory=true") + args = append(args, conf.RunArgs...) + app = "wasmtime" + default: + args = append(args, app) + args = append(args, conf.RunArgs...) + app = wasmer + } } else { args = conf.RunArgs } @@ -910,6 +918,17 @@ const llgoTrace = "LLGO_TRACE" const llgoOptimize = "LLGO_OPTIMIZE" const llgoCheck = "LLGO_CHECK" const llgoRpathChange = "LLGO_RPATH_CHANGE" +const llgoWasmRuntime = "LLGO_WASM_RUNTIME" + +const defaultWasmRuntime = "wasmtime" + +func defaultEnv(env string, defVal string) string { + envVal := strings.ToLower(os.Getenv(env)) + if envVal == "" { + return defVal + } + return envVal +} func isEnvOn(env string, defVal bool) bool { envVal := strings.ToLower(os.Getenv(env)) @@ -943,6 +962,10 @@ func IsRpathChangeEnabled() bool { return isEnvOn(llgoRpathChange, false) } +func WasmRuntime() string { + return defaultEnv(llgoWasmRuntime, defaultWasmRuntime) +} + func ParseArgs(args []string, swflags map[string]bool) (flags, patterns []string, verbose bool) { n := len(args) for i := 0; i < n; i++ {