First of all I want to say that I really like the development experience with the --watch flag, thank you zig team.
But I have one minor issue with it when using in combination with the -fincremental flag that really bugs me: It sometimes just spams a lot into the console or flickers, particularly on syntax errors. Does someone else also have that problem?
Here are some steps to reproduce what I mean:
mkdir /tmp/spam && cd $_
zig init
zig build test --watch -fincremental
and then just remove the first character of the main.zig file:
If I leave the -fincremental flag out it just works as expected. Also if I restart the watch
command it also doesn’t unnecessarily updates repeatedly.
I know that I can use --error-style minimal_clear but it still flickers which annoys me. I’ve also
already tried different terminals but it’s always the same.
I can reproduce it, if I do the modification of the file like you have described, but if I just use a simple text editor to remove something from the file than it no longer happens.
So my guess is that it may have to do with your specific command, I think the difference here is that most editors will edit the file in place, while your command creates a modified copy and then replaces the original file.
So the difference may be that with your command the files file handle / inode becomes replaced with a new file and it seems that this replacement results in some kind of endless loop where the code that checks whether things have changed always comes to the conclusion that there are still new changes, but some other code looks at the old file and doesn’t find any changes or something like that. Some part of the code clearly looks at the new file because the error gets reported. I think this is a bug that somewhere something doesn’t get updated quite right, I think it would make sense to create an issue for this.
Try applying this patch to the file lib/std/Build/Step.zig from the standard library (the lib/ directory will be next to your zig binary if you’re using our standard tarballs):
This solves the problem for me. If you can confirm it works for you too I’ll PR it and it should get into 0.17.0, which is likely coming soon. (While you’re waiting for 0.17.0, you can just keep that patch applied locally, it shouldn’t cause any issues!)