Vendoring Zig Compiler as Library

Hi all, I’ve been working on a node editor using Vulkan and Wayland. I am playing around with creating my own version of MaxMSP, which is a node editor that can be used essentially to create sound graphs where each node is a source, a filter, etc. It is often used for prototyping, but also for other creative sound tasks.

One feature I am keen on trying to implement is the ability to write nodes on the fly in Zig, and allowing them to be recompiled and hot reloaded on the fly. Essentially, the graph is just a representation of a zig program we are constantly hot reloading. This has the benefit that any graph can be trivially exported to be used downstream (imagine: deployed on embedded product, which is close to my interests professionally as I work at a loudspeaker company). I think this plays nicely into zigs strength of near-instant compilation and cross-compilation abilities.

Is this something that anyone has tried? Ideally, I wouldn’t rely on a separate install of Zig, rather I’d love to have it as a library instead.

Sorry in advance if this is a duplicate! Feel free to refer me if that is the case.

5 Likes

I dont see how this requires the compiler as a library? you could just depend on as a system tool?

Certainly I could do that! However, I think that would be less clean for the following reasons:

  1. This would require either the user to install Zig (non trivial for non-technical users), or me to vendor zig as a seperate binary, rather than just being my own independent program.

  2. It would require me essentially to call Zig as a subprocess. This means AFAIK I’d have to interact with it essentially through command line arguments.This to me feels brittle, especially if the user has to bring their own.

In general, I think Zig can be the ideal “plugin” language. By that I mean, rather than shipping some format supported by a DAW etc., a user just has .zig files in his directory which he can freely edit and will be recompiled and hot-reloaded.

1 Like

I was also interested in something similar a good while ago, but calling the compiler from a web wasm application. i.e. pass a string with Zig code, and receive a byte array of wasm. I’d read something about the Zig compiler running as a wasm module and it sounded like a good match but couldnt find anything further. +1 for exposing the compiler as a runtime lib.

2 Likes