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 WebAssembly #215
Conversation
Nice, thanks for sending this! Hoping I'll have time to review this soon (midnight here, and quite busy in general at work). One thing that immediately pops out to me: I think instead of using |
@slimsag That's is unfortunately not going to help, given that the code base already references |
(Note that |
@damz I am aware that |
That would mean the vecty API is different for GopherJS and Wasm, so users would need to change their code (how they use vecty) depending on whether they want to compile with GopherJS or Wasm. That wouldn't be great. It works best when when the package API is pure Go, and I don't know if it's viable to achieve that with vecty, but I just wanted to share these observations. In the case of |
@dmitshur Agreed, even |
FWIW, I uploaded a demo of the Markdown example compiled to WebAssembly. |
@dmitshur I am aware this would be the case. I am approaching this with the assumption that mid to long term, everyone will be switching over to Go's native WebAssembly support and away from GopherJS, but I suppose that could be an invalid assumption on my part. One fact that will likely always be true is that Vecty must expose some sort of access to the underlying DOM nodes, i.e. our public API will always have some way to get a If my assumption is right and GopherJS will eventually go away, I think exposing something like If my assumption is wrong and GopherJS will stay around e.g. even once Go 2 comes out, I think exposing So I think the deciding answer for me boils down to the question: What is the future of GopherJS vs. WebAssembly? |
As somebody that was intrigued by GopherJS, I never actually wanted to use it. With WebAssembly, I'm all over it. There are obviously differences in the details that I'm sure GopherJS people might prefer it, but from my point of view as a GopherJS outsider, with WebAssembly there is no reason for GopherJS. In fact, it's possible with some of the work we've been doing on top of the WebAssembly port, Vecty will become more popular focusing on WebAssembly. |
@slimsag you might like to consider waiting for https://go-review.googlesource.com/c/go/+/142004 to land first? |
@myitcv thanks for the link. Yeah, I agree, given that is likely to change our implementation significantly. It also seems others here haven't quite had a chance to give input on my last message (or they don't wish to); I'll wait a bit longer for now. I am still currently leaning towards "GopherJS will one day go away (so we should expose a pure non- |
To answer your call for responses. The conceptual model relies on accepting a wasm web worker being a Server, and the window being the client. The question as to if gopherjs can be used in the window should be addressed. I am finding it useful for small interactive things like gathering form data etc or special UX effects. |
It's been a while (too long) and I think the correct decision is likely to be supporting WebAssembly and GopherJS under separate build tags for the reasons outlined in my prior comment. I will work on adding support for WebAssembly using this approach. Also, I don't know for certain yet, but I suspect my prior statement to be more true given recent discussion around sunsetting GopherJS here: gopherjs/gopherjs#855 (comment) Some of this sparks questions for me about whether or not Vecty should live under the GopherJS organization long-term, file #230 for discussing that. |
I've sent #232 which will supersede this PR by implementing the alternative approach I mentioned in my comments above. |
This is a fully working implementation of WebAssembly support in Vecty.
The really nice thing here is that a given code base can be compiled to JavaScript or to WebAssembly with barely any change (the only thing absolutely necessary is to add a
select {}
at the end ofmain
for the WebAssembly version).But there are a number of obvious problems for discussion:
github.com/gopherjs/gopherjs/js
withgithub.com/gopherjs/gopherwasm/js
, and as a consequence introduces a large BC break;syscall/js
andgithub.com/gopherjs/gopherwasm/js
) does not have a way to call aCallback
synchronously, which the test suite hacks around by sleeping for 10ms (runtime.Gosched()
is not enough);github.com/gopherjs/gopherwasm/js
doesn't have the minimum support for native (i.e. non-gopherjs and non-wasm) builds, so the test suite fails undergo test
(but it passes under bothGOOS=js GOARCH=wasm go test
and undergopherjs test
).