summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: b227a356c0b2d9ca8d5b60d11c856536d0e50f8c (plain)
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
95
96
97
98
99
100
101
# Maintainer: 5unekku <jimmy.bungalo8@gmail.com>

_pkgname='monsoon'
pkgname="${_pkgname}-git"
pkgver='r201.7c8bd8b'
pkgrel=1
pkgdesc='bittorrent client (daemon + cli + tui) built on libtorrent-rasterbar'
arch=('any')
url='https://gitlab.com/5unekku/monsoon'
license=('GPL-3.0-only')
depends=(
	'libtorrent-rasterbar'
	'gcc-libs'
	'glibc'
	'curl'
)
makedepends=(
	'git'
	'rust'
	'boost'
	'clang'
)
optdepends=(
	'systemd: user service included — enable with: systemctl --user enable --now monsoon'
)
install=monsoon.install
provides=("${_pkgname}")
# disable LTO: makepkg's default `lto` option injects -Clinker-plugin-lto
# into RUSTFLAGS, which breaks ffi to C/asm code (ring, our libtorrent
# bridge). symptom is undefined symbols at final link for every C-derived
# function. revisit if we ever ship a pure-rust dep tree.
options=('!lto')
source=("${pkgname}::git+${url}.git")
sha256sums=('SKIP')

pkgver() {
	cd "${pkgname}"
	# cargo version + commit count since tag + short hash
	# produces something like 0.1.0.r42.gabc1234
	printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

prepare() {
	cd "${pkgname}"
	cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
}

build() {
	cd "${pkgname}"

	# ── env diagnostics (printed to stderr) ──────────────────────────────
	# makes cross-machine failures easier to triage. cheap; runs once.
	{
		cat <<- EOF
		[monsoon-git build env]
		  rustc:       $(rustc --version 2>&1 || echo unknown)
		  cargo:       $(cargo --version 2>&1 || echo unknown)
		  cc:          $(cc --version 2>&1 | head -1 || echo unknown)
		  c++:         $(c++ --version 2>&1 | head -1 || echo unknown)
		  libtorrent:  $(pkg-config --modversion libtorrent-rasterbar 2>/dev/null || echo 'pkg-config miss')
		  boost hdrs:  $(test -f /usr/include/boost/config.hpp && echo present || echo MISSING)
		  RUSTFLAGS:   ${RUSTFLAGS:-(unset)}
		  CFLAGS:      ${CFLAGS:-(unset)}
		  CXXFLAGS:    ${CXXFLAGS:-(unset)}
		  LDFLAGS:     ${LDFLAGS:-(unset)}
		  CARGO_PROFILE_RELEASE_LTO: ${CARGO_PROFILE_RELEASE_LTO:-(unset)}
		EOF
	} >&2

	# belt-and-suspenders against env-injected RUSTFLAGS / LTO settings.
	# options=('!lto') above tells makepkg not to add LTO flags; these
	# additionally override anything in ~/.cargo/config.toml or shell env
	# that might re-enable it. C/asm ffi (ring, our libtorrent bridge)
	# silently lose symbols under LTO.
	unset RUSTFLAGS CARGO_BUILD_RUSTFLAGS
	export CARGO_PROFILE_RELEASE_LTO=off
	export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16

	export RUSTUP_TOOLCHAIN=stable
	# cache target/ OUTSIDE paru's clone dir. paru runs `git clean -fdx`
	# between -S invocations, which would wipe an in-tree target/ on every
	# build. parking it under $HOME/.cache/cargo-builds/ lets cargo's
	# incremental + dep cache survive reinstalls. typical second build
	# with no source change <5s; with small edits <30s. first build still
	# pays the full ~2min compile.
	#
	# one-time recovery if cargo's state ever gets corrupt:
	#   rm -rf ~/.cache/cargo-builds/monsoon-git
	export CARGO_TARGET_DIR="${HOME}/.cache/cargo-builds/monsoon-git"
	mkdir -p "${CARGO_TARGET_DIR}"
	cargo build --frozen --release
}

package() {
	cd "${pkgname}"
	install -Dm755 "${HOME}/.cache/cargo-builds/monsoon-git/release/${_pkgname}" \
		"${pkgdir}/usr/bin/${_pkgname}"
	install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
	install -Dm644 contrib/systemd/monsoon.service \
		"${pkgdir}/usr/lib/systemd/user/monsoon.service"
}