# Copyright 2024-2025 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Autogenerated by pycargoebuild 0.13.2

EAPI=8

RUST_MIN_VER="1.88"

CRATES="
"

inherit cargo shell-completion

DESCRIPTION="A markup-based typesetting system for the sciences"
HOMEPAGE="https://typst.app"
SRC_URI="
	https://github.com/${PN}/${PN}/archive/v${PV}/${P}.tar.gz
	https://github.com/odrling/typst/releases/download/v${PV}/typst-vendor.tar.xz -> ${P}-vendor.tar.xz
"

LICENSE="Apache-2.0"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 BSD-2 BSD Boost-1.0 CC0-1.0 ISC MIT MPL-2.0 UoI-NCSA
	Unicode-3.0 ZLIB
"
SLOT="0"
KEYWORDS="~amd64 ~arm64"

RDEPEND="
	>=dev-libs/openssl-1.0.2o-r6:0=
"
DEPEND="${RDEPEND}"

QA_FLAGS_IGNORED="usr/bin/typst"

DOCS=( README.md )

ECARGO_VENDOR="${WORKDIR}/vendor"

src_prepare() {
	# to ignore git repo for typst-dev-assets
	sed -i 's/^typst-dev-assets.*$/typst-dev-assets = "*"/' Cargo.toml || die

	default
}

src_compile() {
	local GIT_HASH=$(gunzip < "${DISTDIR}/${P}.tar.gz" | git get-tar-commit-id)
	export TYPST_VERSION="${PV} (${GIT_HASH::8})"
	export GEN_ARTIFACTS="artifacts/"

	cargo_src_compile
}

src_install() {
	local ARTIFACTSDIR='crates/typst-cli/artifacts'
	cargo_src_install --path "${S}/crates/typst-cli"
	doman "${ARTIFACTSDIR}/${PN}"*.1
	dozshcomp "${ARTIFACTSDIR}/_${PN}"
	dofishcomp "${ARTIFACTSDIR}/${PN}.fish"
	newbashcomp "${ARTIFACTSDIR}/${PN}.bash" "${PN}"

	einstalldocs
}

src_test() {
	cargo_src_test --workspace
}