mirror of
https://github.com/taigrr/wasm-experiments
synced 2025-01-18 04:03:21 -08:00
Update README with more information
This commit is contained in:
parent
f110c81f2f
commit
b259a71e1a
75
README.md
75
README.md
@ -1,7 +1,78 @@
|
||||
# wasm-experiments
|
||||
|
||||
Just some playing around with the new experimental Go WASM arch target
|
||||
Just some playing around with the experimental Go WebAssembly arch target.
|
||||
|
||||
## Requirements
|
||||
|
||||
Requires `go` 1.11
|
||||
Requires `go` >= 1.11.0.
|
||||
[TinyGo](https://github.com/tinygo-org/tinygo) examples require `docker`.
|
||||
|
||||
## Basic instructions
|
||||
|
||||
Choose your target from the experiments. Compile with `make <target>` and serve
|
||||
with `make serve`. This starts a local web server which serves the `./html`
|
||||
directory. It ensures `.wasm` files are served with their appropriate
|
||||
content-type.
|
||||
|
||||
For example:
|
||||
|
||||
```bash
|
||||
$ make hello
|
||||
rm -f ./html/*
|
||||
GOOS=js GOARCH=wasm go build -o ./html/test.wasm ./hello/main.go
|
||||
cp $(go env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
|
||||
cp $(go env GOROOT)/misc/wasm/wasm_exec.js ./html/wasm_exec.js
|
||||
$ make serve
|
||||
go run main.go
|
||||
2019/02/24 14:11:51 Serving on http://localhost:8080
|
||||
```
|
||||
|
||||
Navigate to http://localhost:8080 to load the page. Some examples require opening
|
||||
the browser console to be seen.
|
||||
|
||||
## TinyGo targets
|
||||
|
||||
To compile something with the TinyGo WebAssembly compiler, simply choose the
|
||||
target and invoke the `tinygo` make rule with the target specified and
|
||||
serve as usual. For example:
|
||||
|
||||
```bash
|
||||
$ make tinygo target=hello
|
||||
rm -f ./html/*
|
||||
docker run --rm -v $(pwd):/go/src/github.com/johanbrandhorst/wasm-experiments --entrypoint /bin/bash tinygo/tinygo:latest -c "\
|
||||
cd /go/src/github.com/johanbrandhorst/wasm-experiments && \
|
||||
tinygo build -o ./html/test.wasm -target wasm ./hello/main.go && \
|
||||
cp /go/src/github.com/tinygo-org/tinygo/targets/wasm_exec.js ./html/wasm_exec.js\
|
||||
"
|
||||
cp $(go env GOROOT)/misc/wasm/wasm_exec.html ./html/index.html
|
||||
$ make serve
|
||||
go run main.go
|
||||
2019/02/24 14:33:58 Serving on http://localhost:8080
|
||||
```
|
||||
|
||||
Note that some of the targets either do not compile or panic at runtime when
|
||||
compiled with TinyGo. The following targets have been tested to work with
|
||||
TinyGo:
|
||||
|
||||
- `hello`
|
||||
- `channels`
|
||||
|
||||
## Experiments
|
||||
|
||||
### Hello
|
||||
|
||||
A simple `Hello World` example that prints to the browser console.
|
||||
|
||||
### Channels
|
||||
|
||||
Showing basic first class support for channel operations in compiled WebAssembly.
|
||||
|
||||
### JS
|
||||
|
||||
A simple example of how to interact with the JavaScript world from WebAssembly.
|
||||
|
||||
### Fetch
|
||||
|
||||
A more complicated example showing how to use `net/http` `DefaultClient` to
|
||||
send a HTTP request, parse the result and write it to the DOM.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user