# 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-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.12.0
	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
	chacha20@0.10.0
	chrono-tz@0.10.4
	chrono@0.4.42
	colored@2.2.0
	const-oid@0.10.2
	core-foundation-sys@0.8.7
	core-foundation@0.10.1
	cpufeatures@0.3.0
	crypto-common@0.2.1
	digest@0.11.2
	domain-macros@0.12.0
	domain@0.12.0
	encoding_rs@0.8.35
	equivalent@1.0.2
	errno@0.3.14
	fastrand@2.3.0
	find-msvc-tools@0.1.3
	fnv@1.0.7
	foldhash@0.1.5
	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
	getrandom@0.2.16
	getrandom@0.3.3
	getrandom@0.4.2
	gimli@0.32.3
	hashbrown@0.15.5
	hashbrown@0.16.1
	hashbrown@0.17.0
	hashify@0.2.8
	heck@0.5.0
	hex@0.4.3
	http-body-util@0.1.3
	http-body@1.0.1
	http@1.3.1
	httparse@1.10.1
	hybrid-array@0.4.10
	hyper-rustls@0.27.7
	hyper-util@0.1.20
	hyper@1.9.0
	iana-time-zone-haiku@0.1.2
	iana-time-zone@0.1.64
	id-arena@2.3.0
	indexmap@2.13.0
	inotify-sys@0.1.5
	inotify@0.11.0
	io-uring@0.7.10
	itoa@1.0.15
	jiff-static@0.2.24
	jiff@0.2.24
	jmap-tools@0.1.2
	js-sys@0.3.81
	lazy_static@1.5.0
	leb128fmt@0.1.0
	lexopt@0.3.1
	libc@0.2.176
	libdav@0.10.5
	libjmap@0.1.1
	linux-raw-sys@0.11.0
	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
	num-traits@0.2.19
	object@0.37.3
	octseq@0.6.1
	once_cell@1.21.3
	openssl-probe@0.1.6
	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-util@0.2.7
	portable-atomic@1.11.1
	prettyplease@0.2.37
	proc-macro2@1.0.101
	quote@1.0.41
	r-efi@5.3.0
	r-efi@6.0.0
	rand@0.10.1
	rand_core@0.10.1
	ring@0.17.14
	roxmltree@0.21.1
	rustc-demangle@0.1.26
	rustix@1.1.2
	rustls-native-certs@0.8.1
	rustls-pki-types@1.12.0
	rustls-webpki@0.103.13
	rustls@0.23.32
	rustversion@1.0.22
	ryu@1.0.20
	scfg@0.3.1
	schannel@0.1.28
	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.11.0
	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
	tempfile@3.23.0
	thiserror-impl@2.0.17
	thiserror@2.0.17
	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
	unicode-xid@0.2.6
	untrusted@0.9.0
	uuid@1.18.1
	version_check@0.9.5
	vparser@1.1.0
	vstorage@0.8.1
	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
	wasip3@0.4.0+wasi-0.3.0-rc-2026-01-06
	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
	wasm-encoder@0.244.0
	wasm-metadata@0.244.0
	wasmparser@0.244.0
	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-core@0.51.0
	wit-bindgen-rust-macro@0.51.0
	wit-bindgen-rust@0.51.0
	wit-bindgen@0.46.0
	wit-bindgen@0.51.0
	wit-component@0.244.0
	wit-parser@0.244.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/v${PV}.tar.gz -> ${P}.tar.gz
	${CARGO_CRATE_URIS}
"
# SRC_URI only strictly needed for any dev/commits in between releases builds.
# also must match what upstream is using at the exact commit
#https://git.sr.ht/~whynothugo/vstorage/archive/f77520288df1a2c439bbe578289aa8c3f2c2b972.tar.gz ->
#	vstorage-f77520288df1a2c439bbe578289aa8c3f2c2b972.tar.gz
#https://git.sr.ht/~whynothugo/libdav/archive/v0.10.4.tar.gz -> libdav-0.10.4.tar.gz
#https://git.sr.ht/~whynothugo/libjmap/archive/2fb17ed328d4d7692ffd64024f67e908c574c0a3.tar.gz ->
#	libjmap-2fb17ed328d4d7692ffd64024f67e908c574c0a3.tar.gz
S="${WORKDIR}/${PN}-v${PV}"

# 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
"
BDEPEND="
	doc? (
		app-text/mandoc
		dev-python/sphinx
	)
"

LICENSE="EUPL-1.2"
# Dependent crate licenses
LICENSE+=" Apache-2.0 BSD EUPL-1.2 ISC MIT MPL-2.0 Unicode-3.0 ZLIB"
SLOT="0"
KEYWORDS="~amd64"
IUSE="jmap doc lto"
# while there's no mirror for pimsync, there's probably gonna be a mirror on
# everything. crates.io is also slower than gentoo mirrors, so it's annoying
# to disable mirrors
#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
}

# only strictly needed for any dev/commits in between releases builds
#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 || die
#	mv "${WORKDIR}/vstorage-"* "vstorage/" || die
#
#	cd "./vstorage"
#	rmdir libdav libjmap || die
#	mv "${WORKDIR}/libdav-"* "libdav" || die
#	mv "${WORKDIR}/libjmap-"* "libjmap" || die
#}

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