OXYGENHUB
# 8597fb5ca16c oxygenhub / scripts / dist.sh
3.5 KiB · Bourne Again Shell (bash) · executable · last changed Release builds of oh for Linux, macOS and Windows 1 month ago source blame history raw
99ca93d6 Andy McCall ↶ 1
#!/usr/bin/env bash
2
# Build release archives of one binary for every platform from Linux:
3
#   Linux x86_64 and arm64 (glibc 2.28 and later): .tar.gz and .deb
4
#   macOS x86_64 and arm64: .tar.gz
5
#   Windows x86_64: .zip
6
# plus SHA256SUMS, in target/dist/VERSION.
7
#
8
#   scripts/dist.sh [VERSION]    (default: the package version)
9
#
10
# Needs: rustup targets x86_64-pc-windows-gnu, aarch64-unknown-linux-gnu,
11
# x86_64-apple-darwin and aarch64-apple-darwin; cargo-zigbuild and zig on
12
# PATH (Linux with an old glibc, and macOS without Apple's SDK); the
13
# MinGW-w64 gcc (Windows); dpkg-deb and zip.
14
set -euo pipefail
15
16
PKG=oh                   # the cargo package
17
BIN=oh                   # the binary it builds
18
DEB_NAME=oh              # the Debian package
19
SUMMARY="OxygenHub from the command line"
20
DESCRIPTION="oh talks to an OxygenHub (such as https://oxygenhub.io): issues,
21
 proposals and their reviews, releases, Flow runs and checks, from the
22
 terminal. It works alongside oxy, the Oxygen version control client."
23
HOMEPAGE="https://oxygenhub.io/andymccall/oxygenhub"
24
MAINTAINER="Andy McCall <[email protected]>"
25
DOCS=(README.md LICENSE docs/oh.md)
26
27
cd "$(dirname "$0")/.."
28
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'))")}"
29
VERSION="${VERSION#v}"
30
OUT="target/dist/$VERSION"
31
rm -rf "$OUT" && mkdir -p "$OUT"
32
export PATH="$HOME/.local/opt/zig:$PATH"
33
# Stripped, with no debug info: these are for people, not for debugging.
34
export CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0
35
# The version the binary reports.
36
export OXY_BUILD="v$VERSION"
37
38
# target triple | platform name | build tool | Debian architecture
39
PLATFORMS=(
40
  "x86_64-unknown-linux-gnu.2.28|linux-x86_64|zig|amd64"
41
  "aarch64-unknown-linux-gnu.2.28|linux-arm64|zig|arm64"
42
  "x86_64-apple-darwin|macos-x86_64|zig|"
43
  "aarch64-apple-darwin|macos-arm64|zig|"
44
  "x86_64-pc-windows-gnu|windows-x86_64|cargo|"
45
)
46
47
for p in "${PLATFORMS[@]}"; do
48
  IFS='|' read -r target platform tool deb <<<"$p"
49
  triple="${target%%.2.*}"
50
  echo "== $platform ($target)"
51
  if [ "$tool" = zig ]; then
52
    cargo zigbuild -q --release --locked --target "$target" -p "$PKG"
53
  else
54
    cargo build -q --release --locked --target "$target" -p "$PKG"
55
  fi
56
  exe="$BIN"
57
  [[ "$triple" == *windows* ]] && exe="$BIN.exe"
58
  built="target/$triple/release/$exe"
59
  name="$BIN-$VERSION-$platform"
60
  stage="$OUT/stage/$name"
61
  mkdir -p "$stage"
62
  cp "$built" "$stage/"
63
  cp "${DOCS[@]}" "$stage/"
64
  if [[ "$triple" == *windows* ]]; then
65
    (cd "$OUT/stage" && zip -qr "../$name.zip" "$name")
66
  else
67
    tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name"
68
  fi
69
  if [ -n "$deb" ]; then
70
    root="$OUT/stage/deb-$deb"
71
    mkdir -p "$root/DEBIAN" "$root/usr/bin" "$root/usr/share/doc/$DEB_NAME"
72
    install -m 0755 "$built" "$root/usr/bin/$BIN"
73
    cp README.md docs/oh.md "$root/usr/share/doc/$DEB_NAME/"
74
    cp LICENSE "$root/usr/share/doc/$DEB_NAME/copyright"
75
    cat >"$root/DEBIAN/control" <<EOF
76
Package: $DEB_NAME
77
Version: $VERSION
78
Architecture: $deb
79
Maintainer: $MAINTAINER
80
Depends: libc6 (>= 2.28)
81
Section: vcs
82
Priority: optional
83
Homepage: $HOMEPAGE
84
Installed-Size: $(du -sk "$root/usr" | cut -f1)
85
Description: $SUMMARY
86
 $DESCRIPTION
87
EOF
88
    dpkg-deb --build --root-owner-group -Zxz "$root" "$OUT/${DEB_NAME}_${VERSION}_$deb.deb" >/dev/null
89
  fi
90
done
91
92
rm -rf "$OUT/stage"
93
(cd "$OUT" && sha256sum -- *.tar.gz *.zip *.deb >SHA256SUMS)
94
echo "== $OUT"
95
ls -l "$OUT"