marler8997 / zigup

Download and manage zig compilers.
MIT No Attribution
784 stars 61 forks source link

Utilize Zig's global package cache to store itself #135

Open marler8997 opened 6 months ago

marler8997 commented 6 months ago

Zigup stores each instance of zig into a "zigup-specific" directory. However, it's possible that other frameworks/tools would also like to install specific versions of zig. If each framework/tool has their own directory to store Zig, then users are downloading and storing multiple copies of the same version of Zig.

One way to address this would be to establish a convention and mechanism to coordinate managing these versions of zig in a common global directory and get frameworks/tools to adopt this convention. That sounds hard, so it's lucky we already have a convention for this, Zig's global package cache. You can already utilize Zig's global package cache to install zig today, here's how you would install zig for linux x86_64 using zig:

$ zig fetch https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz

You can then run it with:

$ ~/.cache/zig/p/1220222c0478d782ec362ec2aa0777d59a727f14ecb3aca7d9efdedc7a7fec43e062/zig

I believe zigup could even leverage zig itself to install itself. The way this would work is zigup could download/install zig to a temporary location (like it already does today), then invoke zig to fetch zig using the temporary file path where zig was downloaded.

The last piece here is maintaining ability to find the a zig installation only knowing its version number. For this zigup can create/maintain a folder of symlinks, i.e.

~/zig/0.12.0-> ~/.cache/zig/p/1220a6ba0703e5baab2c5eb18931c66e4a73b59a298c24ed03f588c80e7c3f82a2ea
~/zig/0.11.0-> ~/.cache/zig/p/1220a69ceaac42e5a3593161c3b4ab1ce7dbc574b1a80398a7cb3100fbfa07baf372

Maybe zigup should also have a way to scan and discover whether any other tools/frameworks have installed different versions of zig and update it's symlink directory, i.e.

zigup scan
found new zig installation 0.7.0 at  ~/.cache/zig/p/1220a69ceaac42e5a3593161c3b4ab1ce7dbc574b1a80398a7cb3100fbfa07baf372