Wasm: Emscripten vs WASI-SDK: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 10: | Line 10: | ||
export PATH="/usr/lib/emscripten/":$PATH | export PATH="/usr/lib/emscripten/":$PATH | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Sekarang buat code C++ simple | |||
<syntaxhighlight lang=cpp> | |||
// hello.cpp | |||
#include <stdio.h> | |||
int main() { | |||
printf("Hello World\n"); | |||
return 0; | |||
} | |||
</syntaxhighlight> | |||
lalu compile dengan perintah <code>emcc</code> | |||
<syntaxhighlight lang=bash> | |||
emcc hello.cpp -o hello.html | |||
</syntaxhighlight> | |||
Maka secara otomatis <code>emcc</code> akan menghasilkan tiga file yaitu: | |||
* hello.html | |||
* hello.js | |||
* hello.wasm | |||
Revision as of 09:55, 25 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