diff options
| author | 2025-02-06 12:44:40 +0000 | |
|---|---|---|
| committer | 2025-02-06 12:44:40 +0000 | |
| commit | 1276cde4b3db5db76f90620aca37e6c56c74807d (patch) | |
| tree | 48fb483257f814f4c6f05435bf84b217d41b4e84 | |
| parent | [chore] update readme support matrix (#3738) (diff) | |
| download | gotosocial-1276cde4b3db5db76f90620aca37e6c56c74807d.tar.xz | |
temporary fix for tetratelabs/wazero#2365 armv8 compiler support bug (#3741)
| -rw-r--r-- | internal/media/ffmpeg/wasm.go | 35 | 
1 files 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 @@ 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 @@ -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 {  | 
