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 4 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
27 changes: 23 additions & 4 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"crypto/rand"
_ "embed"
"encoding/base64"
"fmt"
"html/template"
"io"
"log"
"net/http"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
Expand All @@ -33,6 +33,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,9 +60,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"))
if err != nil {
return nil, err
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 len(buf) == 0 {
agnivade marked this conversation as resolved.
Show resolved Hide resolved
if !strings.Contains(runtime.GOROOT(), "golang.org"+string(os.PathSeparator)+"toolchain") {
return nil, err
}
fmt.Fprintln(os.Stderr, "The go toolchain does not include the WebAssembly exec helper before Go 1.24.")
fmt.Fprintf(os.Stderr, "You should copy wasm_exec.js to %s\n", filepath.Join(runtime.GOROOT(), "misc", "wasm", "wasm_exec.js"))
os.Exit(1)
}
Zxilly marked this conversation as resolved.
Show resolved Hide resolved
srv.wasmExecJS = buf

Expand Down