maintainer="Dominic <git@msrd0.de>"
pkgname=hickory-dns
pkgver=0.25.2
pkgrel=0
pkgdesc="A safe and secure DNS server with DNSSEC support"
url="https://hickory-dns.org/"
arch="all"
license="Apache-2.0 OR MIT"
makedepends="cargo cargo-auditable clang-dev cmake"
checkdepends="bind"
subpackages="
	$pkgname-openrc
	$pkgname-utils:_util
	"
source="https://github.com/hickory-dns/hickory-dns/archive/refs/tags/v$pkgver/hickory-dns-$pkgver.tar.gz
	compatibility-tests.patch
	example-config.patch
	$pkgname.initd
	$pkgname.confd
	"
install="$pkgname.pre-install"

# net: needed for downloading dependencies
options="net"

# we disable default features: it enables ascii-art and the comment says to disable to reduce size
# we use aws-lc-rs as crypto provider because it supports more architectures
_crypto=aws-lc-rs
_cargo_opts="
	--release --frozen --no-default-features
	--features h3-$_crypto,https-$_crypto,quic-$_crypto,tls-$_crypto,dnssec-$_crypto,rustls-platform-verifier"
_cargo_opts_bin="$_cargo_opts,blocklist,recursor,resolver"

# the default config wants zones in /var/named but packages shouldn't write to /var
# so we change the zone dir to /usr/share/hickory-dns/example for the example config
_zonedir=/usr/share/doc/hickory-dns/examples

prepare() {
	default_prepare
	sed -E -i -e "s,\\\$_zonedir,$_zonedir,g" tests/test-data/test_configs/example.toml

	# no --target: https://github.com/rust-lang/cargo/issues/15399
	cargo fetch --locked #--target="$CTARGET"
}

build() {
	cargo auditable build -p hickory-dns  --target="$CTARGET" $_cargo_opts_bin
	cargo auditable build -p hickory-util --target="$CTARGET" $_cargo_opts
}

check() {
	# test hickory-dns separately: we enable more features than available in the other crates
	cargo test -p hickory-dns $_cargo_opts_bin
	TARGET_DIR="$PWD/target" \
	cargo test --workspace --exclude hickory-dns $_cargo_opts
}

package() {
	install -Dm755 target/$CTARGET/release/$pkgname -t "$pkgdir"/usr/bin/

	install -Dm644 tests/test-data/test_configs/example.toml "$pkgdir"/etc/named.toml
	install -Dm644 tests/test-data/test_configs/example.com.zone -t "$pkgdir$_zonedir"
	install -Dm644 tests/test-data/test_configs/include.example.com.zone -t "$pkgdir$_zonedir"
	for zone in localhost 127.0.0.1 ipv6_1 255 0
	do
		install -Dm644 tests/test-data/test_configs/default/$zone.zone -t "$pkgdir$_zonedir/default"
	done

	install -D -m755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -D -m644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
}

_util() {
	for bin in dns recurse resolve
	do
		install -Dm755 "$builddir"/target/$CTARGET/release/$bin -t "$subpkgdir"/usr/bin/
	done
}

sha512sums="
809ac185a751a42d8adba8eb0b620382570086add53552801368ff304d34b3275d277308a64d9f7e7bdb0d0a699f46c72339c9478c82f3ef84c1cd19fcc49530  hickory-dns-0.25.2.tar.gz
52b7892a0c4f555165fd547609056bc150b83f2635d08d244092129e25282994fcb26c62dea46df0393ce0084901bda63c497a5d30ca32f8004c21ccead31150  compatibility-tests.patch
b488685a7d6bd65a6bb7270d0583789b885d2f8bf592e21612e6c4788f18d07dd157cde444de01c7a149f9fc85975c3308f7d12ba7c80bde559962869b7cfa45  example-config.patch
6c8952afc8d0f3ae0011bf8bd4b4c63c70093681fdff38994a129d77a32df4517855fd36cc5776cbfffd86d8baf4b498a6432db4af0a0c6421f2df560b18e374  hickory-dns.initd
1ca2464264d938f880460a27dc92325a30fa35c26461bf69dba2f17849b2d6450ba3bec704ead19148daf06f882c2d60f99dc8f970d0229e62040b793aca9517  hickory-dns.confd
"
