# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer: team/gnome <fossdd@pwned.life>
pkgname=gjs
# even number after first dot are the stable releases
pkgver=1.84.2
pkgrel=1
pkgdesc="GNOME javascript library"
url="https://wiki.gnome.org/Projects/Gjs"
# armhf blocked by mozjs
arch="all !armhf"
license="MIT AND LGPL-2.0-or-later"
makedepends="
	cairo-dev
	clang
	dbus
	gobject-introspection-dev
	gtk+3.0-dev
	libffi>=3.3
	lld
	meson
	mozjs-dev
	"
checkdepends="xvfb-run"
subpackages="$pkgname-dev $pkgname-dbg"
source="https://download.gnome.org/sources/gjs/${pkgver%.*}/gjs-$pkgver.tar.xz
	encoding.patch
	"
options="$options !check" # https://gitlab.gnome.org/GNOME/gjs/-/issues/681#note_2382535

build() {
	case "$CARCH" in
	aarch64|arm*|riscv64|loongarch64)
		# not supported by clang here
		export CFLAGS="${CFLAGS/-fstack-clash-protection}"
		export CXXFLAGS="${CXXFLAGS/-fstack-clash-protection}"
		;;
	esac

	CC=clang \
	CXX=clang++ \
	CFLAGS="$CFLAGS -O2" \
	CXXFLAGS="$CXXFLAGS -O2" \
	LDFLAGS="$LDFLAGS -fuse-ld=lld" \
	abuild-meson \
		--buildtype=release \
		-Db_lto=true \
		-Db_ndebug=true \
		-Dprofiler=disabled \
		-Dinstalled_tests=false \
		output
	meson compile -C output
}

check() {
	# Tests can take a while on armv7
	xvfb-run -a meson test --print-errorlogs -C output -t 10
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

sha512sums="
359b1cc2e1ecb447cc0e2f5e4733e6a47ac5acf5b7ede1716045bde56f53fdbf15f4465227c7ea207a34190ce275486f9725f37080d678a51b0d2d5e9d7a1c9b  gjs-1.84.2.tar.xz
3524a4c6772f1be1d6e2320650d7fb9f81cc2ceb7c79c2521c0ee7a4202d5681a88586ab9439050611ee1719f9a977bb65d0eaaa536148e7e4590baf1f50eae8  encoding.patch
"
