Zig watch similar to cargo watch

Is there an existing zig module or some a zig build file template that adds functionality similar to what cargo watch does?
What cargo watch (and other similar tools for other languages) does is it executes (example given “zig build”) a cargo command whenever a file in the project’s source tree changes.
My use case is, that I want to create a simple game for fun, as a Web Assembly module, and I want to rebuild my project as WASM module whenever one of my source code files changes so that I can hot reload my game whenever I make a change. (I need to implement some basic hot reloading into my game logic as well as maybe manually refreshing the browser).
I guess I can hack something together using inotify but I thought I could ask here first if someone does something similar.


I’ve used watchexec to run commands on file change.
watchexec -e zig zig build


Not yet but that’s an idea that I’ve had in mind for a while now.

The good news is that most of the framework is already there; the compiler already speaks a protocol to communicate semantically information to the parent process, and the build runner acts as a multiplexer. The cache system already has a complete list of files that when changed indicate a rebuild is needed. I’ve been slowly building up to this feature all this time.

It would also be neat to integrate this with user applications - for example, zig build run could spawn the application with a special pipe open that communicates information about rebuilds. For example, if your application is a web server, it could poll the pipe to find out when a rebuild occurs, and find out which installation files in particular have been updated, reload them in memory, and maybe even send a message to connected clients, telling them to refresh certain assets, or maybe the entire page.

Related: hot code swapping · Issue #68 · ziglang/zig · GitHub

I don’t want only a cool hot code swapping demo - I want it to be fully integrated with the build system, and practically useful for many different kinds of projects.


Thanks, I try it out tomorrow

If you are on a reasonably posix system, entr is very simple and does the job.


I use watchexec for now.


Discussion continues at