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

# Autogenerated by pycargoebuild 0.15.1

EAPI=8

CRATES="
	addr2line@0.25.1
	adler2@2.0.1
	ahash@0.8.12
	allocator-api2@0.2.21
	android_system_properties@0.1.5
	anyhow@1.0.100
	async-lock@3.4.1
	async-trait@0.1.89
	atomic-waker@1.1.2
	autocfg@1.5.0
	backtrace@0.3.76
	base64@0.22.1
	bitflags@2.9.4
	block-buffer@0.10.4
	bumpalo@3.19.0
	bytes@1.11.1
	calcard@0.2.0
	camino@1.2.1
	cc@1.2.40
	cfg-if@1.0.3
	chrono-tz@0.10.4
	chrono@0.4.42
	colored@2.2.0
	concurrent-queue@2.5.0
	core-foundation-sys@0.8.7
	core-foundation@0.10.1
	cpufeatures@0.2.17
	crossbeam-channel@0.5.15
	crossbeam-epoch@0.9.18
	crossbeam-utils@0.8.21
	crypto-common@0.1.6
	deranged@0.5.4
	digest@0.10.7
	domain-macros@0.11.1
	domain@0.11.1
	encoding_rs@0.8.35
	equivalent@1.0.2
	errno@0.3.14
	event-listener-strategy@0.5.4
	event-listener@5.4.1
	fastrand@2.3.0
	find-msvc-tools@0.1.3
	fnv@1.0.7
	futures-channel@0.3.31
	futures-core@0.3.31
	futures-macro@0.3.31
	futures-task@0.3.31
	futures-util@0.3.31
	generic-array@0.14.7
	getrandom@0.2.16
	getrandom@0.3.3
	gimli@0.32.3
	hashbrown@0.14.5
	hashbrown@0.16.1
	hashify@0.2.8
	hex@0.4.3
	http-body-util@0.1.3
	http-body@1.0.1
	http@1.3.1
	httparse@1.10.1
	hyper-rustls@0.27.7
	hyper-util@0.1.20
	hyper@1.8.1
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.64
	indexmap@2.13.0
	inotify-sys@0.1.5
	inotify@0.11.0
	io-uring@0.7.10
	itoa@1.0.15
	jmap-tools@0.1.2
	js-sys@0.3.81
	lazy_static@1.5.0
	lexopt@0.3.1
	libc@0.2.176
	linux-raw-sys@0.11.0
	lock_api@0.4.14
	log@0.4.28
	mail-builder@0.4.4
	mail-parser@0.11.1
	memchr@2.7.6
	mime@0.3.17
	miniz_oxide@0.8.9
	mio@1.0.4
	moka@0.12.11
	num-conv@0.2.0
	num-traits@0.2.19
	object@0.37.3
	octseq@0.5.2
	once_cell@1.21.3
	openssl-probe@0.1.6
	parking@2.2.1
	parking_lot@0.12.5
	parking_lot_core@0.9.12
	phf@0.12.1
	phf_shared@0.12.1
	pin-project-lite@0.2.16
	pin-utils@0.1.0
	pkg-config@0.3.32
	portable-atomic@1.11.1
	powerfmt@0.2.0
	ppv-lite86@0.2.21
	proc-macro2@1.0.101
	quote@1.0.41
	r-efi@5.3.0
	rand@0.8.5
	rand@0.9.2
	rand_chacha@0.3.1
	rand_chacha@0.9.0
	rand_core@0.6.4
	rand_core@0.9.3
	redox_syscall@0.5.18
	ring@0.17.14
	roxmltree@0.21.1
	rustc-demangle@0.1.26
	rustc_version@0.4.1
	rustix@1.1.2
	rustls-native-certs@0.8.1
	rustls-pki-types@1.12.0
	rustls-webpki@0.103.10
	rustls@0.23.32
	rustversion@1.0.22
	ryu@1.0.20
	scfg@0.3.1
	schannel@0.1.28
	scopeguard@1.2.0
	security-framework-sys@2.15.0
	security-framework@3.5.1
	semver@1.0.27
	serde@1.0.228
	serde_core@1.0.228
	serde_derive@1.0.228
	serde_json@1.0.145
	sha1_smol@1.0.1
	sha2@0.10.9
	shell-words@1.1.0
	shlex@1.3.0
	simple_logger@5.0.0
	siphasher@1.0.1
	slab@0.4.11
	smallvec@1.15.1
	socket2@0.6.0
	sqlite3-src@0.7.0
	sqlite3-sys@0.18.0
	sqlite@0.37.0
	subtle@2.6.1
	syn@2.0.106
	sync_wrapper@1.0.2
	tagptr@0.2.0
	tempfile@3.23.0
	thiserror-impl@2.0.17
	thiserror@2.0.17
	time-core@0.1.8
	time@0.3.47
	tokio-macros@2.5.0
	tokio-rustls@0.26.4
	tokio@1.47.1
	tower-http@0.6.6
	tower-layer@0.3.3
	tower-service@0.3.3
	tower@0.5.2
	tracing-attributes@0.1.30
	tracing-core@0.1.34
	tracing@0.1.41
	try-lock@0.2.5
	typenum@1.19.0
	unicode-ident@1.0.19
	untrusted@0.9.0
	uuid@1.18.1
	version_check@0.9.5
	vparser@1.1.0
	want@0.3.1
	wasi@0.11.1+wasi-snapshot-preview1
	wasi@0.14.7+wasi-0.2.4
	wasip2@1.0.1+wasi-0.2.4
	wasm-bindgen-backend@0.2.104
	wasm-bindgen-macro-support@0.2.104
	wasm-bindgen-macro@0.2.104
	wasm-bindgen-shared@0.2.104
	wasm-bindgen@0.2.104
	windows-core@0.62.2
	windows-implement@0.60.2
	windows-interface@0.59.3
	windows-link@0.2.1
	windows-result@0.4.1
	windows-strings@0.5.1
	windows-sys@0.48.0
	windows-sys@0.52.0
	windows-sys@0.59.0
	windows-sys@0.61.2
	windows-targets@0.48.5
	windows-targets@0.52.6
	windows_aarch64_gnullvm@0.48.5
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_msvc@0.48.5
	windows_aarch64_msvc@0.52.6
	windows_i686_gnu@0.48.5
	windows_i686_gnu@0.52.6
	windows_i686_gnullvm@0.52.6
	windows_i686_msvc@0.48.5
	windows_i686_msvc@0.52.6
	windows_x86_64_gnu@0.48.5
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnullvm@0.48.5
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_msvc@0.48.5
	windows_x86_64_msvc@0.52.6
	wit-bindgen@0.46.0
	zerocopy-derive@0.8.27
	zerocopy@0.8.27
	zeroize@1.8.2
"

RUST_MIN_VER="1.88.0"
inherit cargo shell-completion systemd

DESCRIPTION="Synchronize calendars and contacts (vdirsyncer rewrite)"
HOMEPAGE="https://pimsync.whynothugo.nl/"
SRC_URI="
	https://git.sr.ht/~whynothugo/pimsync/archive/502de28545b345e3ebc447aebb66acc44eeb7dc3.tar.gz ->
		${PF}.tar.gz
	${CARGO_CRATE_URIS}
	https://git.sr.ht/~whynothugo/vstorage/archive/v0.7.0.tar.gz -> vstorage-0.7.0.tar.gz
	https://git.sr.ht/~whynothugo/libdav/archive/v0.10.3.tar.gz -> libdav-0.10.3.tar.gz
	https://git.sr.ht/~whynothugo/libjmap/archive/2fb17ed328d4d7692ffd64024f67e908c574c0a3.tar.gz ->
		libjmap-2fb17ed328d4d7692ffd64024f67e908c574c0a3.tar.gz
"
# this 0.5.8_pre20260401 ebuild is a snapshot ebuild for the latest commit
# on 2026-04-01, for the upcoming 0.5.8
#
# this was chosen as 0.5.7 contains a git dependency in the Cargo.toml,
# which contains a change which was PR'd
# (https://github.com/stalwartlabs/hashify/pull/5).
#
# i could not instantly get the git cargo dependency to work, but since the
# desired change has been implemented in the library
# (https://github.com/stalwartlabs/hashify/pull/5#issuecomment-4169550631),
# pimsync has reverted to upstream hashify. however, there has not been a
# release since, so here's a snapshot.
#
# SRC_URI ref:
#https://git.sr.ht/~whynothugo/pimsync/archive/v${PV}.tar.gz -> ${P}.tar.gz
# also:
#S="${WORKDIR}/${PN}-v${PV}"
S="${WORKDIR}/${PN}-502de28545b345e3ebc447aebb66acc44eeb7dc3"

# upstream asks for this, build script requires this
export PIMSYNC_VERSION="${PVR}+jacksonchen666-gentoo"

# https://pimsync.whynothugo.nl/install.html#requirements
# make is a @system dependency
DEPEND="
	dev-db/sqlite
	doc? (
		app-text/mandoc
		dev-python/sphinx
	)
"

LICENSE="EUPL-1.2"
# Dependent crate licenses
LICENSE+=" Apache-2.0 BSD ISC MIT MPL-2.0 Unicode-3.0"
SLOT="0"
KEYWORDS="~amd64"
IUSE="jmap doc lto"
# no mirrors available
RESTRICT="mirror"

src_configure() {
	local myfeatures=(
		$(usev jmap)
	)
	cargo_src_configure
}

src_prepare() {
	default

	if use lto; then
		sed -E -i 's/lto = .*/lto = true/' Cargo.toml || die
	else
		sed -E -i 's/lto = .*/lto = false/' Cargo.toml || die
	fi
}

src_unpack() {
	# this seems to unpack everything else too, even the other .tar.gz, even
	# though that won't be used as it's unpacked into directories
	# separately. that will be used in this ebuild
	cargo_src_unpack

	# due to 16fe0fc in upstream pimsync making the vstorage rust dependency
	# a git submodule, the same must be emulated (or it could be reverted
	# for whatever reason, but not sure about that).
	#
	# the submodules:
	# ./vstorage
	# ./vstorage/libdav
	# ./vstorage/libjmap (optional dependency, but cargo refuses to work
	#                     without it)
	cd "$S"
	rmdir vstorage
	mv "${WORKDIR}/vstorage-v0.7.0/" "vstorage/"

	cd "./vstorage"
	rmdir libdav libjmap
	mv "${WORKDIR}/libdav-v0.10.3" "libdav"
	mv "${WORKDIR}/libjmap-2fb17ed328d4d7692ffd64024f67e908c574c0a3" "libjmap"
}

src_compile() {
	cargo_src_compile
	if use doc; then
		emake docs
		HTML_DOCS="${S}/docs/build/html/"
	fi
}

src_install() {
	cargo_src_install
	doman pimsync.1
	doman pimsync.conf.5
	doman pimsync-migration.7
	dozshcomp contrib/_pimsync

	exeinto /etc/user/init.d
	newexe contrib/pimsync.openrc pimsync
	systemd_douserunit "${FILESDIR}/pimsync.service"

	if use doc; then
		einstalldocs
	fi
}

src_test() {
	local CARGO_SKIP_TESTS=(
		sync_vdir_to_xandikos_via_unix_socket # uses external program
	)
	cargo_src_test
}

# XXX: test jmap functionality
# TODO: linux-raw-sys
# TODO: inotify-sys