From e4e829fccbca7015a876284e2d752d51d4398553 Mon Sep 17 00:00:00 2001 From: Will Manning Date: Fri, 1 Mar 2024 11:38:39 -0500 Subject: [PATCH] add zigup for easier zig toolchain installation (#6) --- .zig-version | 1 + README.md | 6 ++++++ zigup | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 .zig-version create mode 100755 zigup diff --git a/.zig-version b/.zig-version new file mode 100644 index 0000000..0008f35 --- /dev/null +++ b/.zig-version @@ -0,0 +1 @@ +0.12.0-dev.2541+894493549 diff --git a/README.md b/README.md index 2fdd0be..55274fc 100644 --- a/README.md +++ b/README.md @@ -166,6 +166,12 @@ The header file requires `zig.h` which is located in the `lib_dir` output by run This process should improve as https://github.com/ziglang/zig/issues/13528 is resolved. +## Installing Zig + +Running `./zigup` will download and install the zig version specified in the `.zig-version` file. We recommend adding +`$HOME/.zig/zig-latest` to your `PATH`. + + ## Python Library TODO: this library will be made available as a Python library using [Ziggy Pydust](https://github.com/fulcrum-so/ziggy-pydust). diff --git a/zigup b/zigup new file mode 100755 index 0000000..3bf5ad5 --- /dev/null +++ b/zigup @@ -0,0 +1,37 @@ +#!/usr/bin/env bash + +set -euo pipefail + +ZIG_HOME="${ZIG_HOME:-$HOME/.zig}" +ZIG_LATEST="${ZIG_HOME}/zig-latest" +mkdir -p "$ZIG_HOME" + +VERSION=$(cat ".zig-version" | tr -d '\n ') + +osOut="$(uname -s)" +case "${osOut}" in + Linux*) OS="linux";; + Darwin*) OS="macos";; +esac + +archOut="$(uname -m)" +case "${archOut}" in + arm64*) ARCH="aarch64";; + x86_64*) ARCH="x86_64";; +esac + +ARCH_VERSION="zig-${OS}-${ARCH}-${VERSION}" + +if [ ! -d "${ZIG_HOME}/${ARCH_VERSION}" ] +then + echo "Downloading Zig version $VERSION" + curl -s -L "https://ziglang.org/builds/${ARCH_VERSION}.tar.xz" | tar -x -J -C "${ZIG_HOME}" +else + echo "Zig version $VERSION already installed" +fi + +# Always update the symlink to the requested version +rm -f "$ZIG_LATEST" +ln -s "${ZIG_HOME}/${ARCH_VERSION}" "$ZIG_LATEST" + +echo "Add ${ZIG_LATEST} to the \$PATH"