#!/usr/bin/env bash # Build release archives of one binary for every platform from Linux: # Linux x86_64, arm64 and riscv64 (glibc 2.28 and later): .tar.gz and .deb # macOS x86_64 and arm64: .tar.gz # Windows x86_64: .zip # plus SHA256SUMS, in target/dist/VERSION. # # scripts/dist.sh [VERSION] (default: the package version) # ONLY=linux-x86_64 scripts/dist.sh builds one platform (a glob) # # Needs: rustup targets x86_64-pc-windows-gnu, aarch64-unknown-linux-gnu, # riscv64gc-unknown-linux-gnu, # x86_64-apple-darwin and aarch64-apple-darwin; cargo-zigbuild and zig on # PATH (Linux with an old glibc, and macOS without Apple's SDK); the # MinGW-w64 gcc (Windows); dpkg-deb and zip. set -euo pipefail PKG=oxy # the cargo package BIN=oxy # the binary it builds DEB_NAME=oxy # the Debian package OTHER_DEB=oh # the other package sharing the apt repository files SUMMARY="Oxygen version control: a distributed, commutative VCS" DESCRIPTION="Oxygen is a version control system in which changes commute: a state is a set of changes, merges need no merge commits, conflicts are recorded and resolved like any other change, and every change is signed by its author." HOMEPAGE="https://oxygenhub.io/andymccall/oxygen" MAINTAINER="Andy McCall " DOCS=(README.md LICENSE) cd "$(dirname "$0")/.." VERSION="${1:-$(cargo pkgid -p "$PKG" | sed 's/.*[#@]//')}" VERSION="${VERSION#v}" OUT="target/dist/$VERSION" rm -rf "$OUT" && mkdir -p "$OUT" export PATH="$HOME/.local/opt/zig:$PATH" # Stripped, with no debug info: these are for people, not for debugging. export CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0 # The version the binary reports. export OXY_BUILD="v$VERSION" # target triple | platform name | build tool | Debian architecture PLATFORMS=( "x86_64-unknown-linux-gnu.2.28|linux-x86_64|zig|amd64" "aarch64-unknown-linux-gnu.2.28|linux-arm64|zig|arm64" "riscv64gc-unknown-linux-gnu.2.28|linux-riscv64|zig|riscv64" "x86_64-apple-darwin|macos-x86_64|zig|" "aarch64-apple-darwin|macos-arm64|zig|" "x86_64-pc-windows-gnu|windows-x86_64|cargo|" ) for p in "${PLATFORMS[@]}"; do IFS='|' read -r target platform tool deb <<<"$p" triple="${target%%.2.*}" # ONLY=linux-x86_64 (a glob) builds just the platforms it matches. if [ -n "${ONLY:-}" ] && [[ "$platform" != $ONLY ]]; then continue; fi echo "== $platform ($target)" if [ "$tool" = zig ]; then cargo zigbuild -q --release --locked --target "$target" -p "$PKG" else cargo build -q --release --locked --target "$target" -p "$PKG" fi exe="$BIN" [[ "$triple" == *windows* ]] && exe="$BIN.exe" built="target/$triple/release/$exe" name="$BIN-$VERSION-$platform" stage="$OUT/stage/$name" mkdir -p "$stage" cp "$built" "$stage/" cp "${DOCS[@]}" "$stage/" if [[ "$triple" == *windows* ]]; then (cd "$OUT/stage" && zip -qr "../$name.zip" "$name") else tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name" fi if [ -n "$deb" ]; then root="$OUT/stage/deb-$deb" mkdir -p "$root/DEBIAN" "$root/usr/bin" "$root/usr/share/doc/$DEB_NAME" install -m 0755 "$built" "$root/usr/bin/$BIN" cp README.md "$root/usr/share/doc/$DEB_NAME/" cp LICENSE "$root/usr/share/doc/$DEB_NAME/copyright" # The apt repository at oxygenhub.io (oxygenhub#85): the package ships # the archive's key and, on its first install, adds the repository, so # apt upgrade keeps it current. oxy and oh share the files they write. mkdir -p "$root/usr/share/$DEB_NAME" install -m 0644 packaging/oxygenhub-archive-keyring.gpg "$root/usr/share/$DEB_NAME/" sed "s/@PKG@/$DEB_NAME/" >"$root/DEBIAN/postinst" <<'EOF' #!/bin/sh set -e if [ "$1" = configure ]; then # The key is refreshed on every install, so a new one reaches everyone. install -m 0644 /usr/share/@PKG@/oxygenhub-archive-keyring.gpg /usr/share/keyrings/oxygenhub-archive-keyring.gpg # The repository is added on the first install only: removing it # keeps it removed. L=/etc/apt/sources.list.d/oxygenhub.sources if [ -z "$2" ] && [ ! -e "$L" ] && ! grep -rqs "oxygenhub.io/apt" /etc/apt/sources.list /etc/apt/sources.list.d; then cat >"$L" <"$root/DEBIAN/postrm" <<'EOF' #!/bin/sh set -e if [ "$1" = purge ] && ! dpkg-query -W -f='${Status}' @OTHER@ 2>/dev/null | grep -q "ok installed"; then rm -f /etc/apt/sources.list.d/oxygenhub.sources /usr/share/keyrings/oxygenhub-archive-keyring.gpg fi EOF chmod 0755 "$root/DEBIAN/postinst" "$root/DEBIAN/postrm" cat >"$root/DEBIAN/control" <= 2.28) Section: vcs Priority: optional Homepage: $HOMEPAGE Installed-Size: $(du -sk "$root/usr" | cut -f1) Description: $SUMMARY $DESCRIPTION EOF dpkg-deb --build --root-owner-group -Zxz "$root" "$OUT/${DEB_NAME}_${VERSION}_$deb.deb" >/dev/null fi done rm -rf "$OUT/stage" (cd "$OUT" && shopt -s nullglob && sha256sum -- *.tar.gz *.zip *.deb >SHA256SUMS) # DIST_FLAT=DIR: the same files again under names without the version, for # a pipeline whose artifacts are fixed paths (the OxygenFlow dist job); the # bytes are the release's, so its assets show as built by that job. if [ -n "${DIST_FLAT:-}" ]; then mkdir -p "$DIST_FLAT" for f in "$OUT"/*.tar.gz "$OUT"/*.zip "$OUT"/*.deb "$OUT"/SHA256SUMS; do [ -e "$f" ] || continue b=$(basename "$f"); b=${b/-$VERSION-/-}; b=${b/_${VERSION}_/_} cp "$f" "$DIST_FLAT/$b" done fi echo "== $OUT" ls -l "$OUT"