Wasm: Emscripten vs WASI-SDK
Appearance
WASI-SDK dan Emscripten adalah toolchain untuk compile C/C++ menjadi WebAssembly, tetapi targetnya berbeda:
- WASI-SDK untuk environment WASI (non-web)
- Emscripten untuk browser (web platform).
Emscripten
Cara install
*note: saya pakai Arch Linux
sudo pacman -S emscripten
export PATH="/usr/lib/emscripten/":$PATH
Sekarang buat code C++ simple
// hello.cpp
#include <stdio.h>
int main() {
printf("Hello World\n");
return 0;
}
lalu compile dengan perintah emcc
emcc hello.cpp -o hello.html
Maka secara otomatis emcc akan menghasilkan tiga file yaitu:
- hello.html
- hello.js
- hello.wasm