temporary fix for tetratelabs/wazero#2365 armv8 compiler support bug (#3741)

This commit is contained in:
kim 2025-02-06 12:44:40 +00:00 committed by GitHub
parent 1a8e42eeb3
commit 1276cde4b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -22,12 +22,14 @@
import ( import (
"context" "context"
"os" "os"
"runtime"
"sync/atomic" "sync/atomic"
"unsafe" "unsafe"
"codeberg.org/gruf/go-ffmpreg/embed" "codeberg.org/gruf/go-ffmpreg/embed"
"codeberg.org/gruf/go-ffmpreg/wasm" "codeberg.org/gruf/go-ffmpreg/wasm"
"github.com/tetratelabs/wazero" "github.com/tetratelabs/wazero"
"golang.org/x/sys/cpu"
) )
// ffmpreg is a concurrency-safe pointer // ffmpreg is a concurrency-safe pointer
@ -46,8 +48,17 @@ func initWASM(ctx context.Context) error {
return nil return nil
} }
// Create new runtime config. var cfg wazero.RuntimeConfig
cfg := wazero.NewRuntimeConfig()
// Create new runtime config, taking bug into account:
// taking https://github.com/tetratelabs/wazero/pull/2365
//
// Thanks @ncruces (of go-sqlite3) for the fix!
if compilerSupported() {
cfg = wazero.NewRuntimeConfigCompiler()
} else {
cfg = wazero.NewRuntimeConfigInterpreter()
}
if dir := os.Getenv("GTS_WAZERO_COMPILATION_CACHE"); dir != "" { if dir := os.Getenv("GTS_WAZERO_COMPILATION_CACHE"); dir != "" {
// Use on-filesystem compilation cache given by env. // Use on-filesystem compilation cache given by env.
@ -110,6 +121,26 @@ func initWASM(ctx context.Context) error {
return nil return nil
} }
func compilerSupported() bool {
switch runtime.GOOS {
case "linux", "android",
"windows", "darwin",
"freebsd", "netbsd", "dragonfly",
"solaris", "illumos":
break
default:
return false
}
switch runtime.GOARCH {
case "amd64":
return cpu.X86.HasSSE41
case "arm64":
return true
default:
return false
}
}
// isNil will safely check if 'v' is nil without // isNil will safely check if 'v' is nil without
// dealing with weird Go interface nil bullshit. // dealing with weird Go interface nil bullshit.
func isNil(i interface{}) bool { func isNil(i interface{}) bool {