{"id":13494701,"url":"https://github.com/ocaml-wasm/wasm_of_ocaml","last_synced_at":"2025-03-28T14:31:50.469Z","repository":{"id":183442823,"uuid":"620341986","full_name":"ocaml-wasm/wasm_of_ocaml","owner":"ocaml-wasm","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-29T11:52:07.000Z","size":23239,"stargazers_count":244,"open_issues_count":28,"forks_count":9,"subscribers_count":13,"default_branch":"main","last_synced_at":"2024-10-29T12:16:25.163Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ocaml-wasm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-03-28T13:49:04.000Z","updated_at":"2024-10-29T11:52:09.000Z","dependencies_parsed_at":"2023-07-24T13:54:40.075Z","dependency_job_id":"eea8683c-3657-4f53-a205-f385f85f6243","html_url":"https://github.com/ocaml-wasm/wasm_of_ocaml","commit_stats":null,"previous_names":["ocaml-wasm/wasm_of_ocaml"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocaml-wasm%2Fwasm_of_ocaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocaml-wasm%2Fwasm_of_ocaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocaml-wasm%2Fwasm_of_ocaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ocaml-wasm%2Fwasm_of_ocaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ocaml-wasm","download_url":"https://codeload.github.com/ocaml-wasm/wasm_of_ocaml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246046068,"owners_count":20714895,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T19:01:27.356Z","updated_at":"2025-03-28T14:31:45.441Z","avatar_url":"https://github.com/ocaml-wasm.png","language":"OCaml","funding_links":[],"categories":["OCaml"],"sub_categories":[],"readme":"# Wasm_of_ocaml\n\nWasm_of_ocaml is a fork of Js_of_ocaml which compiles OCaml bytecode to WebAssembly.\n\n## Requirements\n\nWasm_of_ocaml relies on the Binaryen toolchain; currently, only versions [118](https://github.com/WebAssembly/binaryen/releases/tag/version_118) or greater are supported. Binaryen commands must be in the PATH for wasm_of_ocaml to function.\n\n## Supported engines\n\nThe generated code works with Chrome 11.9, Node.js 22 and Firefox 122 (or more recent versions of these applications).\n\nIn particular, the output code requires the following [Wasm extensions](https://webassembly.org/roadmap/) to run:\n- [the GC extension](https://github.com/WebAssembly/gc), including functional references and 31-bit integers\n- [the tail-call extension](https://github.com/WebAssembly/tail-call/blob/main/proposals/tail-call/Overview.md)\n- [the exception handling extension](https://github.com/WebAssembly/exception-handling/blob/master/proposals/exception-handling/Exceptions.md)\n\nOCaml 5.x code using effect handlers can be compiled in two different ways:\nOne can enable the CPS transformation from `js_of_ocaml` by passing the\n`--enable=effects` flag. Without the flag `wasm_of_ocaml` will instead emit code\nutilizing\n- [the JavaScript-Promise Integration extension](https://github.com/WebAssembly/js-promise-integration/blob/main/proposals/js-promise-integration/Overview.md)\n\n\n## Installation\n\nThe following commands will perform a minimal installation:\n```\ngit clone https://github.com/ocaml-wasm/wasm_of_ocaml\ncd wasm_of_ocaml\nopam pin add dune.3.13 https://github.com/ocaml-wasm/dune.git#wasm\nopam pin add -n --with-version 5.3.0-wasm .\nopam install wasm_of_ocaml-compiler\n```\nYou may want to install additional packages. For instance:\n\n```\nopam install js_of_ocaml-ppx js_of_ocaml-lwt\n```\n\n## Usage\n\nYou 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.\n\n```\nocamlfind ocamlc -package js_of_ocaml,js_of_ocaml-ppx,js_of_ocaml-lwt -linkpkg -o cubes.byte cubes.mli cubes.ml\n```\n\nThen, run the `wasm_of_ocaml` compiler to produce WebAssembly code:\n\n```\nwasm_of_ocaml cubes.byte\n```\n\nThis 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:\n```\npython3 -m http.server 8000 --directory .\n```\n\nAs 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:\n```\nwasm_of_ocaml _build/default/bin/web/index.bc-for-jsoo\n```\n\n## Implementation status\n\nA 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.\n\nSeparate compilation is not implemented yet.\n\n## Compatibility with Js_of_ocaml\n\nSince the value representation is different, some adaptations are necessary.\n\nThe 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.\n\nAdditionally, OCaml physical equality will not work properly on JavaScript objects (it compares boxed values instead of values themselves). You should use `Js.string_equals` instead.\n\nSome forked versions of [Brr](https://github.com/ocaml-wasm/brr/tree/wasm) and\n[Gen_js_api](https://github.com/ocaml-wasm/gen_js_api/tree/wasm) are compatible with Wasm_of_ocaml.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focaml-wasm%2Fwasm_of_ocaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Focaml-wasm%2Fwasm_of_ocaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Focaml-wasm%2Fwasm_of_ocaml/lists"}