maintainer="Hoang Nguyen <folliekazetani@protonmail.com>"
pkgname=templ
pkgver=0.3.850
pkgrel=2
pkgdesc="Language for writing HTML user interface in Go"
url="https://templ.guide/"
arch="all"
license="MIT"
makedepends="go"
checkdepends="gopls"
source="$pkgname-$pkgver.tar.gz::https://github.com/a-h/templ/archive/refs/tags/v$pkgver.tar.gz"
options="net" # download Go modules

# /cmd/templ/lspcmd: hangs on s390x, fails on riscv64 and loongarch64, fails on ppc64le occasionally
# /cmd/templ/generatecmd/testwatch: panics on 32-bit platforms (unaligned 64-bit atomic operation)
case "$CARCH" in
	armhf|armv7|loongarch64|ppc64le|riscv64|s390x|x86) options="$options !check";;
esac

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	echo "$pkgver" > .version
	go build -v ./cmd/templ
}

check() {
	./templ generate -include-version=false

	# Removing -trimpath is needed for tests inside cmd/templ/generatecmd/testwatch and cmd/templ/lspcmd.
	# The tests create template files relative to the current directory and try to watch those files.
	# TestCompletion test fails with our custom GOMODCACHE value.
	unset GOMODCACHE
	GOFLAGS="${GOFLAGS/-trimpath/}" go test ./...
}

package() {
	install -Dm755 $pkgname -t "$pkgdir"/usr/bin/
}

sha512sums="
933c0cb6aaf0d7590dceb3430ab4e30a6c1d64dca48158ed57606e50a7cadabb8701e513faa1ffe85048ba934c2ce1496b609b3a85e7f47be4ed077d3078b8be  templ-0.3.850.tar.gz
"
