Skip to content

Some example scripts for building a parallel compression/decompression tool for WebAssembly

License

Notifications You must be signed in to change notification settings

midokura/wasm-parallel-gzip

 
 

Repository files navigation

wasm-parallel-gzip

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.

Prerequisites

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.

Build

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 the wasm32-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

Run

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.

Running benchmarks using WASM micro runtime

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

TODO

  • add missing symbols to wasi-libc: chown, chmod, pthread_attr_setdetachstate (and remove from pigz/patches)

License

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.

About

Some example scripts for building a parallel compression/decompression tool for WebAssembly

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Makefile 64.6%
  • C 35.4%