Best way to pin Zig version today?

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?

1 Like

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 zig fmt?

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
#rm x86_64-linux*

tar -xf zig-linux-x86_64-0.11.0.tar.xz
mv zig-linux-x86_64-0.11.0 $HOME/.zig
rm zig-linux-x86_64-0.11.0*

don’t forget to export .profil
export PATH=/home/soleil/.zig:$PATH

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.

set -e

ARCH=$(uname -m)

BASEDIR="$(cd "$(dirname "$0")" && pwd)"
VERSION=$(< build.zig.version)

if [ "$1" == "update" ] ; then
    curl -L --silent | jq -r '.master | .version' > build.zig.version
    NEWVERSION=$(< build.zig.version)

    if [ "$VERSION" != "$NEWVERSION" ] ; then
        echo zig updated to $NEWVERSION
        exit 0
    echo zig version $VERSION is up-to-date
    exit 0
    mkdir -p "$ZIGDIR"
    cd "$ZIGDIR"

    if [ ! -d "$ZIGVER" ] ; then
        curl "$TARBALL" | tar -xJ

exec $ZIG "$@"