I made tooling to easily call Zig and generally include Zig code in TypeScript projects, both native and Wasm targets. Still a lot of work left to do with marshalling different types, but the API is starting to look pretty nice:
It’s a bit similar to Zigar mentioned here earlier but much lighter, provides static typing for Zig functions on TS side and doesn’t hide the Zig build config.
Hey! Sorry I found this project late. I’ve been doing a parallel effort to bind zig to typescript. I took the no brain method of converting a zig type to a JSON string and doing a JSON.parse on the frontend and vice-versa to communicate - then just did a zig script to generate a .d.ts file telling Typescript what to expect out of the JSON string. It’s not a fast method by any means … the only optimization is when zig finds a type that could be represented as a TypedArray, it just passes the slice info for Typescript to find manually from the Wasm memory.
It would definitely be awesome if there was some way to build up an interface in Typescript for pulling data from deep struct hierarchies in zig/wasm memory without basically cloning the whole structure… But probably a lot of work.
Thanks for the heads-up! I just updated zbind to support all Zig versions 0.11.0 - 0.12.0 as far as I can tell.
We’ll see if / when I’ll get around to adding support for reading structs directly. One annoyance is that the in-memory layout of slices is undefined. Maybe in Wasm the JS side could just read them anyway using the current layout, but in native it’d have to call a Zig function because we can’t safely hard-code a cross-platform ABI for slices if Zig doesn’t want to define one.
Now zbind supports Zig versions 0.11.0 - 0.13.0 and at least 0.14.0-dev.91+a154d8da8 as well.
The pretty basic algorithm code I’m using to speed up my TypeScript, now compiles into working Wasm and Node.js addons on all those Zig versions. That’s pretty flexible if you want to include Zig code that requires a narrower version range. It’s probably supported by zbind.
In its current state I’m already using zbind for image processing and don’t personally need any new features, so they’ll be added sparingly. Since I’m hoping to also keep a wide version support, the more comptime magic is involved the harder that goal becomes.