# Importada de Alpine aports por `hammer import-alpine` (Etapa G). PUNTO DE PARTIDA — pero
# YA trae los parches de musl de Alpine (lo que un import de nix pierde). Pendiente: el
# sha256 del tarball (el wrapper lo calcula), y adaptar build/install del shell de abuild.
name    = "typst"
version = "0.15.0"

[source]
tarball = "https://github.com/typst/typst/archive/refs/tags/v0.15.0.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "e7479cdbfd5f14efe1b8465c0c833117ec2bf60fa8a069d648c696dd452f855c8a6479196ba8dba57f90675a313005241ca86a706863109c1acd6d9580d43732"
sha256  = "5044bd12138491c6e880df0e09056a9ae4607d937c73962d5806402ae6ee96a6"

[build]
compiler = "zig-cc"
target   = "x86_64-linux-musl"
link     = "static"
flags    = []

[build.phases]
# de build() de Alpine (traducido; el lab provee $CBUILD/$CHOST — Etapa G Fase 3; revisá --shared para estático):
compile = '''
_abuild_phase() {
# 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=0.15.0 \
		cargo auditable build --release --frozen -p typst-cli
}
_abuild_phase
'''
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
_abuild_phase() {
install -Dm755 target/release/typst \
		-t "/out"/usr/bin/

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

[deps]
build = ["openssl"]
