I often come across a Zig project on a git site and I try to build it so that I can learn from it and potentially send a PR with the code updated to master. At this point there is about a 80% chance the build just outright fails because of version changes in the Zig compiler. Which is fine, a lot of people just want to share their code, the responsibility is not on them to ensure other people can use it. But I think the problem is still prescient when the Zig compiler is still rapidly iterating, a lot of code is left to bit rot, and there are a wide range of compiler versions across platforms and linux distros that are considered “current”… all of which exacerbate this issue of projects failing to build.
The only recourse is to download every tagged release of the Zig compiler to see which version this project builds with. I wouldn’t be suggesting this if this was all it took… about 65% of the time, none of the tagged releases work and it becomes apparent that this project was built with a hyper-specific commit between 0.11.0 - 0.13.0. Now this could be thousands of possibilities. At this point it takes an exponential amount of effort to find what version of Zig this project used. This makes it not only impossible to build, but it makes it harder to update and maintain the code.
So with this in mind, I think a perfect solution would be to insert the output of zig version
into a field in the build.zig.zon
file (or another file if there is a better place to do so). I’d love to build a tool that can take this information (compiler version and commit) and automatically fetch or build that version of the Zig compiler, which could potentially be used as a build step so that it becomes trivial to build a project despite what arcane version was used. I don’t really see a downside for this, unless people are somehow adverse to presenting this information, but even in that case I believe that the benefits would still outweigh the downsides.
I’m aware that the build.zig.zon file has a “minimum_zig_version” field but it doesn’t address this issue and being commented out by default, hardly anyone uses it. Some people have taken to putting the Zig version in the readme or the build.zig file, but it is so astronomically rare.
To test this, go to Github, search for some zig projects that aren’t on trending, and try to build 3 of them.