WASM Build - oils-for-unix/oils GitHub Wiki

WASM Build

Building Oils for WASM is an interesting thought.

Emscripten

Emscripten doesn't support fork(), therefore using a emscripten build is extremely limited (e.g. | doesn't work). A working emcc setup is expected and a runtime like node. the library libatomic1 is also required and might not be preinstalled.

  • Download the tarball
  • Fix the configure script to work:
    • Change the cc_print_expr function to use a wasm runtime for the checks, e.g. node $TMP/print_expr > $TMP/print_expr.out
    • Change the cc_or_die function by adding the 2 flags -sEXIT_RUNTIME -sFORCE_FILESYSTEM to the compilation
  • ./configure --cxx-for-configure em++
  • CXXFLAGS=-fexceptions _build/oils.sh --cxx em++
  • Ignore the error regarding strip.

Now it should be possible to run the following:

root@289ab6328d1a:/src/oils-for-unix-0.37.0# node _bin/em++-opt-sh/oils-for-unix ysh -c "= 5 + 5"
(Int)   10

There's still some work to do to run the html file (e.g. passing the proper arguments).

WASIX

I still haven't managed to get it to build with wasixcc, it fails on the link stage. :(

With emulation

Using copy/v86 works, despite being rather slow to start; See the Demo or follow these instructions;

  • clone the repo and go to REPO/tools/docker/alpine
  • Edit the Dockerfile and add:
    • before the very first RUN command: RUN echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories
    • add oils-for-unix to the list of packages to be installed (I had to add mkinitfs to the install list as well)
  • Run ./build.sh
    • this requires the pip package zstandard
  • Afterwards, the directory REPO/build/ should exist with the relevant packages
  • edit the file examples/alpine.html and add the following to the string starting with cmdline; init=/usr/bin/ysh. This makes the VM start directly into ysh, making the startup much faster. ysh effectively becomes PID1. :)
  • in the root of the repository, run make run, then open the following URL: http://localhost:8000/examples/alpine.html
  • After the boot finishes; it's possible to run ysh, see screenshot below.

TODOs:

  • Use build-state.js to store the bootup process and make the VM start in an instant