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

compiler/natives, compiler/gopherjspkg: simplify file embedding by using embed package, if it's a good fit #1149

Open
dmitshur opened this issue Sep 18, 2022 · 2 comments
Labels

Comments

@dmitshur
Copy link
Member

dmitshur commented Sep 18, 2022

GopherJS relies on vfsgen to embed some files. vfsgen predates Go's embed package, so I wanted to see if it's no longer needed. I tried it out on the embed-natives branch.

It turned out to work well to replace vfsgen with embed for the compiler/natives package; see commit 6078b6b and its commit message for some minor details.

For the compiler/gopherjspkg, I haven't found a way to do it that I'm happy with. It's running into embed's restriction files cannot be embedded from the parent directory, so embedding files in js and nosync directories at the top level can only be done from that directory (which is where the gopherjs command currently sits) or from js and nosync directories themselves (which is where those packages sit). It's possible to make extra copies, or to try to do the embedding in the gopherjs command and provide it to the compiler package as an input (this makes the API of compiler package harder to use). Neither of those options seem better than the current use of vfsgen.

It would be nice to remove reliance on vfsgen completely, but since there doesn't seem to be a clean path to do it, it seems fine to leave gopherjspkg alone for now and at least tackle natives.

Any thoughts? I can open a PR to merge the current version of the embed-natives branch into master.

@nevkontakte
Copy link
Member

This would be great to do, even for compiler/natives only. Having to regenerate the VFS every time is kind of tedious and natives are changed a lot more frequently than the other two packages.

For js and nosync packages, I feel like there must be some kind of solution that doesn't require vfsgen, but I haven't put much though into it. Ideally, it would be addressed by Go Modules where the user's project specifies the dependency on the gopherjs module in go.mod, thus making them both available. But that becomes fragile when the user code doesn't import them directly, using syscall/js API instead.

On a somewhat related note, we could do the same for prelude: move unminified JS code into .js files, embed them, and use something like esbuild or minify to minify it at runtime.

@dmitshur
Copy link
Member Author

Thanks. I've made PR #1151 that takes care of natives. The rest can be future work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants