Created
May 30, 2024 17:31
-
-
Save elasticdog/85b4b91aa844d35b5ed2e72bccfadb2b to your computer and use it in GitHub Desktop.
naive zigup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
# save current versions of zig and zls for summary output | |
zig_before=$(zig version) | |
zls_before=$(zls --version) | |
archive_url="https://zigbin.io/master/aarch64-macos.tar.xz" | |
archive="zig-macos-aarch64.tar.xz" | |
zig_dir="${archive%%.*}" # extension removed | |
printf "\n*** UPDATING ZIG\n" | |
local_zig_version=$(fd --type directory "$zig_dir" ~/.local/src/ | xargs basename | sed 's/\/$//') | |
remote_zig_version=$(curl --silent --show-error --location --head "$archive_url" | awk '/^location:/{print $2}' | tr -d '\r' | xargs basename -s .tar.xz) | |
printf "local version: %s\n" "$local_zig_version" | |
printf "remote version: %s\n" "$remote_zig_version" | |
if [[ $local_zig_version != "$remote_zig_version" ]]; then | |
printf "installing latest version...\n" | |
set -x | |
cd ~/.local/src/ | |
curl --silent --show-error --location "$archive_url" --output "$archive" | |
fd --type directory "$zig_dir" --exec rm -rf | |
tar -xf "$archive" | |
fd --type directory "$zig_dir" --exec ln -sf "{}" "$zig_dir" | |
rm "$archive" | |
{ set +x; } 2>/dev/null | |
else | |
printf "versions match; skipping...\n" | |
fi | |
printf "\n*** UPDATING ZLS\n" | |
set -x | |
cd ~/src/vendor/zls/ | |
git pull --ff-only --quiet | |
zig build -Doptimize=ReleaseSafe | |
{ set +x; } 2>/dev/null | |
printf "\n*** SUMMARY\n" | |
printf "zig: %s -> %s\n" "$zig_before" "$(zig version)" | |
printf "zls: %s -> %s\n" "$zls_before" "$(zls --version)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment