wasm

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

WebAssembly (WASM) — Component Model, WASI

WebAssembly (WASM) — 组件模型、WASI

WASM pour performance critique, polyglot runtime, edge computing.
WASM 适用于性能敏感场景、多语言运行时、边缘计算。

Use Cases

使用场景

Browser — Crypto, image (Figma, Google Earth)
Edge — Cloudflare Workers, Fastly
Server — Plugins sandboxés (Envoy)
Embedded — IoT, automotive
浏览器 — 加密运算、图像处理(Figma、Google Earth)
边缘 — Cloudflare Workers、Fastly
服务器 — 沙箱化插件(Envoy)
嵌入式 — IoT、汽车领域

Compilation

编译方案

Rust
wasm-pack
(~50KB, perf)
Go
GOOS=js GOARCH=wasm
(~2MB)
C/C++ — Emscripten (legacy)
AssemblyScript — TypeScript-like
Rust
wasm-pack
(约50KB,高性能)
Go
GOOS=js GOARCH=wasm
(约2MB)
C/C++ — Emscripten(传统方案)
AssemblyScript — 类TypeScript语法

Rust to WASM

Rust 转 WASM

rust
use wasm_bindgen::prelude::*;
#[wasm_bindgen] pub fn add(a: i32, b: i32) -> i32 { a + b }
bash
wasm-pack build --target web
javascript
import init, { add } from './pkg/wasm.js';
await init(); add(2, 3);
rust
use wasm_bindgen::prelude::*;
#[wasm_bindgen] pub fn add(a: i32, b: i32) -> i32 { a + b }
bash
wasm-pack build --target web
javascript
import init, { add } from './pkg/wasm.js';
await init(); add(2, 3);

WASI (System Interface)

WASI(系统接口)

bash
rustc --target wasm32-wasi main.rs -o app.wasm
wasmtime app.wasm
bash
rustc --target wasm32-wasi main.rs -o app.wasm
wasmtime app.wasm

Component Model

组件模型

wit
interface math { add: func(a: s32, b: s32) -> s32 }
Compose Rust/Go/C++ modules typés.
wit
interface math { add: func(a: s32, b: s32) -> s32 }
组合类型化的 Rust/Go/C++ 模块。

Edge (Cloudflare)

边缘计算(Cloudflare)

javascript
import wasm from './processor.wasm';
export default {
  async fetch(req) {
    const inst = await WebAssembly.instantiate(wasm);
    return new Response(inst.exports.process(req.body));
  }
};
javascript
import wasm from './processor.wasm';
export default {
  async fetch(req) {
    const inst = await WebAssembly.instantiate(wasm);
    return new Response(inst.exports.process(req.body));
  }
};

Runtimes

运行时

Wasmtime — Fast, WASI
Wasmer — Universal
WasmEdge — Edge, K8s

Voir
@.claude/skills/edge-computing/SKILL.md
Wasmtime — 高性能、支持WASI
Wasmer — 通用型
WasmEdge — 边缘计算、支持K8s

查看
@.claude/skills/edge-computing/SKILL.md