-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Restructure web bindings #569
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
Conversation
3662b04
to
f25e0f3
Compare
Thanks for calling out that issue about the intended use of I'd prefer to deal with this separately from all of the the other changes that you've made on this branch though: the changes that deal with typescript, eslint, prettier, and all of code style. Would you be ok with backing those changes out of this branch? I'd love to merge a PR that just achieves the following:
I'm still open to the typescript stuff, and potentially the prettier stuff in the future, but it's something I think we should tackle in a separate PR in order to reduce the risk. |
I'd be happy to split up the PR into distinct stages - this one is definitely quite big and risky. Would you want the fixes to the existing typescript declarations also broken out into a separate PR? |
Oh I didn't realize that you had fixed the declarations as well. My main concern is that this PR should just be about the emscripten build config. For the typescript stuff, I'm not 100% sure yet.
I think that these are both very good points, and well said. The build-time complexity was something I had been trying to avoid, but maybe it is worth it in order to make it easier to maintain the type declarations. To me, it seems reasonable to keep the work that you've done on the TypeScript conversion, at least for now, rather than separating out the fixed declarations. After merging this PR (with just the emscripten changes), you could open a separate PR with the rest of your changes, and I'll feel a little more confident in evaluating the tradeoff of build complexity vs code maintainability. Also, thanks a lot for exploring these issues; this is great. It makes sense that you wanted to explore multiple issues at a time, at least at first; hopefully it's not too onerous to separate it out after-the-fact. |
Agreed, I'll leave the TypeScript changes in a separate PR.
Yeah I went down many paths that didn't work at first and ended up here, but now that I have something that appears to work well it shouldn't be too much effort to go back and pull out the individual pieces. |
Good work. I think the API to provide WASM file location we wanted in #559 can be supported easily after this PR. Emscripten can generate the glue code that exports a module with the newly added option If we change the option to Not too much code will be changed -- just move the construction of the global promise to the |
Oh perfect, didn't know that was an option for that. I can integrate that into one of the PR stages. |
Now that #570 is up, I'm gonna close this one. |
This PR was initially motivated by #555.
Currently, the output of emscripten is wrapped with
prefix.js
andbinding.js
using--pre-js
and--post-js
code to create the module. This is nice because no extra dependencies are required. However this is not the intended use of these options (see bullet 2 emscripten-core/emscripten#6814), and the typescript declarations must be manually maintained. Additionally, not much control is provided on the output artifacts and the bindings must be written in javascript. Although it's a minor nitpick, since neitherprefix.js
orbinding.js
are syntactically valid js, it's awkward to add standard tooling such as linters.In an attempt to remedy these issues, this PR makes the following changes:
EXPORT_ES6
emscripten option to create an es6 module.prefix.js
andbinding.js
into a single file that imports the generated emscripten module.Converting the bindings to TypeScript and then generating the declarations uncovered several mistakes in the manually declared bindings, which is some evidence for the benefit of this approach (see also #498). However, this adds a significant number of deps and complicates the build process so it may not be worth it.
Using rollup also provides more flexibility in the output artifacts - it would be trivial to add separate minified output just for browsers and unminified output just for es6 modules.
Although all the tests are passing, I'm not positive this preserves all current behavior, hence the WIP. Also, a significant proportion of the diff is purely cosmetic changes resulting from prettier + eslint.