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

EAPI=8

RUST_MIN_VER="1.99.0"

inherit cargo

DESCRIPTION="JMAP account migration utility"
HOMEPAGE="https://github.com/stalwartlabs/vandelay"
SRC_URI="
	https://github.com/stalwartlabs/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
	https://github.com/gentoo-zh-drafts/${PN}/releases/download/v${PV}/${P}-crates.tar.xz
"

# Upstream also offers the proprietary Stalwart Enterprise License.
LICENSE="AGPL-3"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD CDLA-Permissive-2.0
	ISC MIT MPL-2.0 Unicode-3.0 Unicode-DFS-2016 WTFPL-2 ZLIB
"
SLOT="0"
KEYWORDS="~amd64 ~arm64"
# The tests live in an unpublished vandelay-tests repository
RESTRICT="test"

DEPEND="dev-db/sqlite:3"
RDEPEND="${DEPEND}"
BDEPEND="virtual/pkgconfig"

src_prepare() {
	default
	# link the system sqlite; the binary has no feature to turn this off
	sed -i 's/^default = \["bundled-sqlite"\]$/default = []/' \
		crates/engine/Cargo.toml || die
}

src_install() {
	cargo_src_install --path crates/vandelay
	dodoc README.md CHANGELOG.md
}