# libghostty-vt C API (Phase 8, agent L2) Crate `crates/ghostty-vt-capi` (crate types `cdylib` + `staticlib` + `rlib`). Depends only on `ghostty-vt` and `ghostty-input` (no `ghostty-terminal`), so it builds for `wasm32-unknown-unknown`. ## Mapping | Zig | Rust | | --- | --- | | `lib_vt.zig` `@export` list | `#[unsafe(no_mangle)] extern "C"` fns (38 native symbols) | | `terminal/c/color.zig` | `color.rs` (`ghostty_color_rgb_get`, `GhosttyColorRgb`) | | `terminal/c/osc.zig` | `osc.rs` | | `terminal/c/sgr.zig` | `sgr.rs` (+ wasm attribute helpers in `wasm.rs`) | | `terminal/c/key_event.zig` | `key_event.rs` | | `terminal/c/key_encode.zig` | `key_encode.rs` | | `terminal/c/paste.zig` | `paste.rs` | | `terminal/c/result.zig` | `result.rs` | | `lib/allocator.zig` (C allocator) | `alloc.rs` | | `lib/allocator/convenience.zig` | `wasm.rs` (exported only on wasm32) | Headers are copied unchanged to `include/ghostty/` (`diff -r` against `ZIG/include/ghostty` is empty). The C examples (`examples/c/*.c`) and wasm examples (`examples/wasm/*.html`) are unchanged copies of `ZIG/example/{c-vt,c-vt-key-encode,c-vt-paste,c-vt-sgr,wasm-key-encode,wasm-sgr}`. ## Library file names Cargo forbids hyphens in `[lib] name`, so the artifacts are `libghostty_vt_capi.{so,a}` / `ghostty_vt_capi.wasm`. `build.rs` sets the soname to `libghostty-vt.so`; `just vt-lib [profile]` (and the integration tests) install copies as `libghostty-vt.{so,a}` and `ghostty-vt.wasm` (upstream's names). ## Tests * unit tests: ports of the Zig `test` blocks in `terminal/c/*.zig` (22 tests; the `lib_alloc.test_allocator` leak-check variants map to plain alloc/free round trips). * `tests/abi.rs`: generates a C probe from the headers (enum typedefs and `#define`s are parsed from the header text, every declared function's address is taken), compiles it with `cc`, links it against `libghostty-vt.so`, and compares sizeof/alignof/offsetof of every struct/union, sizeof of every enum and typedef, the value of every enumerator and `#define` against the Rust definitions (`size_of`/`align_of`/`offset_of!`, `Key::ALL`, discriminants). A second test checks `nm -D` exports == declared functions. * `tests/c_examples.rs`: compiles the four C examples with `cc` and checks stdout (upstream has no expected-output files; the strings were derived by reading the example sources), plus a static-link run against `libghostty-vt.a`. * `tests/wasm_examples.rs` + `tests/wasm/run.mjs`: builds `--target wasm32-unknown-unknown`, checks every header function (including the `__wasm__`-only `ghostty_wasm_*`) is exported and that the module has no imports, then runs the two wasm example pages' unmodified `