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

Go 1.11 WebAssembly modules #23

Open
mastersingh24 opened this issue Aug 20, 2018 · 17 comments
Open

Go 1.11 WebAssembly modules #23

mastersingh24 opened this issue Aug 20, 2018 · 17 comments
Labels
go modules Issues related to Go 1.11 WebAssembly module support.

Comments

@mastersingh24
Copy link
Contributor

mastersingh24 commented Aug 20, 2018

Have you guys done any testing with modules created via Go 1.11? I assume it might likely be an issue with wagon?

Simple test.go:

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Hello World")
}

Using Go 1.11rc1:
GOOS=js GOARCH=wasm go build -o test.wasm test.go
and then
./life -entry main /Users/gsingh/Projects/golang/src/webassembly/test.wasm
with result

panic: unexpected EOF

goroutine 1 [running]:
main.main()
	/Users/gsingh/tmp/life/main.go:81 +0x72c

Maybe related to go-interpreter/wagon#69 ?

@mastersingh24
Copy link
Contributor Author

The fix for this issue is to update to the latest version of wagon ... and then you'll hit go-interpreter/wagon#69

@julioholon
Copy link

Friends, we are still having this issue, even using the updated version of wagon (using @mastersingh24 's fork). Anyone able to use life at the moment?

@losfair losfair added the go modules Issues related to Go 1.11 WebAssembly module support. label Aug 25, 2018
@Xe
Copy link
Contributor

Xe commented Sep 1, 2018

I have gotten this working in olin.

Relevant commits:

Example web assembly module and its output:

xena at luna in ~/go/src/github.com/Xe/olin/internal/abi/wasmgo on master
❯ go test -v
=== RUN   TestWasmGo
=== RUN   TestWasmGo/github.com/Xe/olin/internal/abi/wasmgo.testNothing
nothing
--- PASS: TestWasmGo (1.66s)
    --- PASS: TestWasmGo/github.com/Xe/olin/internal/abi/wasmgo.testNothing (1.66s)
PASS
ok      github.com/Xe/olin/internal/abi/wasmgo  1.696s

More info here.

@Xe
Copy link
Contributor

Xe commented Sep 5, 2018

Keeping this thread updated: it seems that including most of the standard library brings in syscall/js somehow. This is getting annoying fast. I am going to fork the Go compiler with a custom GOOS (olin or dagger, can't pick which) at https://github.com/Xe/go. I will need to do a lot of low-level runtime hacking in order to genericize the code for js/wasm to work on webassembly in general, while still offering the Javascript features for things that need JS.

@Xe
Copy link
Contributor

Xe commented Sep 6, 2018

Yay weird linker errors: Xe/go@37bc30e

@ghost
Copy link

ghost commented Sep 6, 2018 via email

@mastersingh24
Copy link
Contributor Author

@Xe - syscall/js is always included when building for the js/wasm platform. The current model in Go1.11 basically assumes that your Web Assembly runtime is the browser. And the only way to pass anything between the host and the WASM module is via the syscall/js callback APIs.

@dobegor
Copy link

dobegor commented Sep 19, 2018

@mastersingh24 could you please update us on the status of this issue?
I thought go-interpreter/wagon#69 was going to be closed in go-interpreter/wagon#70, but that hasn't been merged yet.

@Immortalin
Copy link

@mastersingh24 how much of browser runtime can be pulled into life?

@Immortalin
Copy link

Can we use something like Otto to replace the JS runtime?

@Xe
Copy link
Contributor

Xe commented Sep 26, 2018

I have looked into using Otto to replace the JS runtime. I don't feel comfortable doing it because I don't know how much deviation it has from how browser JS does it.

@gladkikhartem
Copy link

gladkikhartem commented Oct 28, 2018

Hi guys,
I've managed to create a minimal, hardcoded exec.ImportResolver that can actually work with Go1.11 GOOS=js GOARCH=wasm executables.
You could use it for tinkering around or getting ideas about creating your own stuff.
It's definitely gonna change as i'm going to adapt it to event-sourcing and concurrency, but it's at least something.
What i have here is:
panic printing
Log() function
Call() function that allows you to asynchronously handle Callbacks, once VM is waiting for external event.
see usage example at: https://gitlab.com/albert_einstein/kwasm/tree/master/example

Any usage of other external communications (i.e. stdin,/stdout, http, sockets, files and etc) will cause your VM to mysteriously fail.

@Immortalin
Copy link

Any updates with Go 1.12?

@mastersingh24
Copy link
Contributor Author

Go 1.12 is actually no better here.
FWIW - people might want to checkout tinygo ... it creates much cleaner WASM and does not assume the browser as the host environment

@Xe
Copy link
Contributor

Xe commented Apr 21, 2019

I got parts of the runtime working in Olin. Here's the code: https://github.com/Xe/olin/tree/master/internal/abi/wasmgo

@TUSF
Copy link

TUSF commented Apr 22, 2019

Instead of trying to support go's js/wasm target, how about wasi/wasm?

https://hacks.mozilla.org/2019/03/standardizing-wasi-a-webassembly-system-interface/
https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-api.md

Relevant issue: golang/go#31105

@Xe
Copy link
Contributor

Xe commented Apr 22, 2019

The wasi/wasm target post-dates this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go modules Issues related to Go 1.11 WebAssembly module support.
Projects
None yet
Development

No branches or pull requests

8 participants