Jump to content

Wasm: Emscripten vs WASI-SDK

From Haidhi Wiki
Revision as of 11:42, 26 November 2025 by SanzSkuy (talk | contribs)

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:

saya pakai cara yang ketiga

Setalah itu install wasmtime, ini adalah runtime untuk menjalankan file .wasm
Ada dua cara: