# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=keepassxc-proxy-static
_projname=keepassxc-proxy-rust
pkgver=0.2.1
pkgrel=0
pkgdesc="A statically linked proxy between Native Messaging browser extension and KeePassXC (for use with Flatpak)"
url="https://github.com/varjolintu/keepassxc-proxy-rust"
# armhf, armv7, riscv64, s390x: fails to build libc crate (SIGSEGV)
arch="all !armhf !armv7 !riscv64 !s390x"
license="GPL-3.0-or-later"
makedepends="cargo cargo-auditable"
install="$pkgname.post-install"
source="
	https://github.com/varjolintu/keepassxc-proxy-rust/archive/$pkgver/$_projname-$pkgver.tar.gz
	keepassxc-proxy-install.in
	"
builddir="$srcdir/$_projname-$pkgver"

export CARGO_PROFILE_RELEASE_OPT_LEVEL="z"
export RUSTFLAGS="$RUSTFLAGS -C target-feature=+crt-static"

prepare() {
	default_prepare

	sed "s/@@VERSION@@/$pkgver/" "$srcdir"/keepassxc-proxy-install.in \
		> "$srcdir"/keepassxc-proxy-install

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release
}

check() {
	local bin='target/release/keepassxc-proxy'

	if ! file $bin | grep -Fqw 'static-pie linked'; then
		file $bin
		error "$bin is not a static binary!"
		return 1
	fi
}

package() {
	install -D -m755 target/release/keepassxc-proxy "$pkgdir"/usr/libexec/keepassxc-proxy.static
	install -D -m755 "$srcdir"/keepassxc-proxy-install "$pkgdir"/usr/bin/keepassxc-proxy-install
}

sha512sums="
de042a62e375a233aae4ed68919a54f2e7466b125d84f7dc32929e96bd224a600919de6f0678a548f14bcc23c1b9144f5c80cc1ce4e92820ffbf945a84b11483  keepassxc-proxy-rust-0.2.1.tar.gz
3d31ed8d2a430f1e61960990128a9b7277106fcf74c16952ccefdeca3a3ba5cb9e6917d08d801bff1d4d354566689bda8f54d10f3711b03063d01374913c0387  keepassxc-proxy-install.in
"
