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)
{
puts("Hello");
return 0;
}
Download WASI SDK:
curl -LO https://github.com/CraneStation/wasi-sdk/releases/download/wasi-sdk-5/wasi-sdk-5.0-linux.tar.gz
Decompress and extract archive:
tar -xzf wasi-sdk-5.0-linux.tar.gz
Compile:
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 \
example.c