Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mewz-project/wasker

WebAssembly AoT compiler for your favorite Operating System
https://github.com/mewz-project/wasker

compiler llvm rust wasm webassembly

Last synced: 2 months ago
JSON representation

WebAssembly AoT compiler for your favorite Operating System

Awesome Lists containing this project

README

        

[![CI](https://github.com/mewz-project/wasker/actions/workflows/ci.yaml/badge.svg)](https://github.com/mewz-project/wasker/actions/workflows/ci.yaml)

![Wasker_logo](./doc/assets/wasker.png "Wasker_logo")

# Wasker

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

![Wasker_architecture](./doc/assets/wasker_architecture.png "Wasker_architecture")

## 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!

![demo](./doc/assets/wasker.gif)

# Quick Start

## Step1: Install Wasker
```
curl -sSfL https://github.com/mewz-project/wasker/releases/download/v0.1.1/wasker-0.1.1-linux-$(uname -m)-gnu.tar.gz | tar -xzvC /usr/bin/ wasker
```

## Step2: Create Wasm binary
Create any Wasm binary.
### example1
Please refer [examples](./examples) for building Wasm from Rust and Go.

```
git clone https://github.com/mewz-project/wasker.git
cd examples/rust
rustup target add wasm32-wasi
cargo build --target wasm32-wasi
```
### example2
We also provide a pre-build simple Wasm binary.
```
git clone https://github.com/mewz-project/wasker.git
ls helloworld.wat
```

## Step3: Run Wasker to compile Wasm
### example1
```
$ 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
```

### example2
```
wasker helloworld.wat
```

## Step4: Run compiled Wasm

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](./examples/wasi-wrapper/c/wasi-wrapper-linux.c) of running Wasker output on Linux.

Link Wasker output and WASI wapper for Linux
```
gcc -no-pie ./examples/wasi-wrapper/c/wasi-wrapper-linux.c ./wasm.o -o hello
```

Run!!
```
./hello
```

Also please check [Mewz](https://github.com/Mewz-project/Mewz.git), a unikernel OS which has WASI interface.
ELF file generated by Wasker can be executed on Mewz without any modification.

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

## Option1 : Use Devcontainer
You can try Wasker on browser via Devcontainer.

## Option2 : Build from source

The `wasker` binary distributed in Quick Start is dynamically linked with GNU libc (support for musl is planned for the future).
If pre-build binaries don't work on your system, please build from source.

### Clone repository
```
git clone [email protected]:mewz-project/wasker.git
cd Wasker
```

### Install LLVM locally
The commands are a little different because you need an LLVM binary built for your architecture.
#### AMD64
```
mkdir -p dependencies/llvm
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0/clang+llvm-15.0.0-x86_64-linux-gnu-rhel-8.4.tar.xz -O /tmp/llvm-15.0.0.tar.xz
tar -xvf /tmp/llvm-15.0.0.tar.xz -C dependencies/llvm
export LLVM_SYS_150_PREFIX=$PWD/dependencies/llvm/clang+llvm-15.0.0-x86_64-linux-gnu-rhel-8.4
```

#### AArch64
```
mkdir -p dependencies/llvm
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.0/clang+llvm-15.0.0-aarch64-linux-gnu.tar.xz -O /tmp/llvm-15.0.0.tar.xz
tar -xvf /tmp/llvm-15.0.0.tar.xz -C dependencies/llvm
export LLVM_SYS_150_PREFIX=$PWD/dependencies/llvm/clang+llvm-15.0.0-aarch64-linux-gnu
```

### Run Wasker
```
cargo run helloworld.wat
```