# Maintainer: lauren n. liberda <lauren@selfisekai.rocks>
pkgname=typst
pkgver=0.11.1
pkgrel=0
pkgdesc="New markup-based typesetting system that is powerful and easy to learn"
url="https://github.com/typst/typst"
# s390x: 90% of tests fail due to endianness
# armhf: fails build
# s390x, ppc64le, riscv64: ring
arch="all !s390x !ppc64le !riscv64 !armhf"
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
	cargo-update.patch
	"
options="net"

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="
ddae20f2cf77517447d9f79aec45d27fd60422defa381d50bd148b08450749d4f8ebb143d0c136c30ac47c1d2db0e07fcf8146eef73f59b4cc3290972871765c  typst-0.11.1.tar.gz
eab21d0d0e058ca3c3446c5bd04a5b1ade597d37148de3d84af42f628204ed0dfa591dad1fcf2ce61303a3ee1efc2344df0edd23b00defb26900d1f197945cbc  cargo-update.patch
"