maintainer="lauren n. liberda <lauren@selfisekai.rocks>"
pkgname=typst
pkgver=0.13.1
pkgrel=0
pkgdesc="New markup-based typesetting system that is powerful and easy to learn"
url="https://github.com/typst/typst"
# armhf: fails build
# riscv64: fails test
# s390x: 90% of tests fail due to endianness
arch="all !armhf !riscv64 !s390x"
license="Apache-2.0"
makedepends="
	cargo
	cargo-auditable
	openssl-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/typst/typst/archive/refs/tags/v$pkgver.tar.gz
	"
options="net"

case "$CARCH" in
	armv7|x86)
		# Regularly has tests failing due to usize overflow.
		options="$options !check"
		;;
	*)
		;;
esac

prepare() {
	default_prepare
	cargo fetch --target="$CTARGET" --locked
}

build() {
	# XXX: it vendors 5MB of fonts, but the font detection is kinda
	# broken and it won't find math symbols from system fonts correctly
	# (when you have a lot of fonts it seems?)
	# so, just keep them vendored-in for now. when fixed, add
	# --no-default-features
	GEN_ARTIFACTS="./gen" \
	TYPST_VERSION=$pkgver \
		cargo auditable build --release --frozen -p typst-cli
}

check() {
	cargo test --frozen --all
}

package() {
	install -Dm755 target/release/typst \
		-t "$pkgdir"/usr/bin/

	install -Dm644 ./crates/typst-cli/gen/typst.bash "$pkgdir"/usr/share/bash-completion/completions/typst
	install -Dm644 ./crates/typst-cli/gen/typst.fish "$pkgdir"/usr/share/fish/vendor_completions.d/typst.fish
	install -Dm644 ./crates/typst-cli/gen/_typst "$pkgdir"/usr/share/zsh/site-functions/_typst
	install -Dm644 ./crates/typst-cli/gen/*.1 -t "$pkgdir"/usr/share/man/man1/
}

sha512sums="
13f6deac7b7bb642754f8196d9b05b6d5bb7969b289eae76430377ad0e1613cd03769212eb0cdba1fa063896bbe5dc5c08042626bbdd5c646aca914b7d0a0fae  typst-0.13.1.tar.gz
"
