Repository navigation
0.5.0
Existing runtimes must be built again with ocaml-emcc setup --force (zstd with OCaml 5.1 and later, wasm32's minor heap, OCaml 5's single domain); recipes and stubs are rebuilt by themselves.
- Threads: with
--threads(orthreads: yesinocaml-emcc.conf),
Thread.createstarts a real thread and, with OCaml 5.3 or later,
Domain.spawna domain running in parallel, in node, browsers
(cross-origin isolated pages) and WASI hosts with wasi-threads (wasmer,
wasmtime up to 46), interpreted or compiled (with c_of_ocaml's support).
lwt then runs its jobs in its threads, andLwt_preemptiveworks, as
does Async'sIn_thread.run(core_unix'sprctlnames threads). The C code of the runtime, recipes
and stubs is now compiled with-pthread(programs without--threads
stay single-threaded) and-fPIC(for plugins, at no measured cost):
existing runtimes and recipes are built again.
The mpfr, libssl, libevent, pixman and fontconfig recipes are
thread-safe, liblo has its server thread. - Sockets with WASI:
--wasix(orwasix: yesinocaml-emcc.conffor
--wasi) makes a module for wasmer (wasmer run --net) with WASIX's
sockets:Unix.socket,connect,bind,listen,accept, options,
addresses, UDP,getaddrinfoandgethostbyname, and lwt's sockets,
with or without threads. With--wasialone, the program accepts
connections on the sockets its host preopens (wasmtime 46:
-S preview2=n -S tcplisten=ADDR), the descriptors after the standard
streams. - The local time zone has its file,
/etc/localtime, also under its name
in/usr/share/zoneinfo, which core'sTimezone.localreads: under node
the host's (and that of$TZ), in browsers one made from the browser's
time zone (its offsets from 1970 to 2037). It was missing, outside
--node-fs. --wasi: an absolute symbolic link is followed through the preopened
directories (/etc/localtime), which WASI hosts refuse to do.--wasi: lwt works (Lwt_unix,Lwt_io):pollwith no timeout
failed (emscripten's new probe,ENOSYS), as didfdatasync
(imported from JavaScript) and, with node's WASI, waiting for a file.- js_of_ocaml's JavaScript primitives: programs using the libraries
js_of_ocaml (Js,Dom_html, its ppx, js_of_ocaml-lwt, Brr...) run in
browsers and node, interpreted or compiled, on both targets, with the
conventions of wasm_of_ocaml for JavaScript values. Callbacks keep
running after the main program, JavaScript exceptions are
Js_error.Exn(orFailure),Js.exportgives functions to the
page, andSys_jsredirects channels to functions and mounts files
given on demand. Their stubs, which only abort, are no longer linked. --js-file FILE(andjs-files:inocaml-emcc.conf): primitives of
the program implemented in JavaScript, called with JavaScript values.- Plugins, in compiled mode:
ocaml-emcc plugin LIB.cma -o LIB.wasm
compiles a library to a wasm side module, which a program linked with
--dynlinkloads with the new libraryocaml-emcc.dynlink
(Emcc_dynlink.loadfile, orload_urlto fetch it in a web page),
checking their interfaces asDynlinkdoes. A plugin links the C
stubs of its library. Effect handlers with
--effects double-translation, which plugins built with--main
follow. - Added recipes: async_ssl, async_unix, bls12-381-unix, bytesrw, cairo,
class_group_vdf, core_unix, cpu, eio_posix, faad, ffmpeg, freetype,
frei0r, gd, glfw3, hacl_func, lacaml, lame, libev, libevent,
libfontconfig, libjpeg, liblo, liblzo2, libogg, libopus, libpng, libssl,
mad, memcpy, miou, mirage-block-unix, ncurses, nlopt, num, oniguruma,
openblas, osdp, pixman, poll, rowex, scrypt, secp256k1, setcore, shine.
zlib installs its pkg-config file and comes from its GitHub releases
(zlib.net fails at times), gmp installs its C++ interface (gmpxx). - Jane Street's libraries on wasm32: jst-config, the libraries reading its
configuration (time_now, core, core_unix) and those compiled against an
interface that differs there (the async stack) are rebuilt for the
target, as ctypes users are. Their 64-bit code treated anInt63as an
int, where Base has anint64on wasm32 (a crash incaml_int64_div
in async). The configuration is the host's but for the word size and
endianness. core and async run on wasm32, interpreted or compiled, in
node and with--wasi. Without threads, Async's thread pool runs its
jobs synchronously (async_unix recipe), as lwt does. - dune-configurator's C tests in the wasm context read the runtime's
caml/config.h, not the host's (its-Iof the host's standard library
is replaced). - OCaml 5.1 and later: the runtime is built with zstd when the switch's
compiler is, and can read compressed marshalled data: the.cmiand
.cmtfiles (ocamlc.byte, merlin, odoc, toplevels failed with
"Corrupted compiled interface") and compiler-libs'Compression.
Existing runtimes:ocaml-emcc setup --force. - wasm32: the minor heap is 1M words (4 MB) by default instead of 256k
(1 MB, half a 64-bit native program's): programs allocating much spent
their time in minor collections (binary_trees compiled: 1.26 s, now
1.01 s; a list pipeline: 0.80 s, now 0.44 s), for 3 ms and 3 MB more at
startup.OCAMLRUNPARAM=s=...still sets it; wasm64 is unchanged.
Existing runtimes:ocaml-emcc setup --force. --wasi: pipes are buffers in memory (Async's and lwt's wake-up pipes),
fchdirworks,sendmsgandrecvmsgare no longer imported from
JavaScript, and a standard stream the host reports as a socket is a FIFO
(node's piped standard streams).- Recipes:
PATCH_OCAML=1rebuilds the OCaml libraries of the package of an
opam:recipe for the target with its patches. These patches are also
applied to the builds for the target of ctypes users and Jane Street's
libraries (core_unix's C stubs), whose stamps record them. - A primitive that no linked library defines (a stub written for one OS
only: epoll, Windows...) becomes a stub raisingFailure "NAME not implemented"when called, as with js_of_ocaml:linkwarns, and a
program that never calls it runs.--no-missing-primitivesmakes it a
link error, as before. - Compiled mode: the generated C is split in parts (
c_of_ocaml --split),
compiled separately, and a part left unchanged is not compiled again. - The heap is sized with
-sINITIAL_HEAP(emscripten 3.1.55 and later)
unless the user's flags size the memory: withMAXIMUM_MEMORY, the
initial memory was fixed at 16 MB, which the static data alone can exceed
(72 MB of embedded bytecode for core with-linkall). - The C compiler wrapper drops
-march,-mtune,-mcpu,-fopenmp
(emscripten's OpenMP needs threads: the code runs serially) and the
host's-I/usr/include...;-Ofastbecomes-O3 -ffast-math. ocamlc -configin the wasm context reportsarchitecture: none: stubs
choosing their C code with%{architecture}take the portable one (num's
bng, without amd64 assembly).- A package that does not lay C types out is rebuilt for the target only if
an interface it was compiled against differs there: otherwise its build
was inconsistent with the packages depending on it (frama-c's plugins).
One already built is only built again if one of its dependencies was
rebuilt, and one depending on no root (ctypes, jst-config) is checked
without fetching its sources. - The stubs of a dune package are built with what its opam build selects:
--releaseinstead of-p PKGwhen it builds the whole tree (frama-c's
plugins, which are other packages). - Stubs found without a recipe nor dune: a C file including the OCaml
headers through a local header counts (b0'sb0_stubs.h), those of the
library are preferred when the package has several (bytesrw), and
without the native archive the files that do not compile are left out. - Recipes:
meson_setupconfigures a meson project for the target (cross
file, static libraries, the sysroot's pkg-config files). - OCaml 5: the runtime has a single domain (
Domain.spawnalready
failed). It reserved at startup the minor heaps of 16 domains in wasm32
and 128 in wasm64, which emscripten'smmapallocates and clears: a
hello world now starts with 16 MB of wasm memory instead of 29 MB
(wasm32) and 317 MB (wasm64), and ~10 ms (wasm32) and ~130 ms (wasm64)
sooner.OCAMLRUNPARAM=d=Nstill sets it (5.3 and later). Existing
runtimes:ocaml-emcc setup --force. - The stubs built with dune or from a package's native build, and the
packages rebuilt for ctypes, record the version of the toolchain's
wrappers in their stamps: a fix of the wrappers builds them again.
Those built before the pkg-config fix below had the host's C flags
(ctypes-foreign's wasm64 stubs: the host'sffi_cif, 8 bytes too
small, and calls failing with "Unexpected type 0"). - The stubs whose C signature differs from their OCaml arity are found by
reading the wasm objects of the libraries (linkingsection, function
types), no longer by parsing wasm-ld's warnings, whose wording could
change with emsdk.linknow links once instead of twice when stubs
need adapters. - What the recipe driver decided moved from bash to OCaml: which recipes
to build (stamps,DEPENDS), their sources (opam, tarballs, git, system
libraries), the C stubs of opam packages (dune, native build, blind),
the builds for the target of ctypes users, the patched dune and the
toolchain's wrappers.share/driver.sh(1084 lines, now 339) reads
recipes and runs theirbuildfunction; the recipe format and helpers
are unchanged. Unit tests (dune test) cover the logic that moved. - dune-configurator runs
pkg-configfrom a temporary
directory, where the sysroot's wrapper took it for the host context: the
wasm stubs got the host's C flags (gslread its headers from
/usr/include). The wrapper now goes byINSIDE_DUNE. - Compiled mode (experimental): with
--compiled,buildandlink
compile the bytecode to C with c_of_ocaml instead of interpreting it.
Programs run 2 to 5 times faster in node, and their.wasmis 2 to 8
times smaller. It works with OCaml 4.14 and 5, on wasm32 and wasm64,
effect handlers included. The stubs get the same signature adapters as
with the interpreter.tests/run.sh --compiledruns the tests in this
mode. - The bytecode interpreter runs about twice as fast in node and browsers
(fib: 52.7 s before, 23.9 s after, 15.8 s for the nativeocamlrun).
V8 optimizes a wasm function for its next calls only, so the
interpreter, called once for the whole program, stayed in the baseline
tier: it now returns to its caller every 2^20 polls and is called again.
Itssetjmp, which wrapped each of its calls in an exception handler,
moved to that caller (patches/4.x/andpatches/5.x/). - New recipe:
raylib(raylib-ocaml). The raylib it vendors is built for
raylib'sPLATFORM_WEB(emscripten's GLFW, WebGL), linked with
-sASYNCIFYso that the usualwhile not (window_should_close ())
loop runs in a browser (-- -sJSPIreplaces it). Test:raylib.
raylib-ocaml's master after 2.3.0 builds it for the web itself: the
recipe's patch for it only applies to the releases before, and now
builds from fresh sources too (it ran host helpers it did not depend on). - The placeholder
dll<name>.soof a wasm stub archive defines its C
functions (aborting if called): a (ctypes) generator linked against a
library of its package with stubs could not start ("unknown C
primitive"). - The shadow build of a package installing many
.cmifiles (raylib) was
reported as failed:find | grep -q, underpipefail, failed when
findwas killed by SIGPIPE. The same in the check for wasm archives. -cclib "-l X"is read as-lX.