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

WebAssembly: update support file location #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 10 additions & 8 deletions WebAssembly.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ page.

> If you are on Windows, we suggest to follow this tutorial using a BASH emulation system such as Git Bash.

> For Go 1.23 and earlier, the wasm support files needed in this article are located in `misc/wasm`, and the path should be replaced when performing operations with files such as `lib/wasm/wasm_exec.js`.

To compile a basic Go package for the web:

```go
Expand Down Expand Up @@ -63,7 +65,7 @@ support file, and a HTML page to connect everything together.
Copy the JavaScript support file:

```sh
cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" .
cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" .
```

Create an `index.html` file:
Expand Down Expand Up @@ -120,12 +122,12 @@ rather than a browser, which can be useful for testing and automation.

First, make sure Node is installed and in your `PATH`.

Then, add `$(go env GOROOT)/misc/wasm` to your `PATH`.
Then, add `$(go env GOROOT)/lib/wasm` to your `PATH`.
This will allow `go run` and `go test` find `go_js_wasm_exec` in a `PATH` search
and use it to just work for `js/wasm`:

```console
$ export PATH="$PATH:$(go env GOROOT)/misc/wasm"
$ export PATH="$PATH:$(go env GOROOT)/lib/wasm"
$ GOOS=js GOARCH=wasm go run .
Hello, WebAssembly!
$ GOOS=js GOARCH=wasm go test
Expand All @@ -137,15 +139,15 @@ If you're running working on Go itself, this will also allow you to run `run.bas
seamlessly.

`go_js_wasm_exec` is a wrapper that allows running Go Wasm binaries in Node. By default,
it may be found in the `misc/wasm` directory of your Go installation.
it may be found in the `lib/wasm` directory of your Go installation.

If you'd rather not add anything to your `PATH`, you may also set the `-exec` flag to
the location of `go_js_wasm_exec` when you execute `go run` or `go test` manually.

```console
$ GOOS=js GOARCH=wasm go run -exec="$(go env GOROOT)/misc/wasm/go_js_wasm_exec" .
$ GOOS=js GOARCH=wasm go run -exec="$(go env GOROOT)/lib/wasm/go_js_wasm_exec" .
Hello, WebAssembly!
$ GOOS=js GOARCH=wasm go test -exec="$(go env GOROOT)/misc/wasm/go_js_wasm_exec"
$ GOOS=js GOARCH=wasm go test -exec="$(go env GOROOT)/lib/wasm/go_js_wasm_exec"
PASS
ok example.org/my/pkg 0.800s
```
Expand All @@ -154,10 +156,10 @@ Finally, the wrapper may also be used to directly execute a Go Wasm binary:

```console
$ GOOS=js GOARCH=wasm go build -o mybin .
$ $(go env GOROOT)/misc/wasm/go_js_wasm_exec ./mybin
$ $(go env GOROOT)/lib/wasm/go_js_wasm_exec ./mybin
Hello, WebAssembly!
$ GOOS=js GOARCH=wasm go test -c
$ $(go env GOROOT)/misc/wasm/go_js_wasm_exec ./pkg.test
$ $(go env GOROOT)/lib/wasm/go_js_wasm_exec ./pkg.test
PASS
ok example.org/my/pkg 0.800s
```
Expand Down