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
configurescript to work:- Change the
cc_print_exprfunction to use a wasm runtime for the checks, e.g.node $TMP/print_expr > $TMP/print_expr.out - Change the
cc_or_diefunction by adding the 2 flags-sEXIT_RUNTIME -sFORCE_FILESYSTEMto the compilation
- Change the
./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
Dockerfileand add:- before the very first
RUNcommand:RUN echo https://dl-cdn.alpinelinux.org/alpine/edge/testing >> /etc/apk/repositories - add
oils-for-unixto the list of packages to be installed (I had to addmkinitfsto the install list as well)
- before the very first
- Run
./build.sh- this requires the pip package
zstandard
- this requires the pip package
- Afterwards, the directory
REPO/build/should exist with the relevant packages - edit the file
examples/alpine.htmland add the following to the string starting withcmdline;init=/usr/bin/ysh. This makes the VM start directly into ysh, making the startup much faster.ysheffectively becomesPID1. :) - 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.jsto store the bootup process and make the VM start in an instant