Ghostty's wasm code talks to JavaScript through the zig-js library (mitchellh/zig-js, pinned in build.zig.zon). The first port invented its own import ABI because the dependency wasn't available; now: - ghostty-os/src/wasm/js.rs is a Rust port of zig-js's Zig side (Ref, Value, Object get/set/call/new, global, runtime, string) using its "zig-js" import module, function names and NaN-boxed value refs. - web_canvas face and the atlas debug canvas make the same JS calls as Ghostty's Zig code. - zig-js's unmodified JS host (+ LICENSE) is vendored under crates/ghostty-wasm/js/zig-js and drives the node test. Test Plan: - cargo test -p ghostty-wasm (node >= 24; asserts zig-js imports and no leaked host values)
zig-js Glue
This is the JS library that glues with the Zig library so that Zig can communicate with the host JS environment when compiled to WebAssembly. Learn more about the zig-js library at the zig-js repository.
Installation
There are two methods for using the JS side of zig-js:
-
This library is a standard npm package, so you can install and use it as you normally would any other package. Add it to your package.json and integrate it with the bundler you're already using.
-
You can run
npm run buildin this directory and the library will be bundled into a single JS file indist/. You can then copy the single JS file into your web project. We bundle both a normal CJS module atdist/index.jsas well as an ES module atdist/module.js. TypeScript type definitions are available indist/types.d.ts.