#!/usr/bin/env bash # Build release archives of one binary for every platform from Linux: # Linux x86_64 and arm64 (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) # # Needs: rustup targets x86_64-pc-windows-gnu, aarch64-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 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 metadata --no-deps --format-version 1 | python3 -c "import json,sys; print(next(p['version'] for p in json.load(sys.stdin)['packages'] if p['name']=='$PKG'))")}" 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" "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.*}" 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" 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" && sha256sum -- *.tar.gz *.zip *.deb >SHA256SUMS) echo "== $OUT" ls -l "$OUT"