From 1276cde4b3db5db76f90620aca37e6c56c74807d Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Thu, 6 Feb 2025 12:44:40 +0000 Subject: [PATCH] temporary fix for tetratelabs/wazero#2365 armv8 compiler support bug (#3741) --- internal/media/ffmpeg/wasm.go | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/internal/media/ffmpeg/wasm.go b/internal/media/ffmpeg/wasm.go index a22431fdd..29e547364 100644 --- a/internal/media/ffmpeg/wasm.go +++ b/internal/media/ffmpeg/wasm.go @@ -22,12 +22,14 @@ import ( "context" "os" + "runtime" "sync/atomic" "unsafe" "codeberg.org/gruf/go-ffmpreg/embed" "codeberg.org/gruf/go-ffmpreg/wasm" "github.com/tetratelabs/wazero" + "golang.org/x/sys/cpu" ) // ffmpreg is a concurrency-safe pointer @@ -46,8 +48,17 @@ func initWASM(ctx context.Context) error { return nil } - // Create new runtime config. - cfg := wazero.NewRuntimeConfig() + var cfg wazero.RuntimeConfig + + // 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 != "" { // Use on-filesystem compilation cache given by env. @@ -110,6 +121,26 @@ func initWASM(ctx context.Context) error { 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 // dealing with weird Go interface nil bullshit. func isNil(i interface{}) bool {