Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for go1.24 #68

Merged
merged 6 commits into from
Oct 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading