Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

zig-dev-bin: Automatically update to the latest nightly version #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 82 additions & 13 deletions zig-dev-bin/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,32 +1,101 @@
# Maintainer: Kaizhao Zhang <zhangkaizhao@gmail.com>

_buildver=0.10.0-dev.2977+7d2e14267
# Contributor: Techcable <$USER @ techcable.net>

pkgname=zig-dev-bin
pkgver=20220712
# Old versions of zig-dev-bin used date as pkgver (pkgver=20220712)
#
# Now we use something consistent with zig internal versioning.
# Without changing the epoch, the old version scheme would be considered
# "newer" greater than the new version scheme
epoch=1
# NOTE: Hyphen -> underscore
pkgver=0.10.0_dev.3475+b3d463c9e
pkgrel=1
pkgdesc="A general-purpose programming language and toolchain for maintaining robust, optimal, and reusable software"
arch=('x86_64')
arch=('x86_64' 'aarch64')
url="https://ziglang.org/"
license=('MIT')
makedepends=(curl jq)
options=('!strip')
provides=('zig')
conflicts=('zig')
source=(
"https://ziglang.org/builds/zig-linux-x86_64-${_buildver}.tar.xz"
)
sha256sums=(
'22faf5006338de0682bb4c62dc0f73e4df5fb837ecaff21570e4ed39dc63b9c1'
)
# NOTE: We don't include the "real" source until build()
source=()
# GPG verification is not currently possible because Zig binaries aren't signed
# Hardcoded sha256 not possible because this is a an auto-updating (nightly) package
#
# Zig Issue for signed binaries: https://github.com/ziglang/zig/issues/4945
sha256sums=()

pkgver() {
local index_file="${srcdir}/zig-version-index.json";
# Invalidate old verison-index.json
#
# If we put version-index in `source` then it would be cached...
if [[ -x "$index_file" ]]; then
rm "$index_file";
fi
curl -sS "https://ziglang.org/download/index.json" -o "$index_file"
jq -r .master.version "$index_file" | sed 's/-/_/'
}

prepare() {
local newver="$(pkgver)";
pushd "${srcdir}" > /dev/null;
local index_file="zig-version-index.json";
local newurl="$(jq -r ".master.\"${CARCH}-linux\".tarball" $index_file)";
local newfile="zig-linux-${CARCH}-${newver}.tar.xz";
source+=("${newfile}:${newurl}")
local expected_hash="$(jq -r ".master.\"${CARCH}-linux\".shasum" "$index_file")"
sha256sums+=("$newhash")
if [[ -f "$newfile" ]]; then
echo "Reusing existing $newfile";
else
echo "Downloading Zig $newver from $newurl" >&2;
curl -Ss "$newurl" -o "$newfile";
fi;
echo "" >&2
echo "WARNING: No way to GPG/SHA verify the version ahead of time" >&2
echo "See Zig issue https://github.com/ziglang/zig/issues/4945 for signed binaries" >&2;
echo "" >&2;
local actual_hash="$(sha256sum "$newfile" | grep -oE '^\w+')"
if [[ "$expected_hash" != "$actual_hash" ]]; then
echo "ERROR: Expected hash $expected_hash for $newfile, but got $actual_hash" >&2;
exit 1;
fi;
echo "Extracting file";
tar -xf "$newfile";
popd > /dev/null;
}

package() {
cd "${srcdir}/zig-linux-x86_64-${_buildver}"
cd "${srcdir}/zig-linux-${CARCH}-${pkgver//_/-}"
install -d "${pkgdir}/usr/bin"
install -d "${pkgdir}/usr/lib/zig"
cp -R lib "${pkgdir}/usr/lib/zig/lib"
install -D -m755 zig "${pkgdir}/usr/lib/zig/zig"
ln -s /usr/lib/zig/zig "${pkgdir}/usr/bin/zig"
install -D -m644 docs/langref.html "${pkgdir}/usr/share/doc/zig/langref.html"
cp -R docs/std "${pkgdir}/usr/share/doc/zig/"
# Old versions had a `docs` dir in the root dir
local langref_docs="${pkgdir}/usr/share/doc/zig/langref.html";
if [[ -d "docs" ]]; then
install -D -m644 docs/zig/langref.html "$langref_docs";
cp -R docs/std "${pkgdir}/usr/share/doc/zig/";
elif [[ -f "langref.html" ]]; then
# New versions have langref in the root dir,
# stdlib docs in lib/zig/docs
#
# The first install command implicitly creates
# the doc directory needed by stdlib :(
#
# NOTE: Currently missing data.js file
#
# https://ziglang.org/documentation/master/std/data.js
# TODO: Maybe just download it seperately from the tarball?
install -D -m644 langref.html "$langref_docs";
cp -R lib/zig/docs "${pkgdir}/usr/share/doc/zig/std";
else
echo "Unable to find docs!" >&2;
exit 1;
fi;
install -D -m644 LICENSE "${pkgdir}/usr/share/licenses/zig/LICENSE"
}
48 changes: 0 additions & 48 deletions zig-dev-bin/check.sh

This file was deleted.