# 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    = "etcd"
version = "3.6.11"

[source]
tarball = "https://github.com/etcd-io/etcd/archive/refs/tags/v3.6.11.tar.gz"
# FIXME sha256: el wrapper lo calcula (Alpine publica sha512). sha512 de Alpine:
# sha512 = "56423c42443d9d1d2d06ff28aff389a381ed9b726cbee0d3523ac34fe2a8e22029377a42aa808077bb985f524a153c5fe63fd6166857749e8217b705fdf41910"
sha256  = "bdc9b21505f4587c81f33235b53b3cb02f28158eb3487ae158f90b9534f0c0f3"

[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() {
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
	export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
	export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"
	export GOFLAGS="$GOFLAGS -mod=mod"
	export CGO_ENABLED=1
	export FORCE_HOST_GO=1

	GIT_SHA="$(git ls-remote https://github.com/coreos/etcd.git refs/tags/v3.6.11 | awk '{print $1}')" \
		make
}
_abuild_phase
'''
# de package() de Alpine (traducido $pkgdir→/out):
install = '''
_abuild_phase() {
install -d -o "$pkgusers" -g "$pkggroups" -m 700 "/out"/var/lib/etcd
	install -Dm755 bin/etcd "/out"/usr/bin/etcd
	install -Dm755 bin/etcdctl "/out"/usr/bin/etcdctl
	install -Dm644 $srcdir/etcd.yaml "/out"/etc/etcd/conf.yml
	install -Dm644 $srcdir/etcd.confd "/out"/etc/conf.d/etcd
	install -Dm755 $srcdir/etcd.initd "/out"/etc/init.d/etcd
	install -Dm644 LICENSE "/out"/usr/share/licenses/etcd/LICENSE
}
_abuild_phase
'''

[deps]
build = ["bash"]
