# 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    = "helix"
version = "25.07.1"

[source]
tarball = "https://github.com/helix-editor/helix/archive/25.07.1/helix-25.07.1.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "a8f64782273d88cd43b1aeadf45d1fa6a913c9c0b77c1da716ffdc64ec02e89db1bfb2dde4333509c3ddb5733b8f5a450b44ca54d35f113c3c0f411c01f4ce8c"
sha256  = "27c8bc3eba46bc7bab1e3629c6b28ff94882eeff17366b3ea69cd8ceffba7541"
patches = ["fix-gotmpl-grammar-source.patch"]

# GUETO gcc: helix trae tree-house-bindings (tree-sitter en C); cc-rs hace detección de familia
# de compilador con `zig -E` y zig la rechaza. compiler="gcc" usa el musl gcc de Alpine.
[build]
compiler = "gcc"
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() {
# This path is embedded in the resulting binary so that helix can find
	# system grammars
	# https://github.com/helix-editor/helix/blob/25.01.1/helix-loader/src/lib.rs#L64
	export HELIX_DEFAULT_RUNTIME=/usr/share/helix/runtime
	# Sandbox hermético: helix-term/build.rs intenta `git clone` de 245 gramáticas tree-sitter
	# (sin red ⇒ panic). Lo desactivamos; las gramáticas van por runtime/ (build post-install).
	export HELIX_DISABLE_AUTO_GRAMMAR_BUILD=1
	# de-Alpinizado: cargo-auditable no está en el lab de hammer; build plano (Etapa G)
	cargo build --frozen --release
}
_abuild_phase
'''
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
_abuild_phase() {
install -D -m755 target/release/hx -t "/out"/usr/bin/

	install -D -m644 contrib/completion/hx.bash "/out"/usr/share/bash-completion/completions/hx
	install -D -m644 contrib/completion/hx.fish "/out"/usr/share/fish/vendor_completions.d/hx.fish
	install -D -m644 contrib/completion/hx.zsh "/out"/usr/share/zsh/site-functions/_hx

	install -D -m644 contrib/Helix.desktop -t "/out"/usr/share/applications/
	install -D -m644 logo.svg "/out"/usr/share/icons/hicolor/scalable/apps/Helix.svg

	install -d -m755 "/out"/usr/share/"helix"

	rm runtime/grammars/.gitkeep
	rm runtime/themes/README.md
	rm -rf runtime/grammars/sources
	cp -r runtime "/out"/usr/share/"helix"
}
_abuild_phase
'''
