Skip to content

Wasm support#852

Draft
balat wants to merge 1 commit intomasterfrom
wasm
Draft

Wasm support#852
balat wants to merge 1 commit intomasterfrom
wasm

Conversation

@balat
Copy link
Member

@balat balat commented Jan 29, 2026

Add wasm support.
It is activated by default, but there is an Eliom option to deactivate it.
If activated, eliom includes a small inline script that will detect if the browser is compatible and load the right file.
Templates have benn updated to compile the wasm version.

@vouillon This is ready to review but cannot be merged until ocsigen/js_of_ocaml#2151 is released
See also ocsigen/ocsigen-start#699

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds WebAssembly (WASM) support to Eliom, allowing client code to be compiled to WASM as an alternative to JavaScript. The feature is enabled by default but can be disabled via configuration.

Changes:

  • Added WASM compilation support with automatic browser detection that loads WASM when supported, falling back to JavaScript
  • Extended Eliom configuration system with enable_wasm option and related API functions
  • Updated build templates (app.lib, app.exe) to compile and deploy both JS and WASM versions with dune 3.17+

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
src/lib/eliom_registration.server.ml Added wasm_detection_script function that generates inline JavaScript to detect WebAssembly support and load the appropriate file
src/lib/eliom_common.server.ml/mli Added enable_wasm field to sitedata record
src/lib/server/eliommod.ml/mli Added default_enable_wasm configuration, XML parsing for wasm tag, and integration into parse_eliom_option(s)
src/lib/eliom_config.server.ml/mli Added set_enable_wasm and get_enable_wasm API functions
src/lib/eliom.server.ml/mli Added enable_wasm parameter to run function with documentation
pkg/distillery/templates/app.lib/dune Added wasm mode to executables and wasm_of_ocaml configuration
pkg/distillery/templates/app.lib/dune-project Bumped dune version from 3.14 to 3.17 for wasm support
pkg/distillery/templates/app.lib/Makefile.app Added WASM build targets and installation steps with conditional ENABLE_WASM checks
pkg/distillery/templates/app.lib/Makefile.options Added ENABLE_WASM configuration option
pkg/distillery/templates/app.exe/* Similar changes as app.lib template
pkg/distillery/templates/basic.ppx/Makefile Added note that WASM is not supported in this legacy template
pkg/distillery/templates/basic.ppx/Makefile.options Added ENABLE_WASM option (though unused in this template)
dune-project, eliom.opam Added wasm_of_ocaml-compiler dependency
src/ppx/ppx_eliom_utils.ml Added optional loc parameter to type_of_out_type and related functions for better location tracking, plus OCaml 5.3.0 compatibility adjustments

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

in
let script_content =
Printf.sprintf
"(function() {\n\ var script = document.createElement('script');\n\ script.defer = %s;\n\ script.async = %s;\n\ \n\ if (typeof WebAssembly === 'object' && \n\ typeof WebAssembly.instantiate === 'function') {\n\ script.src = '%s';\n\ } else {\n\ script.src = '%s';\n\ }\n\ \n\ document.head.appendChild(script);\n})();"
Copy link
Member

Choose a reason for hiding this comment

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

if (window?.WebAssembly?.JSTag) { ... } else { ... }

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