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

syscall/js: nanotime and walltime not compatible with wasm_exec.js #35205

Closed
EntityB opened this issue Oct 28, 2019 · 3 comments
Closed

syscall/js: nanotime and walltime not compatible with wasm_exec.js #35205

EntityB opened this issue Oct 28, 2019 · 3 comments
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@EntityB
Copy link

EntityB commented Oct 28, 2019

What version of Go are you using (go version)?

$ go version go1.13.3 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/entityb/.cache/go-build"
GOENV="/home/entityb/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/entityb/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go-1.13"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.13/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build157101446=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Build a minimum program for WASM

main.go

package main

import (
	"syscall/js"
)

func main() {

	doc := js.Global().Get("document")
	body := doc.Get("body")

	message := "<h1>Hello world!</h1>"

	body.Set("innerHTML", message)
}

index.html

<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8" />
    <title>TinyGo WASM Boilerplate</title>
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <script src="wasm_exec.js" defer></script>
    <script src="wasm.js" defer></script>
</head>

<body>

</body>

</html>

wasm.js

window.addEventListener("load", () => {
  if (!WebAssembly.instantiateStreaming) { // polyfill
    WebAssembly.instantiateStreaming = async (resp, importObject) => {
      const source = await (await resp).arrayBuffer();
      return await WebAssembly.instantiate(source, importObject);
    };
  }
  const go = new Go();
  let mod, inst;
  WebAssembly.instantiateStreaming(fetch("wasm.wasm"), go.importObject).then((result) => {
    mod = result.module;
    inst = result.instance;
    run();
  }).catch((err) => {
    console.error(err);
  });
  async function run() {
    await go.run(inst);
    inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance
  }
});

wasm_exec.js
from latest master:
https://github.com/golang/go/blob/master/misc/wasm/wasm_exec.js

build command:

GOOS=js GOARCH=wasm go build -o ./wasm.wasm ./main.go

What did you expect to see?

No errors on the webpage/console.

Hello world! in the body

What did you see instead?

Error in console:

LinkError: WebAssembly.instantiate(): Import #3 module="go" function="runtime.nanotime" error: function import requires a callable

After fixing by renaming in wasm_exec.js:

LinkError: WebAssembly.instantiate(): Import #4 module="go" function="runtime.walltime" error: function import requires a callable

Source of the issue seems to be in this commit:
4af3c17

I'm not sure what was the goal here, but something was done wrong. The wasm_exec.js file is not compatible now.

@bradfitz
Copy link
Contributor

/cc @neelance

@bradfitz bradfitz added arch-wasm WebAssembly issues NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 28, 2019
@bradfitz bradfitz added this to the Go1.14 milestone Oct 28, 2019
@cherrymui
Copy link
Member

$ go version go1.13.3 linux/amd64

wasm_exec.js
from latest master:
https://github.com/golang/go/blob/master/misc/wasm/wasm_exec.js

If you use Go 1.13.3, you should also use wasm_exec.js from Go 1.13.3 tree.

@EntityB
Copy link
Author

EntityB commented Oct 29, 2019

@cherrymui thanks for the advice! For some reason, I though that 1.13.3 is the master since it is the latest release :( It is working now.

@EntityB EntityB closed this as completed Oct 29, 2019
@golang golang locked and limited conversation to collaborators Oct 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly issues FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants