# Maintainer: lauren n. liberda <lauren@selfisekai.rocks>
pkgname=typst
pkgver=0.12.0
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"

prepare() {
	default_prepare
	cargo add libc@0.2.155 time@0.3.35
	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="
46fbd83c33e2ef8b2d99b767b15fc683ac2ec1a88d7de0ac1b572d250d0c8f5590cd79a0f2105ee31d631ef6efc8c983bd246f604baca7b3b10c519cc108852a  typst-0.12.0.tar.gz
"
