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