$ show bytecodealliance/wac
wac is a CLI tool and library for composing WebAssembly components using the WAC language, a declarative superset of WIT. It parses .wac files, resolves package references from the filesystem or a Warg registry, builds a directed acyclic composition graph, and encodes the result into a valid WebAssembly component binary (.wasm). The system is modular, with four core crates: wac-parser (lexer, AST, name resolution), wac-resolver (package resolution with filesystem and registry backends), wac-graph (graph representation and binary encoding), and wac-types (type system, subtype checking, semver-aware type aggregation). The CLI exposes commands such as `plug`, `compose`, `targets`, `parse`, and `resolve`, each targeting a specific composition workflow. The architecture follows a pipeline: WAC source text → lexing/parsing → AST resolution (name binding, type checking) → composition graph construction → binary encoding. The resolver supports both local `.wat`/`.wasm` files and remote packages from a Warg registry (feature-gated). The type system includes full component model types (primitives, records, variants, resources, streams, futures, functions, interfaces, worlds) with async function support and semver-aware compatibility checks. The composition graph handles imports, instantiations, aliases, exports, and argument wiring, and can merge compatible imports from multiple packages. External dependencies include the Bytecode Alliance ecosystem: wit-parser, wasmparser, wit-component, wasm-encoder, wasmprinter, wat, and optionally warg-client and warg-protocol for registry support. The project is actively developed with extensive test coverage, including roundtrip parsing, resolution error cases, graph encoding, and registry integration tests. It is published on crates.io and provides prebuilt binaries for Linux, macOS, and Windows.
The LLM identified 4 files worth highlighting for reuse:
Implements `NameMap`, a map keyed by package names with semver-aware lookup. Supports alternate keys (e.g., `@0.2.0` matches `@0.2.1`) and provides methods for inserting, looking up, and iterating over entries. This component is self-contained and could be extracted for any project needing semver-compatible name resolution, such as package registries or dependency managers.
Provides `SubtypeChecker`, a generic subtype checking engine with caching for efficiency. Supports covariant and contravariant modes (via `invert`/`revert` methods) and handles all component model types including resources, functions, and interfaces. The checker is isolated and could be reused in any type system implementation that requires subtype relations with caching.
Implements `TypeAggregator`, which merges compatible imports from multiple packages into a single set of canonical imports. It uses semver compatibility (same major.minor or 0.y.x track) to deduplicate interfaces and worlds, and produces a mapping from original import names to aggregated names. This component is reusable for any composition tool that needs to combine imports from multiple sources while respecting version constraints.
Provides `DocumentPrinter`, which pretty-prints a WAC AST back to valid WAC source text. It handles all AST nodes including package declarations, imports, exports, let statements, types, interfaces, and worlds. This component is self-contained and could be extracted for use in debugging, formatting, or roundtrip testing of WAC or similar DSLs.