aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/arch/PKGBUILD
blob: c62b8d6256ada50eed1586c9265127dfff9028f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Maintainer: Peter Geissler <peter@haxx.in>
#
# This file lives in contrib/arch/ in the slosh repo and is served raw at
# https://raw.githubusercontent.com/sl0p-foo/slosh/master/contrib/arch/PKGBUILD
# -- fetch it and
# makepkg -si. The same file feeds the self-hosted pacman repository at
# https://slosh.foo/arch/ (contrib/arch-repo builds it); it would also be the
# AUR package, but AUR signups are closed while the AUR deals with supply
# chain attacks, so self-hosting it is -- see contrib/arch/README.md.
#
# The build is offline-clean: the terminal core (libghostty-vt) is vendored
# in the tarball, and its zig dependencies are all lazy and unused by the
# VT-only build, so `zig build` fetches nothing. Verified against a cold
# ZIG_GLOBAL_CACHE_DIR.

pkgname=slosh
pkgver=0.1.8
pkgrel=1
pkgdesc="Terminal multiplexer: panes, tabs, and sessions you can detach from, on libghostty-vt"
arch=('x86_64' 'aarch64')
url="https://slosh.foo"
license=('MIT')
depends=('glibc')
# Not a hard dependency: without it, slosh writes its own embedded copy of
# the entry into ~/.terminfo the first time a pane needs it. The package is
# the system-wide, pacman-managed spelling of the same thing -- and we do
# not ship the file ourselves precisely because this package owns that path.
optdepends=('ghostty-terminfo: xterm-ghostty terminfo system-wide, instead of the automatic ~/.terminfo copy')
# One package, no -debug split: this builds for a repo we host ourselves,
# and the stripped binary is the artifact. !strip because the aarch64 package
# is cross-built on the x86_64 release box and native strip cannot read
# foreign ELF -- the link strips instead (LDFLAGS=-s below), both arches
# alike, so the two packages are made the same way.
options=('!debug' '!strip')
# zig 0.16 specifically: the vendored core states minimum_zig_version 0.16.0,
# and a newer zig may well reject it -- zig is not yet stable across versions.
makedepends=('zig')
# GitHub's tag archive extracts to $pkgname-$pkgver/ (the v is stripped).
source=("$pkgname-v$pkgver.tar.gz::https://github.com/sl0p-foo/slosh/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('ad7a9a18accad0daa74eba4b5cdae47c8e93014431fbf6d9b5f0a459ee3b955f')

# The Makefile's ZIG default is a developer-machine path; a builder has the
# real one. Overridable so the package can be test-built where zig lives
# elsewhere (ZIG=/path/to/zig makepkg).
_zig="${ZIG:-/usr/bin/zig}"

# Cross-compile when the target is not the build machine: pacman's CARCH
# names the architecture, zig turns it into a target triple. -linux-gnu
# because depends=('glibc'); zig carries the headers and stubs for every
# glibc, so nothing aarch64 needs to be installed here.
_tgt=""
[ "$CARCH" = "$(uname -m)" ] || _tgt="$CARCH-linux-gnu"

prepare() {
  cd "$pkgname-$pkgver"
  # A snapshot has no .git, so contrib/version falls back to ./VERSION -- and
  # in v0.1.1 that file was left at 0.1.0 (fixed since by contrib/release,
  # which bumps and tags as one step). Harmless for later tags: this writes
  # the number the file already holds.
  echo "$pkgver" > VERSION
}

build() {
  cd "$pkgname-$pkgver"
  # The tarball has no .git, and git walks up: built inside some other
  # repository (our release box builds in a subdirectory of the slosh repo),
  # contrib/version would describe *that* tree and stamp the package with
  # whatever state it happens to be in -- "0.1.4-dirty" was this. The
  # ceiling stops the walk at the build root, so ./VERSION answers.
  export GIT_CEILING_DIRECTORIES="$srcdir"
  # A hermetic zig cache: nothing under $HOME touched, nothing reused from it.
  export ZIG_GLOBAL_CACHE_DIR="$srcdir/zig-global-cache"
  # The pinned 0.1.2 tarball's Makefile predates TARGET= support, so the
  # cross-compile is spelled as full CC / VT_FLAGS overrides, which work on
  # that Makefile and the current one alike. At the next pkgver bump this
  # collapses to: make ZIG="$_zig" TARGET="$_tgt" LDFLAGS=-s vendor all
  local _cc="$_zig cc${_tgt:+ -target $_tgt}"
  local _vtver
  _vtver="$(sed -n 's/^[[:space:]]*\.version = "\([^"]*\)".*/\1/p' \
      vendor/libghostty-vt/build.zig.zon | head -1)"
  local _vtflags="-Demit-lib-vt -Demit-xcframework=false -Dversion-string=$_vtver -Doptimize=ReleaseFast${_tgt:+ -Dtarget=$_tgt}"
  make ZIG="$_zig" CC="$_cc" VT_FLAGS="$_vtflags" LDFLAGS=-s vendor
  make ZIG="$_zig" CC="$_cc" VT_FLAGS="$_vtflags" LDFLAGS=-s all
}

package() {
  cd "$pkgname-$pkgver"
  # make re-derives the version at parse time; same ceiling, same reason.
  export GIT_CEILING_DIRECTORIES="$srcdir"
  make ZIG="$_zig" DESTDIR="$pkgdir" PREFIX=/usr install
  # MIT, so the license ships with the package; THIRD-PARTY-LICENSES covers
  # what is statically linked in (libghostty-vt, stb_image).
  install -Dm644 LICENSE THIRD-PARTY-LICENSES -t "$pkgdir/usr/share/licenses/$pkgname"
}