-
Notifications
You must be signed in to change notification settings - Fork 413
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 #11093
Merged
Merged
Wasm_of_ocaml support #11093
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
f1d0369
Add wasm_files option and wasmoo_runtime META file entry
vouillon 774d877
Compilation to Wasm using Wasm_of_ocaml
vouillon 5da9c12
Update documentation
vouillon fae1f0c
Add tests
vouillon 7ba44dd
Changes
vouillon a1cbe1f
ci: enable wasm_of_ocaml tests
vouillon 5c1c339
Wording changes
vouillon 4ae8cc4
_
rgrinberg e26ece4
_
rgrinberg 21ca0ca
_
rgrinberg 3fb2541
_
rgrinberg 583ba09
_
rgrinberg 0e10ece
_
rgrinberg f4e3c59
Wasm_of_ocaml support: alternative design
vouillon 409a0f8
CR
vouillon 7b034e6
CR
vouillon cb89db6
CR
vouillon fd5acfc
Updated documentation
vouillon d31295f
Some clean-up
vouillon be2bd4a
CR
vouillon 17e954a
CR
vouillon aea189c
Disallow `(wasm_of_ocaml (sourcemap file))`
vouillon 2c0c5f6
Clean-up
vouillon a4bc007
enabled_if not allowed in libraries
vouillon f76b05e
Doc: how to install wasm_of_ocaml
vouillon 906b5e0
CR
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
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 (#11093, @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
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,104 @@ | ||
.. _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 | ||
================= | ||
|
||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the documentation mention the external dependencies that are required for the build ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I now explicitly point to the github repository above. |
||
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 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 | ||
|
||
If you're using the js_of_ocaml syntax extension, you must remember to add the | ||
appropriate PPX in the ``preprocess`` field: | ||
|
||
.. code:: dune | ||
|
||
(executable | ||
(name foo) | ||
(modes wasm) | ||
(preprocess (pps js_of_ocaml-ppx))) | ||
|
||
Selective Compilation | ||
===================== | ||
|
||
The ``js`` and ``wasm`` modes can be selectively disabled using the ``(js_of_ocaml (enabled_if ...))`` and ``(wasm_of_ocaml (enabled_if ...))`` options. This allows for instance to generate one, or the other dependings on a profile: | ||
|
||
.. code:: dune | ||
|
||
(env | ||
(js-only | ||
(wasm_of_ocaml | ||
(enabled_if false))) | ||
(wasm-only | ||
(js_of_ocaml | ||
(enabled_if false)))) | ||
|
||
To be able to invoke the generated code using the same JavaScript script name in all cases, you can add a rule to copy the Wasm launcher script when the js_of_ocaml compilation is disabled. | ||
|
||
.. code:: dune | ||
|
||
(rule | ||
(action | ||
(copy foo.bc.wasm.js foo.bc.js)) | ||
(enabled_if | ||
(= %{profile} wasm-only))) | ||
|
||
Separate Compilation | ||
==================== | ||
|
||
Dune supports two modes of compilation: | ||
|
||
- Direct compilation of a bytecode program to Wasm. This mode allows | ||
wasm_of_ocaml to perform whole-program deadcode elimination and whole-program | ||
inlining. | ||
|
||
- Separate compilation, where compilation units are compiled to Wasm | ||
separately and then linked together. This mode is useful during development as | ||
it builds more quickly. | ||
|
||
The separate compilation mode will be selected when the build profile | ||
is ``dev``, which is the default. It can also be explicitly specified | ||
in an ``env`` stanza (see :doc:`/reference/dune/env`) or per executable | ||
inside ``(wasm_of_ocaml (compilation_mode ...))`` (see :doc:`/reference/dune/executable`) | ||
|
||
Sourcemap | ||
========= | ||
|
||
Wasm_of_ocaml can generate sourcemaps for the generated Wasm code. | ||
By default, they are generated when using the ``dev`` build profile and are not generated otherwise. | ||
The behavior can explicitly be specified in an ``env`` stanza (see :doc:`/reference/dune/env`) | ||
or per executable inside ``(wasm_of_ocaml (sourcemap ...))`` (see :doc:`/reference/dune/executable`) | ||
|
||
.. _wasm_of_ocaml: https://github.com/ocaml-wasm/wasm_of_ocaml |
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.
Opam depext is unused in setup-ocaml v3