Skip to content

Conversation

@phated
Copy link
Contributor

@phated phated commented May 3, 2022

I lost my previous patch and needed to recreate it, and I'm submitting this upstream so I don't lose it again. We need to have a special build target for libbinaryen compiled for js_of_ocaml and our binaryen.ml bindings (also compiled with js_of_ocaml).

This shouldn't add any overhead to normal workflows, as you need to use emcmake with the specific target to run it and it would make my life a lot easier for generating everything in the Grain libraries. What do you think?

@@ -0,0 +1,7 @@
//Provides: binaryen
var binaryen = {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the differences between this and the main binaryen.js build? This line seems to be added, and also -s WASM=0 - anything else? (If just those two then maybe we can add a build flag with an ifdef for each of them, which would avoid duplication.)

Also, what does this line do? I'm not sure why it's needed in your build but not the default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WASM=0 is actually specified in the binaryen_js target, but even binaryen.js only uses the wasm version now.

A few things are going on with this line:

  1. If a var matching EXPORT_NAME doesn't exist, the value is attached to the global, which doesn't work for js_of_ocaml
  2. js_of_ocaml uses the //Provides: syntax to treeshake values from the program

Other changes include:

  1. ENVIRONMENT to only web and worker because js_of_ocaml tries to get smart about node globals and it breaks the usage.
  2. Compiling to ES5, which was changed previously.
  3. EXPORT_ES6=0 because we need plain ES5 javascript until js_of_ocaml finishes their ES6 support
  4. NO_FILESYSTEM=1 - since node is not supported, this ensures there is no filesystem related code in the file that might make js_of_ocaml think it is running in node.

I'm happy to use ifdef or any other solution you want, this was just the patch that I had to generate the file we need.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks. Ok, then I think a new build flag would be best. It sounds like these are specific to js_of_ocaml, so perhaps literally a new flag JS_OF_OCAML? Then we'd ifdef based on that on each of the bullet points you mention 1-2 and 1-4. That would avoid duplication and make it clear what the differences actually are (comments on each would be good as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Should be updated now (I also updated this branch to with main)

@phated phated force-pushed the phated/js-patch/version_106 branch from e5164e6 to 2f0bf1a Compare May 5, 2022 20:13
Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with a declaration of that new variable, something like

// (comment with more details?)
option(JS_OF_OCAML "Build binaryen.js for js_of_ocaml" OFF)

I think that help text shows up in cmake's help for the project, or something like that.

@phated
Copy link
Contributor Author

phated commented May 5, 2022

Cool! Didn't know about that. TIL about cmake -LAH 😄

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

@kripken kripken enabled auto-merge (squash) May 6, 2022 00:16
@kripken kripken merged commit 8554428 into WebAssembly:main May 6, 2022
@phated phated deleted the phated/js-patch/version_106 branch May 6, 2022 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants