Skip to content

0.5.0

Choose a tag to compare

@rboudrouss rboudrouss released this 03 Nov 11:20
· 208 commits to main since this release

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 (or threads: yes in ocaml-emcc.conf),
    Thread.create starts a real thread and, with OCaml 5.3 or later,
    Domain.spawn a 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, and Lwt_preemptive works, as
    does Async's In_thread.run (core_unix's prctl names 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 (or wasix: yes in ocaml-emcc.conf for
    --wasi) makes a module for wasmer (wasmer run --net) with WASIX's
    sockets: Unix.socket, connect, bind, listen, accept, options,
    addresses, UDP, getaddrinfo and gethostbyname, and lwt's sockets,
    with or without threads. With --wasi alone, 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's Timezone.local reads: 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): poll with no timeout
    failed (emscripten's new probe, ENOSYS), as did fdatasync
    (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 (or Failure), Js.export gives functions to the
    page, and Sys_js redirects channels to functions and mounts files
    given on demand. Their stubs, which only abort, are no longer linked.
  • --js-file FILE (and js-files: in ocaml-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
    --dynlink loads with the new library ocaml-emcc.dynlink
    (Emcc_dynlink.loadfile, or load_url to fetch it in a web page),
    checking their interfaces as Dynlink does. 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 an Int63 as an
    int, where Base has an int64 on wasm32 (a crash in caml_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 -I of 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 .cmi and
    .cmt files (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),
    fchdir works, sendmsg and recvmsg are 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=1 rebuilds 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 raising Failure "NAME not implemented" when called, as with js_of_ocaml: link warns, and a
    program that never calls it runs. --no-missing-primitives makes 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: with MAXIMUM_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...; -Ofast becomes -O3 -ffast-math.
  • ocamlc -config in the wasm context reports architecture: 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:
    --release instead of -p PKG when 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's b0_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_setup configures 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.spawn already
    failed). It reserved at startup the minor heaps of 16 domains in wasm32
    and 128 in wasm64, which emscripten's mmap allocates 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=N still 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's ffi_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 (linking section, function
    types), no longer by parsing wasm-ld's warnings, whose wording could
    change with emsdk. link now 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 their build function; the recipe format and helpers
    are unchanged. Unit tests (dune test) cover the logic that moved.
  • dune-configurator runs pkg-config from a temporary
    directory, where the sysroot's wrapper took it for the host context: the
    wasm stubs got the host's C flags (gsl read its headers from
    /usr/include). The wrapper now goes by INSIDE_DUNE.
  • Compiled mode (experimental): with --compiled, build and link
    compile the bytecode to C with c_of_ocaml instead of interpreting it.
    Programs run 2 to 5 times faster in node, and their .wasm is 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 --compiled runs 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 native ocamlrun).
    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.
    Its setjmp, which wrapped each of its calls in an exception handler,
    moved to that caller (patches/4.x/ and patches/5.x/).
  • New recipe: raylib (raylib-ocaml). The raylib it vendors is built for
    raylib's PLATFORM_WEB (emscripten's GLFW, WebGL), linked with
    -sASYNCIFY so that the usual while not (window_should_close ())
    loop runs in a browser (-- -sJSPI replaces 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>.so of 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 .cmi files (raylib) was
    reported as failed: find | grep -q, under pipefail, failed when
    find was killed by SIGPIPE. The same in the check for wasm archives.
  • -cclib "-l X" is read as -lX.