Options to try newer Zig on an older mac?

Hello Zig community,

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?

Thank you everyone,

Cim

Zig version 0.10.0 dropped support for catalina.
There is a solution for building zig from sources targeting catalaina, using the cmake parameter -DZIG_HOST_TARGET_TRIPLE=x86_64-macos.10.15: macOS 10.15: dyld: lazy symbol binding failed: Symbol not found: ___ulock_wait2 Β· Issue #14405 Β· ziglang/zig Β· GitHub

Building from sources in an old machine must be worst that using docker. You can create your own Dockerfile by downloading and copying the contents of https://ziglang.org/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz

1 Like

@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!

Thanks again,

Cim

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.

1 Like

@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…

Thank you for your advice,

Cim

1 Like

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

cmake .. -DZIG_HOST_TARGET_TRIPLE=x86_64-macos.10.15 \
         -DZIG_STATIC_LLVM=ON \
         -DCMAKE_PREFIX_PATH="/opt/local" 

but sadly my build ultimately failed running β€˜zig2’ in stage3 with

[100%] Building stage3
/bin/sh: line 1:  2772 Bus error: 10

Took a look at the Crash Report

───────────────────────────────────────────────────────────────
Exception Type:        EXC_BAD_ACCESS (SIGBUS)
Exception Codes:       KERN_PROTECTION_FAILURE at 0x000000010954a8f2
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Bus error: 10
Termination Reason:    Namespace SIGNAL, Code 0xa
Terminating Process:   exc handler [2772]

...
Thread 0:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib  0x00007fff6d9ac55e __ulock_wait + 10
1   zig2                    0x000000010911b228 Thread_Futex_DarwinImpl_wait__78759 + 280 (zig2.c:1558407)
2   zig2                    0x0000000111950d15 Thread_Futex_wait__63925 + 53 (zig2.c:1219525)
───────────────────────────────────────────────────────────────

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.

───────────────────────────────────────────────────────────────
Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000001
Exception Note:        EXC_CORPSE_NOTIFY

Termination Signal:    Segmentation fault: 11
Termination Reason:    Namespace SIGNAL, Code 0xb
Terminating Process:   exc handler [4173]

...
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   zig2                   0x000000010889f5a0 multi_array_list_MultiArrayList_28InternPool_Local_...
1   zig2                   0x000000010889ff8f multi_array_list_MultiArrayList_28InternPool_Local_...
2   zig2                   0x00000001088ada94 InternPool_indexToKey__7175 + 3844 (zig2.c:494454)
───────────────────────────────────────────────────────────────

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.

Thanks again for any advice,

Cim

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.

3 Likes

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.

Thank you again,

Cim

1 Like

Hi Loris,

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.

Thanks again,

Cim

1 Like

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

2 Likes

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 :tada:

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.

Thank you for help!

Cim

3 Likes

If you want to keep cracking away at it, there’s some lore in #20806 which might be helpful.