A few years ago I tried out Zig but life intervened and I didnβt have an immediate need so I set it aside. Then today I read about Zine: A Static Site Generator Written in Zig and got interested in trying it out again.
I find it hard to learn new tools and languages without a project where I can hack on them. Previously I had some small success with Rust and JS building some personal Zola and 11ty sites so when I read about Zine I felt inspired to see if I could port those over to it and perhaps learn a little Zig in the process.
Unfortunately I hit a snag because Zine appears to need a recent verson of Zig which neither brew or macports will install on my OSX 10.15.7 (Catalina) mac laptop.
I know this sort of thing is likely a sign that itβs time for me to get back on the treadmill and upgrade or purchase a new computer but unfortunately am not employed at the moment and canβt really justify that when my system othewise serves me well.
My mac has docker installed and while Zine doesnβt have a Dockerfile it occurred to me there might be a public docker image or container I could use to build Zig programs. https://github.com/ziglang/zig/issues/7348 seems to imply there isnβt an official Zig image for docker so I thought I would ask here for advice from people who may be rolling their own.
Does anyone in a similar situation have any suggestions or recommendations on using docker or another solution to run a recent version of Zig on an older system like mine?
@dimdin Thank you for your suggestion - I can try to build from sources.
Looking at instructions on the Zig website it seems Iβll also need more recent clang/llvm than the ones I have but I should be able to get those from macports. So It will take a little longer to get everything I need but this gives me hope!
Another option might be to instead boot into linux using a live usb stick.
It depends a bit on what hardware you have, but I think quite a few of the older mac devices also can run linux, you could try out with some linux distribution that allows you to just boot into it without installing anything.
And if you like it you then could decide at a later point, if you want to try to setup some way to have a dual boot system (I donβt know if that is easy with mac, only had that with windows when I still was using windows), or even switch to linux completely.
Of course that only makes sense if you are interested in potentially using linux.
@Sze yes given the directions Apple and I have been going if I donβt end up selling or giving this βoldβ 2020 intel macbook to a family member it will more likely run Linux before it ever runs a more recent OSXβ¦ but itβs got lots of stuff I still depend on so I canβt ditch it yet.
USB/Dual boot is a possibility but my goal was to try out the Zine SSG and learn a little Zig porting my Zola/11ty sites. Ideally Iβd like to run them all at the same time side-by-side so hoping to just get enough Zig working for Zineβ¦
Currently having fun trying to convince CMake to recognize the llvm-config I just installed with macports but old stuff in my .zshrc and PATH I havenβt touched in ages getting in the way. Just need to clean up a bitβ¦
Just an update⦠after reading the instructions and installing clang 18 and llvm 18 from macports I cloned and built zig cf90dfd309 Release 0.13.0 with
Then tried checking out and building current master 2024-09-18 2111f4c38b hoping Iβd have more luck with it. Had to manually add -L/opt/local/lib to work around ld: library not found for -lzstd but again zig2 died in stage 3 only this time with Segmentation fault: 11.
This is fun but need to get back to other stuff so setting this aside for now.
May try docker later when I have more time.
Also happy to try other suggestions.
Finding how to get the build from source to work is probably the way to go, but just to give you another option until that works, another option would be to use something like virtual box to run a virtual machine with linux to still have access to the other mac apps on the host while working on your zig things on the guest, docker works too and is similar, but using a virtual machine might be easier unless you are already familiar and comfortable with docker.
I donβt think any of these options is necessarily better than any other they all have positive and negative things about them.
The steps described in this topic have worked for me to compile Zig from source (but it takes a long time on my laptop and I did it on linux not mac): Building Zig from source for dummies?
In general there is a lot of info in that topic on compiling zig for example this:
Nix might be another good option.
So there are many options, let us know what you have tried, what has worked and what doesnβt, when you are getting back to it.
Hi, sorry for the trouble. Unfortunately itβs prohibitively complicated to keep up testing infrastructure for old mac versions and we prefer invest resources elsewhere because of that (without testing infra itβs impossible to really guarantee that a target doesnβt break).
That said, IMO the shortest path is to setup a linux VM one way or another (docker might be one way, but probably not the simplest one), and to just download a prebuilt binary in there.
Trying to build Zig for an unsupported target seems like a lot of pain in comparison.
Yes thank you all those options are available. For my use case I was hoping I could try out Zine / Zig along with all the other tools Iβve been using. The post mentioning -DZIG_HOST_TARGET_TRIPLE=x86_64-macos.10.15 made me think building from source on Catalina with clang 18 and llvm 18 from macports with that option would just work but it seems itβs not that simple.
I need to set this aside for now but Iβll post an update after I try a few more things.
No thank you itβs really no trouble. Iβve been following Zig for some time now. There are some really cool ideas in Zine I wanted to try out. This small exercise renews my appreciation for the enormity of the tasks the Zig contributors deal with daily. I just need to be patient. The decision to stick with Catalina was mine and I totally understand the consequences of βliving off the gridβ. Someday this old mac will run Linux and all will be good again.
Itβs pretty trivial to install zig in a docker container. If you already have docker working and know a little about using it, Iβd say that is the easiest way to get zig running on some unsupported system.
Here is a simple Dockerfile to get you started:
FROM alpine:latest
ARG VERSION=0.13.0
RUN apk add curl tar xz \
&& ARCH=$(uname -m) \
&& cd /opt \
&& curl https://ziglang.org/download/${VERSION}/zig-linux-${ARCH}-${VERSION}.tar.xz | tar -xJ \
&& cd /usr/bin \
&& ln -s /opt/zig-*/zig \
&& apk del curl tar xz \
&& mkdir /src
WORKDIR /src
ENTRYPOINT ["zig"]
Build it with something like: docker build . -t zig
And run it with something like: docker run -v $PWD:/src --env HOME=/src/.global-cache -u $(id -u):$(id -g) --rm -ti zig build
Wow. In contrast to a few hours of trial and error with macports, clang and llvm with @neurocyteβs Dockerfile it took all of a minute to start docker and another minute to build the alpine container. In less time then it took to write this reply I had a containerized Zig 0.13 running a trivial hello.zig on my old mac
So while ideally I could build Zine as a native osx executable, for someone like me who just wants to try it out on an old system Docker looks like the way to go. Now I need to build and configure Zine to run containerized but that looks straightforward.