# Copyright 2026 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

# Autogenerated by pycargoebuild 0.17.1

EAPI=8

CRATES="
"

inherit cargo systemd

MY_PV="${PV/_rc/-rc.}"
MY_P="${PN}-${MY_PV}"

ARGON2_COMMIT="f57e61e19229e23c4445b85494dbf7c07de721cb"
OTEL_COMMIT="0e66a7c05a693204fa5e9660659e224017f431c5"

DESCRIPTION="A fast, modern web server built for production debugging"
HOMEPAGE="https://ferron.sh"
SRC_URI="
	https://github.com/ferronweb/ferron/archive/refs/tags/${MY_PV}.tar.gz -> ${P}.tar.gz
	https://github.com/P-H-C/phc-winner-argon2/archive/${ARGON2_COMMIT}.tar.gz -> phc-winner-argon2-${ARGON2_COMMIT}.tar.gz
	https://github.com/open-telemetry/opentelemetry-proto/archive/${OTEL_COMMIT}.tar.gz -> opentelemetry-proto-${OTEL_COMMIT}.tar.gz
	${CARGO_CRATE_URIS}
"
if [[ ${PKGBUMPING} != ${PVR} ]]; then
	SRC_URI+="
		https://gentoo.adlevio.net/ferron-3.0.0-rc.11-crates.tar.xz
	"
fi

S="${WORKDIR}/${MY_P}"

LICENSE="MIT"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 BSD Boost-1.0 CC0-1.0 CDLA-Permissive-2.0 ISC MIT MPL-2.0
	openssl Unicode-3.0 ZLIB
"
SLOT="0"
KEYWORDS="~amd64"

RDEPEND="
	acct-group/ferron
	acct-user/ferron
"

src_prepare() {
	rm -rf "${S}/modules/http-basicauth/phc-winner-argon2" "${S}/modules/observability-otlp/opentelemetry-proto"
	mv "${WORKDIR}/phc-winner-argon2-${ARGON2_COMMIT}" "${S}/modules/http-basicauth/phc-winner-argon2" || die
	mv "${WORKDIR}/opentelemetry-proto-${OTEL_COMMIT}" "${S}/modules/observability-otlp/opentelemetry-proto" || die

	(
		cd "${ECARGO_VENDOR}/zincio-0.2.27" || die
		eapply "${FILESDIR}/zincio-0.2.27-musl-statx.patch"
	)

	default
}

src_install() {
	for bin in ferron{,-{fmt,kdl2ferron,passwd,precompress,serve}}; do
		dobin "$(cargo_target_dir)/${bin}"
	done

	newinitd "${FILESDIR}/ferron.initd" ferron
	systemd_dounit "${FILESDIR}/ferron.service"
}