WASI (Wasm di Server) — WebAssembly

WASI: WebAssembly di Luar Browser WASI (WebAssembly System Interface) memungkinkan Wasm berjalan di server, CLI, dan embedded systems — bukan hanya browser. WAS

WASI: WebAssembly di Luar Browser

WASI (WebAssembly System Interface) memungkinkan Wasm berjalan di server, CLI, dan embedded systems — bukan hanya browser. WASI menyediakan interface standar ke filesystem, network, clock, dan resource sistem lainnya.

Kenapa WASI?

Runtime: Wasmtime

# Install wasmtime
curl https://wasmtime.dev/install.sh -sSf | bash

# Rust → WASI
rustup target add wasm32-wasip1

# Compile
cargo build --target wasm32-wasip1 --release

# Jalankan
wasmtime target/wasm32-wasip1/release/myapp.wasm

# Dengan akses filesystem (sandboxed)
wasmtime --dir=./data target/wasm32-wasip1/release/myapp.wasm

Contoh: CLI Tool

// src/main.rs (target: wasm32-wasip1)
use std::env;
use std::fs;
use std::io::{self, BufRead};

fn main() {
    let args: Vec<String> = env::args().collect();

    if args.len() < 2 {
        eprintln!("Usage: wordcount <file>");
        std::process::exit(1);
    }

    let content = fs::read_to_string(&args[1])
        .expect("Cannot read file");

    let lines = content.lines().count();
    let words = content.split_whitespace().count();
    let chars = content.chars().count();

    println!("{} lines, {} words, {} chars", lines, words, chars);
}

WASI Preview

WASI vs Docker

Use Cases Server-Side

Yang akan kamu pelajari