dylibso / hermit

Actually Portable WebAssembly compiler toolchain for self-contained cross-platform binaries
https://dylibso.com/blog/hermit-actually-portable-wasm/
Apache License 2.0
196 stars 11 forks source link
compiler container cosmopolitan-libc cross-platform wasm

Hermit - Actually Portable WebAssembly

Hermit

A toolkit for creating Actually Portable WASM Executables, called hermits. See blogpost.

Download

See releases.

Usage

./hermit.com [-f <path_to_Hermitfile>] [-o <output_path>]

If a path to a Hermitfile is not provided, it tries to load Hermitfile from the current directory. If an output_path is not provided, the hermit is written to wasm.com in the current directory. On Unix-like operating systems you must chmod +x wasm.com to make it executable. This is required because WASI does not have a chmod function.

Note: you may need to call hermit.com and its resulting hermits using sh as such:

sh ./hermit.com

On ARM / Apple Silicon:

arch -x86_64 ./uuid.com  

# or, possibly needed to run with `sh`:
arch -x86_64 sh ./uuid.com

On the .com extension...

Hermit takes advantage of the Cosmopoliltan Libc and produces multi-platform X86_64 binary executables (called αcτµαlly pδrταblε εxεcµταblε, or "APE"s for short). While Unix-like systems do not care about the extension, certain Windows environments require that an extension is used. Remove it if you'd like, but it must be present for the same executable to be run on Windows.

Hermitfile syntax

Supported:

Unimplemented:

Limitations

Building

Setup

  1. Clone with submodules so you get WAMR and the forked dockerfile-parser-rs (the hermitfile parser)

    git clone --recurse-submodules git@github.com:dylibso/hermit.git

  2. Bootstrap pest (dockerfile-parser-rs dependency):

    cd dockerfile-parser-rs/third-party/pest && cargo build --package pest_bootstrap

  3. Clone the Cosmopolitan libc and setup cosmocc as mentioned in Getting Started. If cosmocc isn't in your PATH after adding a new shell, maybe append to .bashrc instead.

Build

./build_hermit.sh configures and builds with cmake to the build dir.

Demo hermits

After building, try out:

./build/cowsay.hermit.com 'Hello, Dylibso!'

or

echo aeiou | ./build/count_vowels.hermit.com

Benchmarks

Community

Hermit shares the Extism Discord. Join #hermit to discuss working with or building Hermit.