diff --git a/zig-dev-bin/PKGBUILD b/zig-dev-bin/PKGBUILD index 192bed0..8044c7f 100644 --- a/zig-dev-bin/PKGBUILD +++ b/zig-dev-bin/PKGBUILD @@ -1,32 +1,101 @@ # Maintainer: Kaizhao Zhang - -_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" } diff --git a/zig-dev-bin/check.sh b/zig-dev-bin/check.sh deleted file mode 100755 index f39db87..0000000 --- a/zig-dev-bin/check.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env bash - -# need: curl, jq - -_buildver_line=$(cat PKGBUILD | grep '^_buildver=') -_pkgver_line=$(cat PKGBUILD | grep '^pkgver=') - -_builddate=${_pkgver_line:7} - -_current_builddate="${_builddate:0:4}-${_builddate:4:2}-${_builddate:6}" -_current_buildver=${_buildver_line:10} - -echo "Current build:" -echo " date: ${_current_builddate}" -echo " version: ${_current_buildver}" - -echo "Fetching latest JSON version..." - -_json_version=$(curl https://ziglang.org/download/index.json) -#_json_version=$(cat index.json) - -_latest_builddate=$(echo ${_json_version} | jq -r '.["master"]["date"]') -_latest_buildver=$(echo ${_json_version} | jq -r '.["master"]["version"]') - -echo "Parsed latest build:" -echo " date: ${_latest_builddate}" -echo " version: ${_latest_buildver}" - -#_new_builddate=$(echo ${_latest_builddate} | tr -d '-') -_new_builddate=${_latest_builddate//-} - -if [[ ${_latest_buildver} == ${_current_buildver} ]]; then - echo "No new build yet." -else - if [[ ! (${_new_builddate} -lt ${_builddate}) ]]; then - _latest_tarball=$(echo ${_json_version} | jq -r '.["master"]["x86_64-linux"]["tarball"]') - _latest_sha256=$(echo ${_json_version} | jq -r '.["master"]["x86_64-linux"]["shasum"]') - _latest_size=$(echo ${_json_version} | jq -r '.["master"]["x86_64-linux"]["size"]') - echo "New build:" - echo " date: ${_latest_builddate}" - echo " version: ${_latest_buildver}" - echo " tarball: ${_latest_tarball}" - echo " sha256: ${_latest_sha256}" - echo " size: ${_latest_size}" - else - echo "No new build yet." - fi -fi