Skip to content

Commit

Permalink
temporary fix for tetratelabs/wazero#2365 armv8 compiler support bug
Browse files Browse the repository at this point in the history
  • Loading branch information
NyaaaWhatsUpDoc committed Feb 6, 2025
1 parent dd094e4 commit 76b1196
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions internal/media/ffmpeg/wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ package ffmpeg
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
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 76b1196

Please sign in to comment.