Adding a field to build.zig/build.zig.zon for the Zig compiler version and commit used to init the project

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.

2 Likes

The solution is not to add another field that everybody ignores. As you pointed out, the field is already there, and everyone ignores it. The solution is to come up with a way to get people to not ignore it. For example, by failing the build if a too-old compiler version is used.

As a side note I think it would be neat if third party projects such as zigup would have a feature where they can be used as the command to invoke zig build. They would look at build.zig.zon notice the minimum zig version, and then use exactly that version to run the build script. Something like zigup build ...

The idea of auto-populating minimum_zig_version with zig init is a good one. I would accept a patch to do that.

8 Likes

That sounds perfect. I haven’t contributed to Zig yet, but I’ll give it a shot. It seems like it should be fairly straightforward. It would definitely make building a project with zigup or zvm frictionless

1 Like

I think if the field does not auto-update it will not help much as the zig init version of zig might be out of sync with the actual current zig version used for development.

Personally I auto-generate READMEs for my projects which include the current zig version for the project https://github.com/Cloudef/zig-aio/blob/master/flake.nix#L84

4 Likes