Skip to content

arjunr2/WALI

Repository files navigation

Webassembly Linux Interface (WALI)

WebAssembly Linux Interface

A (Nearly-Complete) Linux API for WebAssembly!

This is a result of work published at EuroSys 2025 on Empowering WebAssembly with Thin Kernel Interfaces (arxiv version available here)

This repo contains all the compiler and engine prototypes for an implementation of the WebAssembly Linux Interface. A list of supported syscalls can be found here

Initial Setup

  1. Install dependencies with sudo ./apt-install-deps.sh or equivalent packages

  2. Setup toolchain configs: python3 toolchains/gen_toolchains.py

Component Setup

There are four major toolchain components, that may be incrementally built:

I just want to run WALI Wasm executables!:

  1. WALI Engine

I want to compile/build WALI executables!:

  1. WALI LLVM Toolchain
  2. WALI Sysroot

I want to AoT compile the Wasm executables to go fast!

  1. AoT Compiler

1. WALI Engine

We include a baseline implementation in WAMR. To build:

git submodule update --init wasm-micro-runtime
# Generates `iwasm` symlink in root directory
make iwasm

See examples/precompiled for runnable WALI binaries.

WASM as a Miscellaneous Binary Format!

WALI Wasm/AoT binaries can be executed like ELF files with iwasm (e.g. ./bash.wasm --norc). This is recommended since it simplifies execution and is necessary to build some applications out-of-the-box. To do this, run:

cd misc
source gen_iwasm_wrapper.sh
# Specify '-p' option to register with systemd-binfmt for reboot survival. Default binfmt_register does not survive system reboots
sudo ./binfmt_register.sh -p

For more info about miscellaneous binary formats and troubleshooting, see here

2. WALI LLVM Toolchain

git submodule update --init llvm-project
make wali-compiler

NOTE: Building the LLVM suite takes a long time and can consume up to 150GB of disk. The compiler is essential if you want to rebuild libc or build applications.

3. WALI Sysroot

git submodule update --init wali-musl
make libc

NOTE: Only the following 64-bit architectures are supported: x86-64, aarch64, riscv64. Future iterations will include a larger set of ISAs.

4. AoT Compiler

Generates faster ahead-of time compiled executables. For the WAMR implementation, build with:

make wamrc

The wamrc symlink can be used as follows:

# --enable-multi-thread flag is needed for thread support
wamrc --enable-multi-thread -o <destination-aot-file> <source-wasm-file>

Refer to WAMR compiler docs for more info.

Building WALI Applications

Setup appropriate toolchain files:

python3 toolchains/gen_toolchains.py

For additional information on using/customizing toolchains, see toolchains

Hello World

You can use the convenience bash script in the examples directory. For instance:

cd examples
./compile-wali-standalone.sh -o printf.wasm printf.c
# Run the binary. Can just run `printf.wasm` if miscellaneous binary format is setup
../iwasm printf.wasm

Tests

Run make tests. WALI executables are generated in tests/wasm

Compiler Ports

Rust

Note: Preliminary support for a wasm32-wali-linux-musl target has been upstreamed to rustc! Support for this target requires several ecosystem components to ratchet up to something usable long-term stability, and may hence currently be broken. Use the below out-of-tree build process for rustc if you need a stable target as a proof-of-concept.

We support a custom Rust compiler with a wasm32-wali-linux-musl target. Existing cargo and rustup are required for a successful build. To build rustc, run:

make rustc

This adds a new toolchain to rustup named wali with the new target. To compile applications:

cargo +wali build --target=wasm32-wali-linux-musl

Note: Many applications will currently require a custom libc to be patched into Cargo.toml for the out-of-tree build.

Project Motivation

The WALI for WebAssembly aims to push lightweight virtualization down to prevalent, low-level Linux applications. WALI adopts a layering approach to API design, allowing WASI (and other arbitrary Wasm APIs) to be virtualized over it, establishing infrastructure for Wasm both in research and industry.

Building and running Wasm binaries is now trivial with WALI, while improving ecosystem security by layering Wasm APIs

Resources

About

A low-level virtualization interface for Linux-based systems using WebAssembly

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published