# Maintainer: Adam Mikołajczyk <adam@tui-lipan.dev>

pkgname=rozi
pkgver=0.0.4
pkgrel=1
pkgdesc='Hyprland-style tiling terminal multiplexer built on tui-lipan'
arch=('x86_64' 'aarch64')
url='https://github.com/tui-lipan/rozi'
license=('MPL-2.0')
depends=('gcc-libs' 'glibc')
makedepends=('cargo')
provides=("$pkgname=$pkgver")
conflicts=("$pkgname-bin")
# !lto: makepkg's LTO adds `-flto` to the C flags, and `ring` - reached through the release
# verification path - then compiles its C sources to LLVM bitcode that the Rust link cannot resolve,
# failing on every `ring_core_*` symbol. Nothing is lost by disabling it here: the release profile
# already performs thin LTO across the Rust side, which is where rozi's code actually is.
# !debug: the release profile strips, so a debug package would be built and shipped empty.
options=('!lto' '!debug')

# The repository tarball at the tag, which is the exact tree upstream CI builds, tests, and
# releases from. Until tui-lipan 0.4.1 this was load-bearing - rozi patched termina, and cargo
# strips `[patch]` when publishing, so the crate would have built without the fix - and it stays
# the source because it is the artifact the tag actually names.
source=("$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz")
sha256sums=('3d180355cb498ae5c0f70d40d230edc93723c3d8ff3222435de7bccc09037d12')

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

build() {
	cd "$pkgname-$pkgver"
	export RUSTUP_TOOLCHAIN=stable
	export CARGO_TARGET_DIR=target
	# `--bin rozi` for explicitness. The manifest's other binary is the Windows activation launcher,
	# which is gated behind the non-default `windows-launcher` feature and so would not be built
	# here in any case.
	cargo build --frozen --release --bin rozi
}

# No check(). The suite is an integration suite: it opens PTYs, spawns service children and
# grandchildren, and binds IPC endpoints in a runtime directory. A clean chroot has no session to
# provide those, so a check() here would fail for reasons unrelated to the package. Upstream CI runs
# the full suite on Linux, macOS, and Windows for every commit.

package() {
	cd "$pkgname-$pkgver"
	install -Dm755 "target/release/$pkgname" "$pkgdir/usr/bin/$pkgname"
	install -Dm644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
	install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

	# Sample configuration and the bundled example extensions, installed non-executable: nothing
	# under /usr/share/doc should carry the execute bit the extension payloads have in the tree.
	local _docs="$pkgdir/usr/share/doc/$pkgname/examples"
	(
		cd examples || exit 1
		find . -type f -exec install -Dm644 '{}' "$_docs/{}" \;
	)
}
