← 返回博客

Rotifer v0.3:TypeScript → WASM 自动编译

用 TypeScript 写基因,自动编译为 WASM。无需 Rust,无需 AssemblyScript,无需工具链配置。用你已经在用的语言。

Rotifer v0.3:TypeScript → WASM 自动编译

编写 WASM 基因的最大障碍是工具链。v0.3 彻底移除了它:写一个 TypeScript 函数,运行 rotifer compile,得到一个沙箱化的 WASM 基因。零配置。

TS → WASM 流水线

新的编译流水线自动串联三个阶段:

TypeScript → esbuild(打包)→ WASI shim → IR 编译器(QuickJS→WASM)→ Rotifer IR
rotifer compile my-gene            # 自动检测 index.ts,编译为 WASM
rotifer compile my-gene --lang ts  # 强制 TypeScript 模式

底层使用 IR 编译器将 QuickJS 嵌入 WASM 模块。产出的基因在与手写 Rust 基因相同的 wasmtime 沙箱中运行——相同的燃料计量、内存限制和安全隔离。

无需 Rust。无需 AssemblyScript。无需 WASM 工具链配置。 用你已经在用的语言。

WASI 沙箱支持

Rust 核心的 WasmtimeSandbox 现在支持两种执行模式:

最小化 WASI shim 提供 9 个宿主函数(fd_readfd_writeclock_time_get 等)——刚好够 QuickJS 运行,不多不少。

IR 验证器更新

数据一览

开始使用

npm install -g @rotifer/playground

写一个基因:

// genes/my-search/index.ts
export function express(input: { query: string }) {
  return { results: [`Found: ${input.query}`], total: 1 };
}

编译并提交:

rotifer compile my-search
rotifer arena submit my-search