Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vshymanskyy/wasm2native
Turn WASI apps into native executables
https://github.com/vshymanskyy/wasm2native
compiler toolchain wasi wasm wasm2c wasm2elf wasm2exe ziglang
Last synced: 3 months ago
JSON representation
Turn WASI apps into native executables
- Host: GitHub
- URL: https://github.com/vshymanskyy/wasm2native
- Owner: vshymanskyy
- License: mit
- Created: 2021-12-07T20:57:51.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-14T15:23:04.000Z (almost 3 years ago)
- Last Synced: 2024-10-01T03:22:13.285Z (4 months ago)
- Topics: compiler, toolchain, wasi, wasm, wasm2c, wasm2elf, wasm2exe, ziglang
- Language: C
- Homepage:
- Size: 4.21 MB
- Stars: 118
- Watchers: 11
- Forks: 6
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![SWUbanner](https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/banner-direct.svg)](https://vshymanskyy.github.io/StandWithUkraine)
# wasm2native
Turn WASI apps into native executables
## How it works
The approach is similar to [`WasmBoxC`](https://kripken.github.io/blog/wasm/2020/07/27/wasmboxc.html) or [`RLBox`](https://hacks.mozilla.org/2020/02/securing-firefox-with-webassembly/):
**`WASM file`** 🠖 `WASM to C translator` 🠖 `platform C compiler + libuvwasi + libuv` 🠖 **`native executable`**
## Prerequisites
- CMake
- Native toolchain (GCC/Clang/MSVC). Optional: [Zig](https://github.com/ziglang/zig/releases/latest)## Usage examples
```sh
# Single step:
export CC="clang-12"
export LDFLAGS="-fuse-ld=lld"
./build.sh ./examples/coremark.wasm# Cross-compile with Zig CC: x86_64-windows-gnu, x86_64-linux-gnu, x86_64-macos-gnu
CC="zig cc -target x86_64-linux-musl" ./build.sh ./examples/coremark.wasm# Cross-compilation to other architectures
# For full targets list: zig targets | jq .libc
CC="zig cc -target aarch64-linux-musl" ./build.sh ./examples/hello.wasm
qemu-aarch64-static hello.elf
Hello from WebAssembly!
```**Note:** this tool can be used for building `WASI` apps, not `emscripten`-generated `wasm+js` output.
## Coremark 1.0 results
Intel(R) Core(TM) i5-10400 CPU @ 2.90GHz, single-thread:
- Native: **32475**
- wasm2c: **27400** (84% of native)## TODO
- [ ] Big-endian target support
- [ ] Windows host support
- [ ] Convert main script to `zig`
- [ ] Allow setting `CFLAGS`, overriding optimization flags
- [ ] CI via Github Actions
- [ ] Get rid of mandatory CMake dependency (write build script for `libuv` and `uvwasi` for major platforms)### License
This project is released under The MIT License (MIT)