Zig NEWS

LI Yu
LI Yu

Posted on • Updated on

`asdf` to manage multiple versions of Zig, including custom dev versions

asdf is a good general tool version management tool. Just like virtualenv for python, or rvm for Ruby, or nvm for nodejs. It supports plugins so it can be used as a one tool to rule all languages thing. So I was attempted to use it to manage my local zig version.

Then I found asdf-zig from asdf-community/asdf-zig, and it works, and works great! Until that I found as zig envolves fast, seems every important project is using their own specific dev version like 0.12.0-dev.2139+e025ad7b4 or 0.12.0-dev.1828+225fe6ddb, they are unfortunately not supported by asdf-zig.

But I do want to use this tool for managing my local zig versions, so again, seems the code of asdf-zig is simple enough, so I forked and created my own flavor, where I put it at https://github.com/liyu1981/asdf-zig.

Simply to say, it allows to create a custom version file at ~/.asdf/custom/zig/versions.json like below

{
  "0.12.0-dev.2139+e025ad7b4": {},
  "0.12.0-dev.1828+225fe6ddb": {},
}
Enter fullscreen mode Exit fullscreen mode

then normal asdf list-all zig can show these versions and asdf install zig 0.12.0-dev.2139+e025ad7b4 can install it and then use it as it supports natively.

Following pictures shows how it is used

create a custom versions.json file

list custom versions by asdf

install and find custom version of zig with asdf

GitHub logo liyu1981 / asdf-zig

Zig plugin for the asdf version manager

a fork of asdf-zig for supporting custom versions

why

The official asdf-zig can only support what versions are listed at https://ziglang.org/download/index.json, which are all versions either official or cutting-edge master. But as we know zig is evolving fast, sometime I need to stick with a specific version for a while, like 0.12.0-dev.2139+e025ad7b4. This is easy job if just download it and make it available to my path. But if there are multiple projects using different custom zig version, manual changing will be tedious.

So I start to miss asdf, the one shop for managing many different new language runtimes, and luckily there is asdf-zig, but unluckily it supports no custom versions.

So I just make my fork and adjust it a bit for my usage.

how it works

essentially my fork replaces the official asdf-zig. To install it, need to remove the old one, just

Enter fullscreen mode Exit fullscreen mode

Update:

added the ability to use zig master version as @justinryanh commented.

list all zig including master version

install zig master version with asdf

Oldest comments (4)

Collapse
 
justinryanh profile image
Justin Ryan Hurstwright

Nice. I've been just doing the latest master but that's great. Good post

Collapse
 
liyu1981 profile image
LI Yu

a ha, I get you, a good missing point, and I updated my fork with a solution to that :)

Collapse
 
mustcodeal profile image
Albert

can you add support for zls in your fork and does your fork work with mise ?

Thread Thread
 
liyu1981 profile image
LI Yu

You got me, I do not know mise yet, so I do not know whether it will work or not.

For support for zls I am bit of not getting the point. As I am using this in vscode, zls installed by vscode extension is working with asdf installed zig version.

Anyway, I am happy to learn from you the usage. If zls has a similar release manifesto file like zig: ziglang.org/download/index.json, it will not be hard to add the support.