This project demonstrates how to build and run parallel compression using WebAssembly and wasi-threads. It compiles the pigz CLI tool to WebAssembly using a wasi-sdk release and runs it using a recent version of wasmtime (and optionally, wamr). At the moment, wasi-threads is still experimental; though its ABI is unstable, this demo motivates the need for spawning threads in WebAssembly.
git clone --recurse-submodules ...
The various source repositories are retrieved as Git submodules — these are all necessary for
the build to succeed. Also, this project expects some basic Linux tools (make
, wget
, git
,
tar
) as well as Rust. The specific Linux expectations are incidental to this sample code.
For MacOS, brew install wget gnu-tar
is necessary.
Contributions are welcome to make this sample work on other OSes.
make
This will build or retrieve all of the components necessary for running the parallel compression tool:
- wasi-sdk: an experimental release of the
wasi-sdk
toolchain with support for thewasm32-wasi-threads
target - zlib: the parallel compression library relies on this C library — we must build a WebAssembly version of it
- pigz: the parallel compression library
- wasmtime: a WebAssembly engine that implements wasi-threads
- WAMR: a WebAssembly engine that implements wasi-threads
make benchmark
Default platform is Linux, use make PLATFORM=macos
on MacOS.
Run parallel compression (by default, NUM_THREADS=1
) on a randomly-generated file.
make benchmark
command uses Wasmtime engine to run the benchmark. Use the following
command to build WASM micro runtime (for linux platform) and run benchmarks (in the fast
interpreter mode):
make benchmark.wamr
- add missing symbols to
wasi-libc
:chown
,chmod
,pthread_attr_setdetachstate
(and remove from pigz/patches)
This code sample is released under the MIT license. By contributing to the project, you agree to the license and copyright terms therein and release your contribution under these terms.