From 53d563da34b3250c4280268f6698212bdf27e8a2 Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 6 Aug 2022 19:11:24 -0700 Subject: [PATCH 1/2] Automatically use latest nightly version of Zig Downloads directly from https://ziglang.org/download GPG verification of downloaded files is not currently possible because Zig nightly binaries aren't signed. See github issue https://github.com/ziglang/zig/issues/4945 for details Using hardcoded sha256 is also impossible because this is an auto-updating package Therefore, there is no security beyonnd the basic integrity of a https:// network connection (although that is still some security, you would have to forge a signed HTTPS certificate to intercept). This commit also changes the versioning scheme to match the upstream downloads (and be compatible with the main zig package) This requires incrementing the "epoch" This also changes the package to support multiple architectures (both x86_64 and ARM64) --- zig-dev-bin/PKGBUILD | 71 +++++++++++++++++++++++++++++++++++++------- zig-dev-bin/check.sh | 48 ------------------------------ 2 files changed, 60 insertions(+), 59 deletions(-) delete mode 100755 zig-dev-bin/check.sh diff --git a/zig-dev-bin/PKGBUILD b/zig-dev-bin/PKGBUILD index 192bed0..a9e7b89 100644 --- a/zig-dev-bin/PKGBUILD +++ b/zig-dev-bin/PKGBUILD @@ -1,26 +1,75 @@ # 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" 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 From 2f8e43ff80101784544454e39bdc1f7bdbb7b56f Mon Sep 17 00:00:00 2001 From: Techcable Date: Sat, 13 Aug 2022 20:37:19 -0700 Subject: [PATCH 2/2] Handle moved docs directory The location in the nightly tarball moved. This change is required by the new auto-update scheme. --- zig-dev-bin/PKGBUILD | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/zig-dev-bin/PKGBUILD b/zig-dev-bin/PKGBUILD index a9e7b89..8044c7f 100644 --- a/zig-dev-bin/PKGBUILD +++ b/zig-dev-bin/PKGBUILD @@ -75,7 +75,27 @@ package() { 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" }