-
Notifications
You must be signed in to change notification settings - Fork 926
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
Support compiling basic Vecty/Vugu examples to WASM #93
Comments
Should be doable. Perhaps not
That's a really big one. If it is required, please tell me which part is because Oh and I seem to remember vecty also needs callback support in syscall/js? That's not yet implemented AFAIK. |
Updated topic with callback support, thanks! |
i'm not going to have time to look or work on this for about 2 weeks, but I'd like to consider removing the reflect requirements from vecty. That might mean it's less vecty and more something new. |
Interesting, would definitely be worthwhile thinking about coming at this problem from both ends, designing a Go web framework with TinyGo compatibility from the start could get us where we want significantly faster. Do you have a repo for this new framework already? |
I'm out of town and then on vacation for a few weeks, so I likely won't be able to follow up on this until after the holidays some time. FWIW though the list mentioned above looks correct to me. I am very interested in adding TinyGo support to Vecty, I was actually looking into how hard it would be a few weeks back but the main kicker was the lack of reflect + Vecty's usage of reflect is pretty minimal, but is required. It is used for a few things:
All other uses of reflect are just for improved debugging around printing type names, but nothing critical. |
Thank you so much for chiming in @slimsag! There's no reason we can't try to achieve this with Vecty or whatever vecty-like thing we might be able to create. The requirements for vecty then are narrowed down to:
This is obviously something TinyGo wants to support eventually anyway, but the real goal of this issue is for a vecty-like framework to be possible to use with TinyGo, so it's still valuable for us consider a new framework written from scratch to avoid the use of reflect specifically, since I don't think we'll ever be able to remove the other two requirements. |
For sure. One thing I would mention is that Vecty certainly did not use reflection because it was convenient, but rather because the API would be abysmal otherwise. I'd be super happy to see a React-like framework that doesn't require reflection and could be fully featured.. but I just don't see it being possible without the API being really unpleasant. If anyone can prove me wrong Vecty will change 😃 |
Hearing that is a strong discouragement from even trying... I know far less about it than @slimsag, not much chance I can do better. |
Thought: One viable option to bypass the reflection requirement would be code generation. Every component would have auto-generated Does tinygo have its own build tag? |
I think code generation is definitely a viable alternative. As long as we can make that easy enough to use. I suppose we would have a generator that checks for some comment or embedded interface or something like that and generate into the same directory? If it's as easy as running |
Yeah, it would be something like that; it would find all components by looking for structs that embed Ideally that would be an intermediate solution and the long term solution here would still be the reflection approach so that code generation is not needed, since code generation is not great. |
How much of these features (like reflect) would be necessary for a "proof of concept" hello world example? It would be nice to have some sort of absolute minimum to iterate on. EDIT: oh and yes there is a |
@aykevl Conclusively I think:
I am on holiday starting next week, I may try to hack something together here. I'll let you know if I do. |
I've started work on reflection support in #104. See testdata/reflect.go for what is supported. |
Fwiw, Vugu has similar requirements. vugu/vugu#39 . I'm not sure if there are other places where reflect is used but certainly the ability to obtain reflect.Value and check the Kind, and the ability to iterate over struct fields - Vugu needs those in order to function properly. And otherwise it's maps, and syscall/js. As mentioned in Slack, once I have some more of the core functionality of Vugu built out I'll see if I can help contribute on some of these points. Is there any sense in creating another issue to track Vugu-related support items for TinyGo? Or is it better to just track it all here in this issue? |
I don't think it's useful to add another issue. However, sharing what you need exactly here is very useful, like you just did.
This has been implemented
This should still be implemented. Should not be a massive amount of work, but not trivial either. (Something about priorities and hours in a day).
There is very limited support, it's barely usable in its current state. Any help here is appreciated, you can take a look at the map implementation in the runtime of the main Go compiler for ideas. Wikipedia also gives some background information.
Many functions are implemented, but to be broadly useful more functions need to be implemented. In particular, callback support ( |
Thanks for the feedback Ayke, that makes sense. On syscall/js, it's essentially:
While complex programs built with Vugu might have more requirements, the above should make a basic Vugu program compile and run. Regarding map support, sounds good. I will try following the instructions here to see if I can build from source on my machine (Mac laptop) and go from there. |
Update: the latest release (v0.6.0) has added support for |
hexops/vecty#232 has just been merged which implements WebAssembly support in Vecty using the standard Go compiler. While this doesn't automatically give us TinyGo support (unfortunately), it does give a clear picture of how far away we are. To get compilation passing we currently need:
I'll see if I can create a branch of Vecty soon that at least compiles under TinyGo to see if there are any other issues. |
Great! Now we have something to work towards. |
In my rushed attempt to merge WebAssembly support and get an announcement out at 2am last night, my sleep-deprived brain incorrectly parsed the output of `ls -s` in bytes and not kilobytes as is correctly stated in `man ls`. 🤦♂ 🤦♀ I do believe we can get much smaller bundle sizes, particularly [once we have TInyGo support](tinygo-org/tinygo#93) but it definitely wasn't my goal to mislead everyone here & in the announcement posts. Apologies for the confusion and to everyone I have misled with this mistake!
In my rushed attempt to merge WebAssembly support and get an announcement out at 2am last night, my sleep-deprived brain incorrectly parsed the output of `ls -s` in bytes and not kilobytes as is correctly stated in `man ls`. 🤦♂ 🤦♀ I do believe we can get much smaller bundle sizes, particularly [once we have TInyGo support](tinygo-org/tinygo#93) but it definitely wasn't my goal to mislead everyone here & in the announcement posts. Apologies for the confusion and to everyone I have misled with this mistake!
…242) In my rushed attempt to merge WebAssembly support and get an announcement out at 2am last night, my sleep-deprived brain incorrectly parsed the output of `ls -s` in bytes and not kilobytes as is correctly stated in `man ls`. 🤦♂ 🤦♀ I do believe we can get much smaller bundle sizes, particularly [once we have TInyGo support](tinygo-org/tinygo#93) but it definitely wasn't my goal to mislead everyone here & in the announcement posts. Apologies for the confusion and to everyone I have misled with this mistake!
I've created a WIP / hacked together branch of Vecty which passes type checking under TinyGo: hexops/vecty#243 Unfortunately, it doesn't pass compilation yet due to this issue: #440 |
Hi @ethanfrey I've done a fair amount of work getting Vugu to compile under Tinygo - the latest on master does now compile but functionally it's broken because of some things that need alternate implementation. Json is one of those things. I actually created the vjson package for this purpose but haven't written the Tinygo part of it yet (see https://github.com/vugu/vjson/blob/master/vjson-tinygo.go). The json parsing itself should be trivial to get working in tinygo and I believe a number of other json parsers out there will work fine - it's the more advanced reflection stuff that Tinygo has trouble with. Vugu does need some basic json support in order to work but it's minimal (I think only map[string]interface{} and basic types) and I plan on adding that into vjson as soon as possible. Otherwise most of the data transfer that Vugu does internally is encoded manually; I ended up making a simple "instruction" format for this - but that's really a Vugu-specific thing. If you are trying to transfer data from your app to a server, JSON is a good choice. And probably a third party library will do the trick. |
Take a look at #856, which adds support for interfaces as map keys. |
Hi @bradleypeabody thank you for the answer. I actually think |
@ethanfrey Thanks and sounds good - yes, please do let me know how that goes. To shed a little more light on it - the thing about |
any updates here? :) |
Although not entirely a blocker, module support in Tinygo would be a big help for Vugu. Vugu supports re-building your application on the fly (upon page refresh and I also just added a websocket auto reloader so editing a vugu file refreshes the page automatically). These and other tools and features are only supported and tested in conjunction with modules. My current plan is that when Tinygo has module support I will dive back in and try to get Vugu+Tinygo working. I saw this PR #941 but am not sure how close this is to being functional. (Although even as I write this I'm coming up with ideas for workarounds, but yeah, modules would make things much simpler.) |
Hi @bradleypeabody thank you for the feedback. Module support is an important feature, and we will likely return to it after the release that we are currently preparing for this week, which adds Go 1.14 and LLVM 10 support. If you have a chance to try out the latest Thanks! |
@deadprogram understood and thanks for the info. There are some challenges involved on my side but this is definitely on my todo list and I'll get back to you as soon as I can. (I do have a workaround in mind to make things work without modules and I'll try that out and see how far I can get.) |
FYI good progress is being made on this. With this issue #1091 now resolved enough to move forward, for Vugu the ball is back in my court to start testing and trying out more complex examples. But basic page rendering and event handling plus re-render loop (i.e. stuff shows up and you can click buttons that toggle things on and off) is working now and with executables that are around 250k. |
That is fantastic news Brad, congratulations to everyone involved! |
Vugu+TinyGo support now has basic functionality along with an example and some documentation: https://www.vugu.org/doc/tinygo . A majority of the Vugu test suite also now runs both the default Go compiler and TinyGo. There are still some test cases that don't work, but most of them do and I think it's working well enough to start trying it out. I'll update with anymore specific issues that arise. I know http client support (i.e. making |
Awesome news Brad, thank you so much for your contributions to this project! |
That sounds great! I saw that https://www.vugu.org/doc/tinygo says that modules are not supported:
By now, TinyGo does in fact support modules: #941. |
@aykevl Nice! I didn't realize that. I've updated the doc page text for accuracy
And I will try this out. If everything plays well together I can simplify a few things and I'll see if it makes sense to make the local (non-Docker) call approach be the default. I suspect as TinyGo gets better and better the advantages of the Docker approach will become fewer and fewer (and not be worth the added overhead). |
@bradleypeabody I took a look at Vugu and am quite impressed with how much you managed to get into Wasm, and compile with TinyGo. My respect. I am the CTO of https://github.com/CosmWasm/cosmwasm , a blockchain smart contracting module (that can plug into many different blockchains). We run Wasm modules and currently only have a Rust compile path. After watching TinyGo (and your progress with it) for some time, we have decided to start trying to port our smart contract framework to Go, and support both languages (Most blockchains we integrate with are written in Go). I started looking at your code, and would love to reuse some of it (like https://github.com/vugu/vjson) and ideally contribute back in some way if I can. Is there a better way to reach out to you than responding to this issue? |
@ethanfrey Will reply separately. |
Hi there 👋 Any updates on TinyGo working with Vecty? Thank you! |
This was released with v0.14.0 so now closing. Please reopen if needed. Thanks! |
@deadprogram thank you for the update! Trying to compile my program with tinygo results in the following errors from encoding/json
Here's a simple program to reproduce it:
@deadprogram I'm not sure if this is a known issue and if it's unrelated to compiling tiny go with vecty but thought I'd bring it up here since frontend applications will most likely use the json library for api calls. Thanks! |
@marwan-at-work encoding/json does not work with TinyGo as it makes extensive use of the reflect package (which is not fully supported by TinyGo for various technical reasons). @bradleypeabody made an amazing package https://github.com/vugu/vjson which provides TinyGo-compliant JSON parsing and unmarshalling. |
@ethanfrey thank you! I will definitely check that library out. Encoding/json aside, I tried compiling a basic Vecty app (without importing json) and got the following error:
Using this simple program:
Again, not sure if it's a vecty specific issue or a tiny-go issue with reflect but thought I'd post it here and happy to report it anywhere else that needs to be. Thanks again for the quick response and all the work on tiny go! |
Should we re-open the issue in this case? Or make a new one to track the progress on whatever is needed to compile vecty programs? Thanks |
I would suggest check out https://www.vugu.org/doc/tinygo for specifics. |
@deadprogram FWIW, I was mainly talking about vecty not vugu, and the page you linked me is very vugu specific and doesn't offer any hints on how to make vecty work :) The above program compiles with Go but it does not compile with TinyGo which makes me think it's probably more appropriate to file as a TinyGo bug rather than a Vecty bug. I definitely understand that TinyGo still doesn't fully support reflection, but I was under the impression that this issue was to track its progress since it was what was missing for Vecty to compile with tiny go. If that's the case, I'd be happy to re-open the issue, or maybe open a separate tracking issue. Otherwise, I'm happy to go with the follow on whichever is the best way to solve this issue. Thanks again and appreciate all of the work and help here! |
I think closing this issue is appropriate as it is now possible to use Vugu with TinyGo (:tada:). Vugu and TinyGo had to meet a bit in the middle on this, and I think it might be reasonable to expect the same thing from Vecty. Therefore, I think we should open a separate issue to track the outstanding work, if any, for supporting Vecty. We should port over the current errors (thanks @marwan-at-work for trying it!) so we know where the shortcomings are, and if we should tackle them in TinyGo or Vecty. I'd say the above error is a TinyGo one, but it's not unreasonable for Vecty to provide a less reflect-heavy implementation if it helps bridge the gap, like Vugu did. How does that sound? |
@johanbrandhorst done :) |
This is just a tracking issue for any outstanding work required for us to compile a vecty-style web app into WASM with tinygo. I think this would be a fantastic milestone for this repo and the Go WASM community at large, so lets see what remains outstanding.
syscall/js
callback supportreflect
includingreflect.ValueOf
,reflect.TypeOf
,reflect.New
and the following functions of thereflect.Value
type:Kind
,Elem
,String
,Interface
,Type
,NumField
,Field
,Set
Would love to have @slimsag take a quick look at this if possible, but otherwise I think @bketelsen will know the best what is outstanding.
The text was updated successfully, but these errors were encountered: