-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Update embind to work with the Closure Compiler #3084
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
Update embind to work with the Closure Compiler #3084
Conversation
cc @chadaustin This is surprising, since imvu uses closure and embind? Perhaps not by appending code, though. The normal usage in emscripten is generally to use |
I don't necessarily prefer appending versus In this particular case though, it is using The solutions I know of are to either use As to why @chadaustin hasn't run into problems if imvu does indeed use Closure, my wild guess would be that it could be because they weren't exercising the part that was broken, which specifically is the code for extending a C++ class from JavaScript. |
Ok, if the problem happens with Looking at the changes, it makes sense that extending a C++ class from JavaScript would need extra closure annotations. Changes look good to me (except for the testing issue), but leaving to @chadaustin . |
OK, if |
This change adds a pass to the embind tests to run them with the Closure Compiler enabled. Because embind.test.js will be passed through the Closure Compiler, name- mangling will occur on unquoted references to embound classes and functions. However, because embound symbols are exposed via string literals, this results in a mismatch. The tests have now been updated so that all references to embound symbols are referred to by string literals (i.e. object["property"] syntax) instead of just by name (i.e. object.property syntax). A set of Closure externs for Underscore were also added, because Underscore (which is used by the embind test adapter) exposes some symbols by string literal as well.
Several names within the embind JavaScript itself need to be guarded from name mangling in the Closure Compiler. With this commit, the embind tests will now pass in the Closure Compiler test phase.
9a5dea0
to
1ea1a63
Compare
I've updated the pull request so that everything is going through Let me know what you think. |
By the way, I've left the original PR branch at https://github.com/rharkeadsk/emscripten/tree/dev/embind-closure-old for reference. |
$$.preservePointerOnDelete = true; | ||
Object.defineProperty(this, '$$', { | ||
Object.defineProperties(this, { $$: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, I had the same question. :)
Looks good, one question above (and we need @chadaustin 's feedback here). |
$$ is an internal property used by embind, and is referred to throughout |
Got it, thanks. |
I am also surprised we haven't run into this before! We've used Closure Compiler since day one. cc @waywardmonkeys Any ideas? That said, the changes look fine to me. It would be great if @waywardmonkeys could give them a once over too. |
That is a bit of a mystery. I will look into that some. |
Any update on this? |
Sorry for the delay. I think I meant to merge this but didn't. Thanks again! |
Update embind to work with the Closure Compiler
Wait, are we decided on all the issues here? In particular, look at the size of the diff on |
Good point. I didn't see the embind.test.js changes because the github PR diff UI hid them for some reason. Yes, those are not necessary - you don't need to run closure on your tests. I can revert that single file. |
I reverted the changes to embind.test.js in 36cd7a4 |
LLVM 3.5 has been merged to incoming. This has a known issue with embind which might mask breakage caused by that revert (see emscripten-core/emscripten-fastcomp#51 ). To test the revert, can use master branches + the revert commit. |
Fix for that known issue has been pushed. The breakage from that revert is unmasked, i.e., can just run |
We discovered that certain parts of embind do not work when the code is run through the Closure Compiler (
--closure 1
). Several names within the embind JavaScript itself need to be guarded from namemangling in the Closure Compiler.
The existing tests would be sufficient to detect this case, except that they were never being run with the Closure Compiler enabled. This pull request also updates
other.test_embind
to run a pass with the Closure Compiler enabled.Because the tests were never designed to themselves be Closure'd, I updated the test to manually append the tests and the test adapter to the output JavaScript, instead of using
--post-js
. We considered updating the tests themselves to be Closure'able, but that turned into a minor nightmare- I think this way is better, but if you feel otherwise please let me know. We would be happy to finish that work if it is the preferred road forward.Small updates were also needed to the test adapter to make it work- it was relying on the
assert
function from Emscripten, and now needs to create its own object rather than appending to it.