Skip to content

Commit

Permalink
add support for go1.24 (#68)
Browse files Browse the repository at this point in the history
* fix: hack to handle the go toolchain

* fix: typo

* feat: also find new location for wasm_exec.js

* feat: remove fallback

* feat: return error to let exit happen elsewhere

Co-authored-by: Agniva De Sarker <[email protected]>

* added import

---------

Co-authored-by: Agniva De Sarker <[email protected]>
  • Loading branch information
Zxilly and agnivade authored Oct 29, 2024
1 parent 0667919 commit a249c2e
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import (
"crypto/rand"
_ "embed"
"encoding/base64"
"errors"
"fmt"
"html/template"
"io"
"log"
"net/http"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
Expand All @@ -33,6 +34,11 @@ type wasmServer struct {
securityToken string
}

var wasmLocations = []string{
"misc/wasm/wasm_exec.js",
"lib/wasm/wasm_exec.js",
}

func NewWASMServer(wasmFile string, args []string, coverageFile string, l *log.Logger) (http.Handler, error) {
var err error
srv := &wasmServer{
Expand All @@ -55,8 +61,23 @@ func NewWASMServer(wasmFile string, args []string, coverageFile string, l *log.L
srv.envMap[vars[0]] = vars[1]
}

buf, err := os.ReadFile(path.Join(runtime.GOROOT(), "misc/wasm/wasm_exec.js"))
var buf []byte
for _, loc := range wasmLocations {
buf, err = os.ReadFile(filepath.Join(runtime.GOROOT(), loc))
if err == nil {
break
}
if !os.IsNotExist(err) {
return nil, err
}
}
if err != nil {
var perr *os.PathError
if errors.As(err, &perr) {
if strings.Contains(perr.Path, filepath.Join("golang.org", "toolchain")) {
return nil, fmt.Errorf("The Go toolchain does not include the WebAssembly exec helper before Go 1.24. Please copy wasm_exec.js to %s", filepath.Join(runtime.GOROOT(), "misc", "wasm", "wasm_exec.js"))
}
}
return nil, err
}
srv.wasmExecJS = buf
Expand Down

0 comments on commit a249c2e

Please sign in to comment.