|
2 | 2 |
|
3 | 3 | Wasm_of_ocaml is a fork of Js_of_ocaml which compiles OCaml bytecode to WebAssembly.
|
4 | 4 |
|
5 |
| -## Supported engines |
6 |
| - |
7 |
| -The generated code works with Chrome 11.9, Node.js 22 and Firefox 122 (or more recent versions of these applications). |
8 |
| - |
9 |
| -In particular, the output code requires the following [Wasm extensions](https://webassembly.org/roadmap/) to run: |
10 |
| -- [the GC extension](https://github.com/WebAssembly/gc), including functional references and 31-bit integers |
11 |
| -- [the tail-call extension](https://github.com/WebAssembly/tail-call/blob/main/proposals/tail-call/Overview.md) |
12 |
| -- [the exception handling extension](https://github.com/WebAssembly/exception-handling/blob/master/proposals/exception-handling/Exceptions.md) |
13 |
| - |
14 |
| -OCaml 5.x code using effect handlers can be compiled in two different ways: |
15 |
| -One can enable the CPS transformation from `js_of_ocaml` by passing the |
16 |
| -`--enable=effects` flag. Without the flag `wasm_of_ocaml` will instead emit code |
17 |
| -utilizing |
18 |
| -- [the JavaScript-Promise Integration extension](https://github.com/WebAssembly/js-promise-integration/blob/main/proposals/js-promise-integration/Overview.md) |
19 |
| - |
20 |
| - |
21 |
| -## Installation |
22 |
| - |
23 |
| -The following commands will perform a minimal installation: |
24 |
| -``` |
25 |
| -git clone https://github.com/ocaml-wasm/wasm_of_ocaml |
26 |
| -cd wasm_of_ocaml |
27 |
| -opam pin add -n --with-version 6.0.0 . |
28 |
| -opam install dune.3.17.0 wasm_of_ocaml-compiler |
29 |
| -``` |
30 |
| -You may want to install additional packages. For instance: |
31 |
| - |
32 |
| -``` |
33 |
| -opam install js_of_ocaml-ppx js_of_ocaml-lwt |
34 |
| -``` |
35 |
| - |
36 |
| -## Usage |
37 |
| - |
38 |
| -You can try compiling the program in `examples/cubes`. Your program must first be compiled using the OCaml bytecode compiler `ocamlc`. JavaScript bindings are provided by the `js_of_ocaml` package. The syntax extension is provided by `js_of_ocaml-ppx` package. Package `js_of_ocaml-lwt` provides Javascript specific Lwt functions. |
39 |
| - |
40 |
| -``` |
41 |
| -ocamlfind ocamlc -package js_of_ocaml,js_of_ocaml-ppx,js_of_ocaml-lwt -linkpkg -o cubes.byte cubes.mli cubes.ml |
42 |
| -``` |
43 |
| - |
44 |
| -Then, run the `wasm_of_ocaml` compiler to produce WebAssembly code: |
45 |
| - |
46 |
| -``` |
47 |
| -wasm_of_ocaml cubes.byte |
48 |
| -``` |
49 |
| - |
50 |
| -This outputs a file `cubes.js` which loads the WebAssembly code from file `cube.wasm`. For debugging, we currently also output the generated WebAssembly code in text file to `cube.wat`. Since Chrome does not allow loading from the filesystem, you need to serve the files using some Web server. For instance: |
51 |
| -``` |
52 |
| -python3 -m http.server 8000 --directory . |
53 |
| -``` |
54 |
| - |
55 |
| -As a larger example, you can try [CAMLBOY](https://github.com/linoscope/CAMLBOY). You need to install a forked version of [Brr](https://github.com/ocaml-wasm/brr/tree/wasm). Once the Js_of_ocaml UI is compiled (with `dune build --profile release`), you can generate WebAssembly code instead with the following command: |
56 |
| -``` |
57 |
| -wasm_of_ocaml _build/default/bin/web/index.bc-for-jsoo |
58 |
| -``` |
59 |
| - |
60 |
| -## Implementation status |
61 |
| - |
62 |
| -A large part of the runtime is [implemented](https://github.com/ocaml-wasm/wasm_of_ocaml/issues/5). File-related functions and dynamic linking are not supported yet. |
63 |
| - |
64 |
| -## Compatibility with Js_of_ocaml |
65 |
| - |
66 |
| -Since the value representation is different, some adaptations are necessary. |
67 |
| - |
68 |
| -The most notable change is that, except for integers, OCaml numbers are no longer mapped to JavaScript numbers. So, explicit conversions `Js.to_float` and `Js.float` are now necessary to convert between OCaml floats and JavaScript numbers. The typing of JavaScript Typed Arrays has also been changed to deal with this. |
| 5 | +Wasm_of_ocaml has now been merged back with Js_of_ocaml, and further development will take place in the [Js_of_ocaml repository](https://github.com/ocsigen/js_of_ocaml). |
0 commit comments