Update your Zig installation automatically to the newest master version (Python 3.x needed)

Hey there Zig Community,

I am very new to Zig and tried learning the basics with the ziglings repo from ratfactor: GitHub - ratfactor/ziglings: Learn the Zig programming language by fixing tiny broken programs.

The Problem was that I needed a feature from the 0.11 version and the latest stable release was 0.10.1.
Since I know a little Python I made myself a program to check on startup if zig has any new version and just install it while replacing the old version.

It maybe is not the finest work of mine but I put in a simple logging feature to be able to debug if anything goes wrong.

Disclaimer (Better safe than sorry):

  • There is no Backup included
  • Always be aware of what the code is doing before running other peoples code :smiley:
  • This code only checks for master versions.
  • If zig ever changes the way the json for the versions is formatted the program will probably crash ^^
  • You will need python 3.x and some pip modules (the most should be installed by default)
  • Please check your paths!!!
  • You are responsible if this program deletes something you still needed

I thought maybe some of you will find this helpful so I wanna post it here even though it is not perfect :smiley:
GitHub gist Link → Automatic Updater for Zig · GitHub

Maybe it helps some developers :smiley:

Have a great night,
XOYZ

2 Likes

Cool! Welcome to the forum, happy to have you!

If you’re familiar with the subprocess module in python, you can query zig and get the current install directory. Running “zig env” on my system produces:

 "zig_exe": "/snap/zig/7828/zig",
 "lib_dir": "/snap/zig/7828/lib",
 "std_dir": "/snap/zig/7828/lib/std",

You could then locate the zig_exe field and use the directory from there for your update script. Similarly, you can do things to check for the target platform if you wanted to as well if you wanted to completely automate this.

I will give you one word of caution however - as you can see, I have my installed via snap. The issue is that snap is a package manager and the python script could invalidate any meta-data that the package manager has. This is why I am very cautious of automatic update tools as scripts… they don’t play nicely with package managers.

Another issue to be careful of is if anything is installed in root directories. This can lead to problems for systems that are not executing the script as root (not a bad problem to have, privilege escalation is quite dangerous).

I can see someone using this if they wanted to provide a config for their system, or if the script prompted the user enter a password. I built a custom C++ object for python a while ago that runs shell scripts because the subprocess library is quite limited in what it can do.

Anyhow, these are just some thoughts, you have to ultimately choose the path that you are most comfortable with.

Cool stuff, and welcome again!

Thanks for having me ^^

Yeah thats definitely a nice to have. I have 3 Systems that I want to have implemented with a Script like this. Ubuntu (for a Server), Manjaro and Windows. So more automation is definetly wanted as I get further into Zig development. So this is a point I’ve been thinking about too.

Yep that’s definitely something to be aware of. I also want to implement some kind of error handling because currently if the installation gets corrupted you’re basically need to re-install it yourself. So yeah not ideal.

I definitely take your points into consideration ^-^
My plan for the future of this project is to convert it from a simple gist to full fletched repo which is a bit more flexible. Features I am currently thinking about is:

  • automatically detect the system os
  • backup old files
  • test new zig installation and maybe notify the user if it is not working (email / desktop notification)
  • Maybe make it so you could write modules to check for other things
  • Version handling with optional automatic Path extension (What can go wrong :})
  • and what ever comes to my mind on my zig journey
  • If you have any other ideas insert them here :slight_smile:

If I can find the time for this and if there are any updates I am happy to share them here.

1 Like

Not to discourage you, or dissuade you from developing your updater, but just wanted to mention this shell script:
https://github.com/jsomedon/night.zig/

It was announced by the developer at r/Zig a couple of weeks before it went down.
I have it on one of my machines and it works nicely.

Thank you very much for mentioning it. I didn’t found it when I searched for a tool like it :ok_hand:

It is still only for bash and I don’t want to work with the Linux subsystem etc.

Still thank you very much. It might come in handy😁

1 Like