OXYGENHUB
# 2aa1854b0d13 oxygen / scripts / dist.sh
3.5 KiB · Bourne Again Shell (bash) · executable · last changed Release builds for Linux, macOS and Windows 1 month ago source blame history raw
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=oxy                  # the cargo package
17
BIN=oxy                  # the binary it builds
18
DEB_NAME=oxy             # the Debian package
19
SUMMARY="Oxygen version control: a distributed, commutative VCS"
20
DESCRIPTION="Oxygen is a version control system in which changes commute: a
21
 state is a set of changes, merges need no merge commits, conflicts are
22
 recorded and resolved like any other change, and every change is signed
23
 by its author."
24
HOMEPAGE="https://oxygenhub.io/andymccall/oxygen"
25
MAINTAINER="Andy McCall <[email protected]>"
26
DOCS=(README.md LICENSE)
27
28
cd "$(dirname "$0")/.."
29
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'))")}"
30
VERSION="${VERSION#v}"
31
OUT="target/dist/$VERSION"
32
rm -rf "$OUT" && mkdir -p "$OUT"
33
export PATH="$HOME/.local/opt/zig:$PATH"
34
# Stripped, with no debug info: these are for people, not for debugging.
35
export CARGO_PROFILE_RELEASE_DEBUG=0 CARGO_PROFILE_RELEASE_STRIP=true CARGO_INCREMENTAL=0
36
# The version the binary reports.
37
export OXY_BUILD="v$VERSION"
38
39
# target triple | platform name | build tool | Debian architecture
40
PLATFORMS=(
41
  "x86_64-unknown-linux-gnu.2.28|linux-x86_64|zig|amd64"
42
  "aarch64-unknown-linux-gnu.2.28|linux-arm64|zig|arm64"
43
  "x86_64-apple-darwin|macos-x86_64|zig|"
44
  "aarch64-apple-darwin|macos-arm64|zig|"
45
  "x86_64-pc-windows-gnu|windows-x86_64|cargo|"
46
)
47
48
for p in "${PLATFORMS[@]}"; do
49
  IFS='|' read -r target platform tool deb <<<"$p"
50
  triple="${target%%.2.*}"
51
  echo "== $platform ($target)"
52
  if [ "$tool" = zig ]; then
53
    cargo zigbuild -q --release --locked --target "$target" -p "$PKG"
54
  else
55
    cargo build -q --release --locked --target "$target" -p "$PKG"
56
  fi
57
  exe="$BIN"
58
  [[ "$triple" == *windows* ]] && exe="$BIN.exe"
59
  built="target/$triple/release/$exe"
60
  name="$BIN-$VERSION-$platform"
61
  stage="$OUT/stage/$name"
62
  mkdir -p "$stage"
63
  cp "$built" "$stage/"
64
  cp "${DOCS[@]}" "$stage/"
65
  if [[ "$triple" == *windows* ]]; then
66
    (cd "$OUT/stage" && zip -qr "../$name.zip" "$name")
67
  else
68
    tar -C "$OUT/stage" -czf "$OUT/$name.tar.gz" "$name"
69
  fi
70
  if [ -n "$deb" ]; then
71
    root="$OUT/stage/deb-$deb"
72
    mkdir -p "$root/DEBIAN" "$root/usr/bin" "$root/usr/share/doc/$DEB_NAME"
73
    install -m 0755 "$built" "$root/usr/bin/$BIN"
74
    cp README.md "$root/usr/share/doc/$DEB_NAME/"
75
    cp LICENSE "$root/usr/share/doc/$DEB_NAME/copyright"
76
    cat >"$root/DEBIAN/control" <<EOF
77
Package: $DEB_NAME
78
Version: $VERSION
79
Architecture: $deb
80
Maintainer: $MAINTAINER
81
Depends: libc6 (>= 2.28)
82
Section: vcs
83
Priority: optional
84
Homepage: $HOMEPAGE
85
Installed-Size: $(du -sk "$root/usr" | cut -f1)
86
Description: $SUMMARY
87
 $DESCRIPTION
88
EOF
89
    dpkg-deb --build --root-owner-group -Zxz "$root" "$OUT/${DEB_NAME}_${VERSION}_$deb.deb" >/dev/null
90
  fi
91
done
92
93
rm -rf "$OUT/stage"
94
(cd "$OUT" && sha256sum -- *.tar.gz *.zip *.deb >SHA256SUMS)
95
echo "== $OUT"
96
ls -l "$OUT"