Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Compiling C to WebAssembly using Clang/LLVM & WASI

Compiling C to WebAssembly using Clang/LLVM & WASI

These are my notes. See also “Compiling C to WebAssembly using clang/LLVM and WASI” by Frank Denis, which was my starting point.

Assume the following example program in a file called example.c:

#include <stdio.h>

int main(void)
    return 0;


Download WASI SDK:

curl -LO

Decompress and extract archive:

tar -xzf wasi-sdk-5.0-linux.tar.gz


wasi-sdk-5.0/opt/wasi-sdk/bin/clang \
    --target=wasm32-wasi \
    --sysroot wasi-sdk-5.0/opt/wasi-sdk/share/sysroot \
    -Os -s -o example.wasm \
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.