用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill webassembly命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | webassembly |
| description | | Use when this capability is needed. |
WebAssembly (WASM) is a binary instruction format for a stack-based virtual machine. It is a compilation target — not a language — designed for near-native execution with strong sandboxing guarantees. A WASM module cannot access the host filesystem, network, or system calls unless the host explicitly grants those capabilities.
Three properties make WASM useful at runtime boundaries:
.wasm runs on any host with a compatible runtime, regardless of OS or architecture..wasm can replace a running one by re-instantiating the component in a fresh store.This skill is language-agnostic: WIT syntax, component model semantics, WASI capabilities, the canonical ABI, and the binary format live here. Rust-side host embedding (Engine/Store/Linker/Component, wasmtime::component::bindgen!, WasiCtxBuilder) lives in the wasmtime sibling skill. Rust language and build surface (target flags, the cargo-component CLI, the wit-bindgen macro, wasm-bindgen for the browser) lives in the rust sibling skill plus docs.rs for crate APIs. Anything that is "what does this contract MEAN / what is the on-the-wire shape / which capability is needed" belongs here regardless of language.
wasm.md)The binary format itself: stack machine execution, linear memory, modules, traps, runtime landscape (wasmtime/wasmer/wasmi/v8). Read this for a grounding in what a .wasm file actually is and how runtimes execute it.
wasi.md)WebAssembly System Interface — how a sandboxed module talks to the host OS. Critical distinction: preview1 (legacy) vs preview2 (component-model-based). The wasm32-wasip2 target produces preview2 components. Read this before touching any capability grants or host linker setup.
wasm-components.md)The layer above raw modules. A component wraps a module and annotates its imports and exports with WIT types (strings, records, variants, results) instead of raw i32/i64. Composition — wiring one component's exports to another's imports — happens here. Read this before designing any component interface or using wasm-tools/wac.
wit.md)WebAssembly Interface Type language — the IDL for the component model. Defines worlds, interfaces, types. Most importantly: directionality. Every WIT file is either describing existing code (Direction 1) or enforcing a contract on yet-to-be-written code (Direction 2); confusing the two breaks the architectural invariant. Read this before writing or modifying any .wit file.
Use WASM when the code satisfies at least one of:
Do NOT use WASM when:
Traps are unrecoverable. When a WASM guest traps (out-of-bounds memory access, integer divide by zero, explicit unreachable), the store is poisoned. Re-instantiate the component from the same bytecode — do not attempt to resume the same store.
Linear memory is flat and bounded. There is no garbage collector in core WASM. Strings and lists passed across the component boundary are copied, not shared. For high-frequency calls, batch data or reduce crossing frequency.
Clock and random are not free. WASM has no built-in access to the system clock or a CSPRNG. The host must explicitly wire in the WASI wasi:clocks and wasi:random interfaces. A component compiled expecting these and running under a linker that doesn't provide them will trap at instantiation time, not at the first call.
wasm32-wasip2 is not wasm32-unknown-unknown. The wasip2 target produces a component, not a raw module. Tooling that expects a flat .wasm module (wasm-bindgen, some older toolchains) may not handle it correctly. The wasm32-unknown-unknown target is for browser/bindgen scenarios; wasm32-wasip2 is for server-side component model scenarios. Mixing them is the most common source of "why won't this load?" errors. The legacy wasm32-wasi target was renamed to wasm32-wasip1; wasm32-wasip3 exists as a Tier 3 target for the upcoming WASI 0.3 (wasm32-wasip2 is Tier 2 and is the default for component-model server scenarios today).
WIT types are not host-language types. Strings in WIT are UTF-8, length-prefixed, and copied at the boundary. A guest's &str is not the same pointer as the host sees. record fields are laid out by the component model ABI, not by the host language's repr rules. Never assume memory layout compatibility across the boundary.
Imports must all be satisfied. A component that declares any import — function, type, or WASI interface — must have every import linked before instantiation. Missing imports cause a link error at instantiation time, not at the call site.
WASM lives at exactly one boundary in most systems: between a host process (compiled native) and a hot-swappable guest (compiled to .wasm). Every other boundary is in-process polymorphism using the host language's native facilities (Rust traits, Python protocols, etc.).
host process (native)
│
│ driver.invoke(ctx) -> result
│ [component boundary — WIT types cross here]
▼
my-component.wasm (guest, WASM component)
├── implements: <namespace>:<package>/<world>
├── imports: <namespace>:<package>/<types>
└── pure computation; no I/O; no shared memory
The WIT contract that governs this boundary typically lives next to whichever side owns the contract:
For the full direction model and decision tree, see wit.md.
The host typically holds a mutex around runtime state containing the Store and bindings. On each guest call:
Hot-swap is a re-instantiation: compile the new .wasm bytes into a Component, create a new Store, instantiate new bindings, replace the runtime-state contents. The old store and bindings are dropped. No state survives a swap — guests are stateless across instantiations unless the host explicitly persists state.
Rust-side embedding details (Engine/Store/Linker/Component, bindgen! macro, WASI capability grants, Mutex-wrapped state, AOT precompilation) live in the wasmtime sibling skill.
This concept is covered fully in wit.md. The one-line summary:
Before writing or modifying any .wit file, identify which direction it is. If ambiguous, add a comment to the file declaring the direction. Bulk-generating Direction 2 files breaks the architectural contract.
| WIT file role | Direction |
|---|---|
| Shared-types package mirroring existing host types | 1 |
| World defining what plugin/guest components must export | 2 |
Component-side world.wit consuming an upstream contract | 2 (component is the implementer) |
Before modifying any .wasm or .wit file, inspect it first:
# Is the built artifact a component or a raw module?
wasm-tools validate --features component-model path/to/my_component.wasm
# What WIT interface does the compiled component declare?
wasm-tools component wit path/to/my_component.wasm
# Disassemble to text format for reading
wasm-tools print path/to/my_component.wasm | head -100
# Validate a WIT package directory
wasm-tools component wit path/to/wit/
For runtime errors:
import declarations vs what the linker provides.unreachable). The store is now poisoned.The most common source of silent failures: changing a WIT file without recompiling the component that implements it. The host bindgen re-runs at build time, but the .wasm binary must also be rebuilt against the updated WIT. If the WIT and the component binary diverge, the link error surfaces at runtime instantiation.
The WASM toolchain has language-agnostic and language-specific tools. The language-agnostic ones live in this skill's reference files; the language-specific ones live in their host language's skill or on docs.rs.
| Tool | What it is | Where the depth lives |
|---|---|---|
wasm-tools | Swiss Army knife: validate, print, component new, component wit, compose, metadata show, strip. The binary inspector. | wasm-components.md, wit.md |
wac | WebAssembly Composition tool — wires components together by their WIT imports/exports. | wasm-components.md |
wit-bindgen | Multi-language guest-side binding generator from a .wit package. Rust, C, Go, JS, Python. | host language skill (Rust: see crate docs on docs.rs) |
wasmtime | Reference runtime + Rust host embedding crate. | wasmtime sibling skill |
cargo-component | Rust-specific cargo subcommand: compiles a Rust crate directly to a WASM component, runs wit-bindgen at build time, targets wasm32-wasip2. | rust skill cargo.md; crate docs |
wasm-bindgen | Rust↔JS interop for wasm32-unknown-unknown (browser). NOT a component-model tool — produces raw modules. | rust skill / docs.rs |
cargo-component and wasm-bindgen are mutually exclusive targets: the former produces components for wasm32-wasip2; the latter produces raw modules for wasm32-unknown-unknown. Mixing them in the same crate's build will fail.
Four flat reference files live alongside this skill:
wasm.md — Stack machine, linear memory, module structure, text/binary format, traps, runtime landscape, security model.wasi.md — WASI capabilities, preview1 vs preview2 distinction, wasm32-wasip2 target, capability model, adapters, WASI 0.3 trajectory.wasm-components.md — Component vs module, composition, interface types vs core types, resources (own<T>/borrow<T>), canonical ABI, wasm-tools, wac.wit.md — WIT syntax reference, worlds, interfaces, types, directionality (the most important concept), feature gates (@since/@unstable/@deprecated), include, async (stream<T>/future<T>), placement rules, anti-patterns.Read the pillar file that matches the question before answering. For WIT questions, wit.md is authoritative. For capability/sandbox questions, wasi.md. For composition questions, wasm-components.md.
wasmtime (sibling skill) — Rust-side host embedding: Engine/Store/Linker/Component lifecycle, wasmtime::component::bindgen!, WasiCtxBuilder capability grants, the Mutex<Inner> driver pattern, AOT precompilation. Reach there for any "how do I load and call this .wasm from a Rust host?" question.rust (sibling skill) — Rust language and build surface. The Rust target tier table is in rust/rustc.md; the cargo-component subcommand summary is in rust/cargo.md. Reach there for Rust-side compile/link/feature questions.code-style (sibling skill) — personal-preference layer for whichever host language is involved. Project-specific component layouts (which directory holds the .wasm builds, naming conventions, dependency rules) live in the project's own docs, not here.Source: FL03/claude — distributed by TomeVault.