-
Notifications
You must be signed in to change notification settings - Fork 412
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
Wasm of ocaml support #10695
Closed
Closed
Wasm of ocaml support #10695
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
40ac010
Add wasm_files option and wasmoo_runtime META file entry
vouillon 39b83ab
Compilation to Wasm using Wasm_of_ocaml
vouillon 2de7794
Update documentation
vouillon d998954
Add tests
vouillon 5e0eaaf
Changes
vouillon 52523e3
ci: enable wasm_of_ocaml tests
vouillon fb09911
Wording changes
vouillon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
- Wasm_of_ocaml support (#10695, @vouillon) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
.. _wasmoo: | ||
|
||
*************************************** | ||
Wasm Compilation With Wasm_of_ocaml | ||
*************************************** | ||
|
||
.. TODO(diataxis) | ||
|
||
This is an how-to guide. | ||
|
||
Wasm_of_ocaml_ is a compiler from OCaml to WebAssembly (Wasm for | ||
short). The compiler works by translating OCaml bytecode to Wasm code. | ||
|
||
Compiling to Wasm is very similar to compiling to JavaScript. See | ||
:doc:`jsoo` for more information. | ||
|
||
|
||
Compiling to Wasm | ||
================= | ||
|
||
Dune has full support for building wasm_of_ocaml libraries and executables transparently. | ||
There's no need to customise or enable anything to compile OCaml | ||
libraries/executables to Wasm. | ||
|
||
To build a Wasm executable, just define an executable as you would normally. | ||
Consider this example: | ||
|
||
.. code:: console | ||
|
||
$ echo 'print_endline "hello from wasm"' > foo.ml | ||
|
||
With the following ``dune`` file: | ||
|
||
.. code:: dune | ||
|
||
(executable (name foo) (modes js) (js_of_ocaml (submodes wasm))) | ||
|
||
And then request the ``.wasm.js`` target: | ||
|
||
.. code:: console | ||
|
||
$ dune build ./foo.bc.wasm.js | ||
$ node _build/default/foo.bc.wasm.js | ||
hello from wasm | ||
|
||
.. _wasm_of_ocaml: https://github.com/ocaml-wasm/wasm_of_ocaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Instead of having this, which controls JS vs WASM generation globally, couldn't we add a
wasm
constructor to the(modes)
field inexecutable
stanzas (similar to how there is ajs
constructor)?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.
I've been unhappy about submodes but never had enough time to think about it.
I wonder if we could do something with modes of the form
(<compilation-mode> <binary-kind>)
.We could have
(jsoo js)
and(jsoo wasm)
, or something.IIRC, you want to be able to compile both js and wasm without touching all dune files. We could imagine a new
env
field that define the semantic of the 'js' mode.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.
This directive can also be included in
executable
stanzas.I'm not completely happy with the design either. It might be better to have a separate
wasm_of_ocaml
field, for instance, to be able to pass different flags to the compilers.Still, I think we need a global way to specify whether we want to generate JavaScript and/or Wasm code.
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.
Maybe we could have these in
env
stanzas:and a
(jsoo default)
executable mode.And the mode
(jsoo js)
and(jsoo wasm)
could be used to generate explicitly some Wasm or JavaScript code.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.
Agreed that this submodes stuff doesn't seem satisfactory. Making it more similar to regular modes would be preferable.