#wasm-binary #elf #wasi #compiler #compile #favorite #running

bin+lib wasker

Wasm compiler for running Wasm on your favorite kernel

2 releases

0.1.1 Mar 20, 2024
0.1.0 Feb 19, 2024

#8 in #favorite

Download history 128/week @ 2024-02-19 20/week @ 2024-02-26 1/week @ 2024-03-04 171/week @ 2024-03-18 35/week @ 2024-04-01

207 downloads per month

MIT license

1MB
28K SLoC

WebAssembly 24K SLoC Rust 3.5K SLoC // 0.1% comments

Wasker

Wasker is a WebAssembly compiler. Wasker compiles Wasm binary into ELF format binary.  Currently, Wasker supports WASI preview 1.

What's new with Wasker

There are already software tools that compile Wasm to native binaries.

What's new with Wasker is, Wasker generates an OS-independent ELF file where WASI calls from Wasm applications remain unresolved.

This unresolved feature allows Wasker's output ELF file to be linked with WASI implementations provided by various operating systems, enabling each OS to execute Wasm applications.

Wasker empowers your favorite OS to serve as a Wasm runtime!

Installation

Wasker compiler is based on LLVM (LLVM 15 currently).

Suppose cargo is installed.

export LLVM_SYS_150_PREFIX=~/.wasker/clang+llvm-15.0.0-x86_64-linux-gnu-rhel-8.4/
cargo install wasker

Run Wasker

Step1: Prepare Wasm binary

Please refer examples for building Wasm from Rust and Go.

cd examples/rust
rustup target add wasm32-wasi
cargo build --target wasm32-wasi

Step2: Run Wasker

$ wasker examples/rust/target/wasm32-wasi/debug/rust.wasm
[2024-03-19T12:10:20Z INFO  wasker::compiler] input: examples/rust/target/wasm32-wasi/debug/rust.wasm
[2024-03-19T12:10:20Z INFO  wasker::compiler] write to ./wasm.ll
[2024-03-19T12:10:20Z INFO  wasker::compiler] write to ./wasm.o, it may take a while
[2024-03-19T12:10:21Z INFO  wasker::compiler] Compile success

Step3: Run wasker output on Linux

ELF file generated by Wasker is OS-independent: WASI calls from Wasm applications remain unresolved.

Please write your own WASI wrapper for your favorite OS to be linked with Wasker output.

Here, we'll show a tiny example of running Wasker output on Linux.

Compile WASI wapper for Linux and ink with Wasker output.

gcc -no-pie ./examples/wasi-wrapper/wasi-wrapper-linux.c ./wasm.o -o hello

Run!!

./hello

Also please check Mewz, a unikernel OS which has WASI interface. ELF file generated by Wasker can be executed on Mewz without any modification.

Development

Option1 : Use Devcontainer

You can try Wasker via Devcontainer.

Option2 : Build from source

git clone git@github.com:mewz-project/wasker.git
cd Wasker
export LLVM_SYS_150_PREFIX=~/.wasker/clang+llvm-15.0.0-x86_64-linux-gnu-rhel-8.4/
cargo install wasker

By default, Wasker targets x86_64. If you want to target AArch64, please rewrite build.rs and override LLVM_SYS_150_PREFIX environment variable as follows.

# build.rs
5: let target = format!("clang+llvm-{}-aarch64-linux-gnu-rhel-8.4", llvm_version);

# shell
export LLVM_SYS_150_PREFIX=~/.wasker/clang+llvm-15.0.0-aarch64-linux-gnu/

Dependencies

~27–37MB
~546K SLoC