# Contributor: TBK <alpine@jjtc.eu>
# Maintainer: TBK <alpine@jjtc.eu>
pkgname=jsonnet
pkgver=0.20.0
pkgrel=0
pkgdesc="The data templating language"
url="https://jsonnet.org/"
arch="all !s390x !riscv64 !loongarch64" # blocked by rapidyaml
license="Apache-2.0"
makedepends="cmake gtest-dev nlohmann-json rapidyaml-dev samurai"
checkdepends="bash"
subpackages="$pkgname-libs $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/google/jsonnet/archive/v$pkgver.tar.gz
	json-include.patch
	unvendor-ryml.patch
	"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_STATIC_LIBS=OFF \
		-DBUILD_SHARED_BINARIES=ON \
		-DUSE_SYSTEM_GTEST=ON \
		-DUSE_SYSTEM_JSON=ON \
		$CMAKE_CROSSOPTS
	cmake --build build
}

check() {
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest
}

package() {
	DESTDIR="$pkgdir" cmake --install build
}

sha512sums="
d46d2521d4389d05f91a16ecd9f181be1853f674a9264e9fac23e413f1084dee947e80682af59603e15e443061a0beb50a30c14c858853e10ed1ae7187d09730  jsonnet-0.20.0.tar.gz
6e6130797992015d223e54ad165fc6790eb2653433aa1c11d5bd17c3cc027c8befb3437601c08681bca29d16700c3c70555236bd1832c59443627419ae972d55  json-include.patch
a38176c3b13ae017c9aa622171373cf9d9f9c9e31f094f787db9038ca9303fd6fb6c415711a4356c57c3f5226e98a346f35eef73d36412fd427794c496b8239c  unvendor-ryml.patch
"