I want to write a tiny program in Zig today, such that, without any maintenance, I could come back to it in five years, and still be able to compile & run it. As Zig isn’t stable yet, this means I need to pin a specific version of Zig compiler.
What’s the best way to do that? I could use various Zig version managers, but I can’t be 100% sure that they themselves would be around 5 years down the line.
I could use
shell.nix with a pinned version of nixpkgs. For that, I am pretty sure it will be there many years down the line, but that sounds like “you wanted a banana, you got yourself a banana, a gorilla holding the banana, and half of the rest of the jungle”.
I guess I could manually download specific Zig version from the website. Does Zig guarantee that download URLs are stable even for per 1.0 Zig versions? If I go that way, what’s the canonical download script to copy paste?
From my experience the download urls are pretty stable, but I wouldn’t bet on it. Who knows what could happen within 5 years.
The safest way to guarantee that it still works in 5 years would be to package a copy of the compiler with the source code. It is just 40 MB (per supported platform) after all.
If that program is so important for you wouldn’t it be better to adjust it after each Zig release (if needed), either manually or using
it is for stable version 0.11.0 if version 0.11.1
come this will be the last for 0.11
this code is for linux
rm -r $HOME/.zig
#tar -xf x86_64-linux.tar.xz
#mv zig-linux-x86_64* $HOME/.zig
tar -xf zig-linux-x86_64-0.11.0.tar.xz
mv zig-linux-x86_64-0.11.0 $HOME/.zig
don’t forget to export .profil
I use this wrapper script (as ./zig) in all my projects to pin the version of zig last used to successfully build it. ./build.zig.version and ./zig are then checked in and ./zig is used to build. This allows me to have some projects really up-to-date and others possibly lagging quite a bit.
BASEDIR="$(cd "$(dirname "$0")" && pwd)"
if [ "$1" == "update" ] ; then
curl -L --silent https://ziglang.org/download/index.json | jq -r '.master | .version' > build.zig.version
if [ "$VERSION" != "$NEWVERSION" ] ; then
echo zig updated to $NEWVERSION
echo zig version $VERSION is up-to-date
mkdir -p "$ZIGDIR"
if [ ! -d "$ZIGVER" ] ; then
curl "$TARBALL" | tar -xJ
exec $ZIG "$@"