Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ The client-side code is compiled to JS using Ocsigen Js_of_ocaml or to Wasm usin
ppx_deriving
(ppxlib (>= 0.15))
(js_of_ocaml-compiler (>= 6.0))
wasm_of_ocaml-compiler
(js_of_ocaml (>= 6.0))
(js_of_ocaml-lwt (>= 6.0))
(js_of_ocaml-ocamlbuild :build)
Expand Down
1 change: 1 addition & 0 deletions eliom.opam
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ depends: [
"ppx_deriving"
"ppxlib" {>= "0.15"}
"js_of_ocaml-compiler" {>= "6.0"}
"wasm_of_ocaml-compiler"
"js_of_ocaml" {>= "6.0"}
"js_of_ocaml-lwt" {>= "6.0"}
"js_of_ocaml-ocamlbuild" {build}
Expand Down
20 changes: 20 additions & 0 deletions pkg/distillery/templates/app.exe/Makefile.app
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ install.static: $(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js | $(PREFIX)$(
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(JS_PREFIX)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR) && \
ln -sf $(PROJECT_NAME)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js
ifeq ($(ENABLE_WASM),yes)
HASH_WASM=`md5sum _build/default/client/$(PROJECT_NAME).bc.wasm.js | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(JS_PREFIX)_$$HASH_WASM.wasm.js $(PREFIX)$(ELIOMSTATICDIR) && \
ln -sf $(PROJECT_NAME)_$$HASH_WASM.wasm.js $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).wasm.js
if [ -d _build/default/client/$(PROJECT_NAME).bc.wasm.assets ]; then \
cp -rf _build/default/client/$(PROJECT_NAME).bc.wasm.assets $(PREFIX)$(ELIOMSTATICDIR)/; \
[ -z $(WWWUSER) ] || chown -R $(WWWUSER) $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).bc.wasm.assets; \
fi
endif
[ -z $(WWWUSER) ] || chown -R $(WWWUSER) $(PREFIX)$(FILESDIR)

.PHONY:
Expand All @@ -91,13 +100,24 @@ config-files: | $(TEST_PREFIX)$(ELIOMSTATICDIR) $(TEST_PREFIX)$(LIBDIR)
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
cp -f _build/default/client/$(PROJECT_NAME).bc.js $(JS_PREFIX)_$$HASH.js && \
ln -sf $(PROJECT_NAME)_$$HASH.js $(JS_PREFIX).js
ifeq ($(ENABLE_WASM),yes)
HASH_WASM=`md5sum _build/default/client/$(PROJECT_NAME).bc.wasm.js | cut -d ' ' -f 1` && \
cp -f _build/default/client/$(PROJECT_NAME).bc.wasm.js $(JS_PREFIX)_$$HASH_WASM.wasm.js && \
ln -sf $(PROJECT_NAME)_$$HASH_WASM.wasm.js $(JS_PREFIX).wasm.js
if [ -d _build/default/client/$(PROJECT_NAME).bc.wasm.assets ]; then \
cp -rf _build/default/client/$(PROJECT_NAME).bc.wasm.assets $(TEST_PREFIX)$(ELIOMSTATICDIR)/; \
fi
endif
cp -f _build/default/$(PROJECT_NAME).cm* $(TEST_PREFIX)$(LIBDIR)/

all::
$(ENV_PSQL) dune build $(DUNE_OPTIONS) @install @$(PROJECT_NAME)

js::
$(ENV_PSQL) dune build $(DUNE_OPTIONS) client/$(PROJECT_NAME).bc.js
ifeq ($(ENABLE_WASM),yes)
$(ENV_PSQL) dune build $(DUNE_OPTIONS) client/$(PROJECT_NAME).bc.wasm.js
endif

byte:: js
$(ENV_PSQL) dune build $(DUNE_OPTIONS) $(PROJECT_NAME)_main.bc
Expand Down
3 changes: 3 additions & 0 deletions pkg/distillery/templates/app.exe/Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ CSS_PREFIX := $(LOCAL_STATIC_CSS)/${PROJECT_NAME}
# JavaScript, ocsigenserver
DEBUG := yes

# Enable WASM compilation (yes/no): Requires wasm_of_ocaml (enabled by default)
ENABLE_WASM := yes

##----------------------------------------------------------------------

6 changes: 5 additions & 1 deletion pkg/distillery/templates/app.exe/PROJECT_NAME.eliom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ let%server application_name = "%%%PROJECT_NAME%%%"
let%client application_name = Eliom_client.get_application_name ()

let%server () =
Ocsipersist_settings.set_db_file "local/var/data/%%%PROJECT_NAME%%%/%%%PROJECT_NAME%%%_db";
Ocsipersist_settings.set_db_file "local/var/data/%%%PROJECT_NAME%%%/%%%PROJECT_NAME%%%_db"
(* Enable WebAssembly support with automatic browser detection.
The server will load the WASM version if the browser supports it,
with fallback to JavaScript otherwise. *)
; Eliom_config.set_enable_wasm true

(* Create a module for the application. See
https://ocsigen.org/eliom/manual/clientserver-applications for more
Expand Down
9 changes: 5 additions & 4 deletions pkg/distillery/templates/app.exe/dune
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
client
(executables
(names %%%PROJECT_NAME%%%)
(modes js byte)
(modes js byte wasm)
(preprocess
(pps
js_of_ocaml-ppx
Expand All @@ -106,9 +106,9 @@
--enable
with-js-error
--enable
use-js-string
--no-source-map))
; source maps are slow...
use-js-string))
(wasm_of_ocaml
(flags :standard))
(libraries eliom.client))
(dynamic_include ../gen/dune.client))

Expand All @@ -122,6 +122,7 @@
%%%PROJECT_NAME%%%_main.exe
client/%%%PROJECT_NAME%%%.bc
client/%%%PROJECT_NAME%%%.bc.js
client/%%%PROJECT_NAME%%%.bc.wasm.js
tools/check_modules.ml)
(action
(run ocaml -I +unix -I +str tools/check_modules.ml %%%PROJECT_NAME%%%)))
11 changes: 7 additions & 4 deletions pkg/distillery/templates/app.exe/dune-project
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
(lang dune 3.14)
(lang dune 3.17)

(dialect
(name "eliom-server")
(implementation (extension "eliom"))
(interface (extension "eliomi")))
(implementation
(extension "eliom"))
(interface
(extension "eliomi")))

(wrapped_executables false)

(formatting (enabled_for ocaml "eliom-server"))
(formatting
(enabled_for ocaml "eliom-server"))
25 changes: 25 additions & 0 deletions pkg/distillery/templates/app.lib/Makefile.app
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ install.static: $(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js | $(PREFIX)$(
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(JS_PREFIX)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR) && \
ln -sf $(PROJECT_NAME)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js
ifeq ($(ENABLE_WASM),yes)
HASH_WASM=`md5sum _build/default/client/$(PROJECT_NAME).bc.wasm.js | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(JS_PREFIX)_$$HASH_WASM.wasm.js $(PREFIX)$(ELIOMSTATICDIR) && \
ln -sf $(PROJECT_NAME)_$$HASH_WASM.wasm.js $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).wasm.js
if [ -d _build/default/client/$(PROJECT_NAME).bc.wasm.assets ]; then \
cp -rf _build/default/client/$(PROJECT_NAME).bc.wasm.assets $(PREFIX)$(ELIOMSTATICDIR)/; \
[ -z $(WWWUSER) ] || chown -R $(WWWUSER) $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).bc.wasm.assets; \
fi
endif
[ -z $(WWWUSER) ] || chown -R $(WWWUSER) $(PREFIX)$(FILESDIR)
install.etc: $(TEST_PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf | $(PREFIX)$(ETCDIR)
install $< $(PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf
Expand Down Expand Up @@ -122,6 +131,11 @@ SED_ARGS += -e "s|%%FILESDIR%%|%%PREFIX%%$(FILESDIR)|g"
SED_ARGS += -e "s|%%ELIOMSTATICDIR%%|%%PREFIX%%$(ELIOMSTATICDIR)|g"
SED_ARGS += -e "s|%%APPNAME%%|$(shell basename `readlink $(JS_PREFIX).js` .js)|g"
SED_ARGS += -e "s|%%CSSNAME%%|$(shell readlink $(CSS_PREFIX).css)|g"
ifeq ($(ENABLE_WASM),yes)
SED_ARGS += -e "s|%%WASMATTR%%|wasm=\"$(shell basename `readlink $(JS_PREFIX).wasm.js` .wasm.js).wasm.js\"|g"
else
SED_ARGS += -e "s|%%WASMATTR%%||g"
endif
ifeq ($(DEBUG),yes)
SED_ARGS += -e "s|%%DEBUGMODE%%|\<debugmode /\>|g"
else
Expand Down Expand Up @@ -156,6 +170,14 @@ config-files: | $(TEST_PREFIX)$(ELIOMSTATICDIR) $(TEST_PREFIX)$(LIBDIR)
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
cp -f _build/default/client/$(PROJECT_NAME).bc.js $(JS_PREFIX)_$$HASH.js && \
ln -sf $(PROJECT_NAME)_$$HASH.js $(JS_PREFIX).js
ifeq ($(ENABLE_WASM),yes)
HASH_WASM=`md5sum _build/default/client/$(PROJECT_NAME).bc.wasm.js | cut -d ' ' -f 1` && \
cp -f _build/default/client/$(PROJECT_NAME).bc.wasm.js $(JS_PREFIX)_$$HASH_WASM.wasm.js && \
ln -sf $(PROJECT_NAME)_$$HASH_WASM.wasm.js $(JS_PREFIX).wasm.js
if [ -d _build/default/client/$(PROJECT_NAME).bc.wasm.assets ]; then \
cp -rf _build/default/client/$(PROJECT_NAME).bc.wasm.assets $(TEST_PREFIX)$(ELIOMSTATICDIR)/; \
fi
endif
cp -f _build/default/$(PROJECT_NAME).cm* $(TEST_PREFIX)$(LIBDIR)/
$(MAKE) $(CONFIG_FILES) $(TEST_CONFIG_FILES) PROJECT_NAME=$(PROJECT_NAME)

Expand All @@ -164,6 +186,9 @@ all::

js::
$(ENV_PSQL) dune build $(DUNE_OPTIONS) client/$(PROJECT_NAME).bc.js
ifeq ($(ENABLE_WASM),yes)
$(ENV_PSQL) dune build $(DUNE_OPTIONS) client/$(PROJECT_NAME).bc.wasm.js
endif

byte::
$(ENV_PSQL) dune build $(DUNE_OPTIONS) @$(PROJECT_NAME)
Expand Down
3 changes: 3 additions & 0 deletions pkg/distillery/templates/app.lib/Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ CSS_PREFIX := $(LOCAL_STATIC_CSS)/${PROJECT_NAME}
# JavaScript, ocsigenserver
DEBUG := yes

# Enable WASM compilation (yes/no): Requires wasm_of_ocaml (enabled by default)
ENABLE_WASM := yes

##----------------------------------------------------------------------

4 changes: 3 additions & 1 deletion pkg/distillery/templates/app.lib/PROJECT_NAME.conf.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
<extension findlib-package="eliom.server">
<!-- Ask Eliom to ignore UTM parameters and others: -->
<ignoredgetparams regexp="utm_[a-z]*|[a-z]*clid|li_fat_id"/>
<!-- Enable WebAssembly support with automatic browser detection: -->
<wasm enabled="true"/>
<!-- Uncomment if you are using https only and want secure cookies:
<securecookies value="true" />
-->
Expand All @@ -51,7 +53,7 @@
<static dir="%%FILESDIR%%" />
%%ELIOM_MODULES%%
<eliommodule module="%%LIBDIR%%/%%PROJECT_NAME%%.cma">
<app name="%%APPNAME%%" css="%%CSSNAME%%" />
<app name="%%APPNAME%%" css="%%CSSNAME%%" %%WASMATTR%% />
<avatars dir="%%FILESDIR%%/avatars" />
<os-db
host="%%DB_HOST%%"
Expand Down
9 changes: 5 additions & 4 deletions pkg/distillery/templates/app.lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
client
(executables
(names %%%PROJECT_NAME%%%)
(modes js byte)
(modes js byte wasm)
(preprocess
(pps
js_of_ocaml-ppx
Expand All @@ -77,9 +77,9 @@
--enable
with-js-error
--enable
use-js-string
--no-source-map))
; source maps are slow...
use-js-string))
(wasm_of_ocaml
(flags :standard))
(libraries eliom.client))
(dynamic_include ../gen/dune.client))

Expand All @@ -91,6 +91,7 @@
%%%PROJECT_NAME%%%.cma
client/%%%PROJECT_NAME%%%.bc
client/%%%PROJECT_NAME%%%.bc.js
client/%%%PROJECT_NAME%%%.bc.wasm.js
tools/check_modules.ml)
(action
(run ocaml -I +unix -I +str tools/check_modules.ml %%%PROJECT_NAME%%%)))
11 changes: 7 additions & 4 deletions pkg/distillery/templates/app.lib/dune-project
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
(lang dune 3.14)
(lang dune 3.17)

(dialect
(name "eliom-server")
(implementation (extension "eliom"))
(interface (extension "eliomi")))
(implementation
(extension "eliom"))
(interface
(extension "eliomi")))

(wrapped_executables false)

(formatting (enabled_for ocaml "eliom-server"))
(formatting
(enabled_for ocaml "eliom-server"))
3 changes: 3 additions & 0 deletions pkg/distillery/templates/basic.ppx/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@

# NOTE: WASM support is only available in modern templates (app.exe, app.lib)
# This legacy template (basic.ppx) does not support wasm_of_ocaml compilation
#
##----------------------------------------------------------------------
## DISCLAIMER
##
Expand Down
4 changes: 3 additions & 1 deletion src/lib/client/dune
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
(language c)
(names eliom_stubs))
(js_of_ocaml
(javascript_files eliom_client.js)))
(javascript_files eliom_client.js))
(wasm_of_ocaml
(wasm_files eliom_client.wat)))

(include dune.client)

Expand Down
4 changes: 4 additions & 0 deletions src/lib/eliom.server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let run
?max_anonymous_services_per_session
?secure_cookies
?application_script
?enable_wasm
?global_data_caching
?html_content_type
?ignored_get_params
Expand Down Expand Up @@ -74,6 +75,9 @@ let run
max_anonymous_services_per_session;
Option.iter (fun v -> sitedata.secure_cookies <- v) secure_cookies;
Option.iter (fun v -> sitedata.application_script <- v) application_script;
(* Always update enable_wasm: use provided value or current global default *)
sitedata.enable_wasm <-
Option.value enable_wasm ~default:!Eliommod.default_enable_wasm;
Option.iter (fun v -> sitedata.cache_global_data <- v) global_data_caching;
Option.iter (fun v -> sitedata.html_content_type <- Some v) html_content_type;
Option.iter
Expand Down
9 changes: 8 additions & 1 deletion src/lib/eliom.server.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ val run :
-> ?max_anonymous_services_per_session:int * bool
-> ?secure_cookies:bool
-> ?application_script:bool * bool
-> ?enable_wasm:bool
-> ?global_data_caching:(string list * int) option
-> ?html_content_type:string
-> ?ignored_get_params:string * Re.re
Expand All @@ -42,4 +43,10 @@ val run :
(** [run ?app ()] run Eliom application [app] under current site.
Use this to build a static executable without configuration file.
Default value of [?app] is [default_app_name].
Other optional values correspond to Eliom configuration for this site. *)
Other optional values correspond to Eliom configuration for this site.

When [?enable_wasm] is set to [true], the server will generate a detection
script that loads the WASM version of your client code if the browser
supports WebAssembly, with automatic fallback to JavaScript otherwise.
If not specified, the global default is used
(see {!Eliom_config.set_enable_wasm}), which is [false]. *)
3 changes: 2 additions & 1 deletion src/lib/eliom_common.server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ and sitedata =
; mutable ipv6mask : int option * bool
; mutable application_script : bool (* defer *) * bool
; (* async *)
mutable cache_global_data : (string list * int) option
mutable enable_wasm : bool
; mutable cache_global_data : (string list * int) option
; mutable html_content_type : string option
; mutable ignored_get_params : (string * Re.re) list
; mutable ignored_post_params : (string * Re.re) list
Expand Down
3 changes: 2 additions & 1 deletion src/lib/eliom_common.server.mli
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,8 @@ and sitedata =
; mutable ipv6mask : int option * bool
; mutable application_script : bool (* defer *) * bool
; (* async *)
mutable cache_global_data : (string list * int) option
mutable enable_wasm : bool
; mutable cache_global_data : (string list * int) option
; mutable html_content_type : string option
; mutable ignored_get_params : (string * Re.re) list
; mutable ignored_post_params : (string * Re.re) list
Expand Down
2 changes: 2 additions & 0 deletions src/lib/eliom_config.server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ let set_max_volatile_groups_per_site v =

let set_secure_cookies v = Eliommod.default_secure_cookies := v
let set_application_script v = Eliommod.default_application_script := v
let set_enable_wasm v = Eliommod.default_enable_wasm := v
let get_enable_wasm () = !Eliommod.default_enable_wasm
let set_cache_global_data v = Eliommod.default_cache_global_data := v
let set_html_content_type v = Eliommod.default_html_content_type := Some v

Expand Down
17 changes: 17 additions & 0 deletions src/lib/eliom_config.server.mli
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ val set_max_anonymous_services_per_session : int -> unit
val set_max_volatile_groups_per_site : int -> unit
val set_secure_cookies : bool -> unit
val set_application_script : bool * bool -> unit

val set_enable_wasm : bool -> unit
(** Enable or disable WebAssembly support with automatic browser detection.
When enabled, Eliom will generate a script that detects WebAssembly
support in the browser and loads either the WASM version (.wasm.js) or
the JavaScript fallback (.js) accordingly.

Disabled by default for backward compatibility. The Eliom templates
enable it explicitly.

This setting can be overridden per-site using the [~enable_wasm] parameter
of {!Eliom.run} or the [<wasm enabled="true|false"/>] tag in the
configuration file. *)

val get_enable_wasm : unit -> bool
(** Get the current global setting for WebAssembly support. *)

val set_cache_global_data : (Eliom_lib.Url.path * int) option -> unit
val set_html_content_type : string -> unit
val add_ignored_get_params : string * Re.re -> unit
Expand Down
Loading
Loading