Wasm: Emscripten vs WASI-SDK: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 30: | Line 30: | ||
* hello.js | * hello.js | ||
* hello.wasm | * hello.wasm | ||
== WASI-SDK == | |||
ada beberapa cara install WASI-SDK: | |||
* build manual: tidak disarankan, butuh komputasi berat | |||
* download tar.gz: download dari https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-29, ekstrak ke <code>/opt</code> atau ke tempat lain | |||
* The Arch Linux Way: <code>paru -S wasi-sdk-bin</code> | |||
<i>saya pakai cara yang ketiga</i> | |||
Setalah itu install <i>wasmtime</i>, ini adalah runtime untuk menjalankan file <code>.wasm</code> <br> | |||
Ada dua cara: | |||
* cara official: <code>curl https://wasmtime.dev/install.sh -sSf | bash</code> | |||
* The Arch Linux Way: <code>sudo pacman -S wasmtime</code> | |||
Revision as of 11:42, 26 November 2025
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
WASI-SDK
ada beberapa cara install WASI-SDK:
- build manual: tidak disarankan, butuh komputasi berat
- download tar.gz: download dari https://github.com/WebAssembly/wasi-sdk/releases/tag/wasi-sdk-29, ekstrak ke
/optatau ke tempat lain - The Arch Linux Way:
paru -S wasi-sdk-bin
saya pakai cara yang ketiga
Setalah itu install wasmtime, ini adalah runtime untuk menjalankan file .wasm
Ada dua cara:
- cara official:
curl https://wasmtime.dev/install.sh -sSf | bash - The Arch Linux Way:
sudo pacman -S wasmtime