Jump to content

Wasm: Emscripten vs WASI-SDK: Difference between revisions

From Haidhi Wiki
No edit summary
No edit summary
Line 1: Line 1:
WASI-SDK dan Emscripten adalah toolchain untuk compile C/C++ menjadi WebAssembly, tetapi targetnya berbeda:  
WASI-SDK dan Emscripten adalah toolchain untuk compile C/C++ menjadi WebAssembly, tetapi targetnya berbeda:  
* <b>WASI-SDK<b> untuk environment WASI (non-web)
* <b>WASI-SDK</b> untuk environment WASI (non-web)
* <b>Emscripten<b> untuk browser (web platform).
* <b>Emscripten</b> untuk browser (web platform).


== Emscripten ==
== Emscripten ==

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