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

EAPI=8

CRATES="
	aead@0.5.2
	aes-siv@0.7.0
	aes@0.8.4
	anyhow@1.0.102
	arbitrary@1.4.2
	async-trait@0.1.89
	autocfg@1.5.1
	aws-lc-rs@1.17.0
	aws-lc-sys@0.41.0
	bitflags@2.13.0
	block-buffer@0.10.4
	bumpalo@3.20.3
	bytes@1.11.1
	cc@1.2.63
	cesu8@1.1.0
	cfg-if@1.0.4
	chacha20@0.10.0
	cipher@0.4.4
	clock-steering@0.2.1
	cmac@0.7.2
	cmake@0.1.58
	combine@4.6.7
	core-foundation-sys@0.8.7
	core-foundation@0.10.1
	core-foundation@0.9.4
	cpufeatures@0.2.17
	cpufeatures@0.3.0
	critical-section@1.2.0
	crossbeam-channel@0.5.15
	crossbeam-epoch@0.9.18
	crossbeam-utils@0.8.21
	crypto-common@0.1.7
	ctr@0.9.2
	data-encoding@2.11.0
	dbl@0.3.2
	deranged@0.5.8
	digest@0.10.7
	displaydoc@0.2.6
	dunce@1.0.5
	either@1.16.0
	equivalent@1.0.2
	errno@0.3.14
	find-msvc-tools@0.1.9
	foldhash@0.1.5
	foreign-types-shared@0.1.1
	foreign-types@0.3.2
	form_urlencoded@1.2.2
	fs_extra@1.3.0
	futures-channel@0.3.32
	futures-core@0.3.32
	futures-io@0.3.32
	futures-macro@0.3.32
	futures-task@0.3.32
	futures-util@0.3.32
	generic-array@0.14.7
	getrandom@0.2.17
	getrandom@0.3.3
	getrandom@0.4.2
	hashbrown@0.15.5
	hashbrown@0.17.0
	heck@0.5.0
	hickory-net@0.26.1
	hickory-proto@0.26.1
	hickory-resolver@0.26.1
	icu_collections@2.2.0
	icu_locale_core@2.2.0
	icu_normalizer@2.2.0
	icu_normalizer_data@2.2.0
	icu_properties@2.2.0
	icu_properties_data@2.2.0
	icu_provider@2.2.0
	id-arena@2.3.0
	idna@1.1.0
	idna_adapter@1.2.2
	indexmap@2.14.0
	inout@0.1.4
	ipconfig@0.3.4
	ipnet@2.12.0
	itoa@1.0.18
	jni-macros@0.22.4
	jni-sys-macros@0.4.1
	jni-sys@0.3.1
	jni-sys@0.4.1
	jni@0.21.1
	jni@0.22.4
	jobserver@0.1.34
	js-sys@0.3.100
	lazy_static@1.5.0
	leb128fmt@0.1.0
	libc@0.2.186
	linked-hash-map@0.5.6
	litemap@0.8.2
	lock_api@0.4.14
	log@0.4.32
	lru-cache@0.1.2
	md-5@0.10.6
	memchr@2.8.1
	mio@1.2.1
	moka@0.12.15
	ndk-context@0.1.1
	nu-ansi-term@0.50.3
	num-conv@0.2.2
	num-traits@0.2.19
	once_cell@1.21.4
	openssl-macros@0.1.1
	openssl-probe@0.2.1
	openssl-src@300.6.1+3.6.3
	openssl-sys@0.9.116
	openssl@0.10.80
	parking_lot@0.12.5
	parking_lot_core@0.9.12
	percent-encoding@2.3.2
	pin-project-lite@0.2.17
	pkg-config@0.3.33
	portable-atomic@1.13.1
	potential_utf@0.1.5
	powerfmt@0.2.0
	pps-time@0.2.3
	ppv-lite86@0.2.21
	prefix-trie@0.8.4
	prettyplease@0.2.37
	proc-macro2@1.0.106
	quote@1.0.45
	r-efi@5.3.0
	r-efi@6.0.0
	rand@0.10.1
	rand@0.8.6
	rand_chacha@0.3.1
	rand_core@0.10.1
	rand_core@0.6.4
	redox_syscall@0.5.18
	resolv-conf@0.7.6
	ring@0.17.14
	rustc_version@0.4.1
	rustls-native-certs@0.8.4
	rustls-openssl@0.3.1
	rustls-pki-types@1.14.1
	rustls-platform-verifier-android@0.1.1
	rustls-platform-verifier@0.5.3
	rustls-webpki@0.103.13
	rustls@0.23.40
	rustversion@1.0.22
	same-file@1.0.6
	schannel@0.1.29
	scopeguard@1.2.0
	security-framework-sys@2.17.0
	security-framework@3.7.0
	semver@1.0.28
	serde@1.0.228
	serde_core@1.0.228
	serde_derive@1.0.228
	serde_json@1.0.150
	serde_spanned@0.6.9
	serde_test@1.0.177
	sharded-slab@0.1.7
	shlex@2.0.1
	signal-hook-registry@1.4.8
	simd_cesu8@1.1.1
	simdutf8@0.1.5
	slab@0.4.12
	smallvec@1.15.1
	socket2@0.6.4
	stable_deref_trait@1.2.1
	subtle@2.6.1
	syn@2.0.117
	synstructure@0.13.2
	system-configuration-sys@0.6.0
	system-configuration@0.7.0
	tagptr@0.2.0
	thiserror-impl@1.0.69
	thiserror-impl@2.0.18
	thiserror@1.0.69
	thiserror@2.0.18
	thread_local@1.1.9
	time-core@0.1.8
	time@0.3.47
	timestamped-socket@0.2.8
	tinystr@0.8.3
	tinyvec@1.11.0
	tinyvec_macros@0.1.1
	tokio-macros@2.7.0
	tokio-rustls@0.26.4
	tokio@1.52.3
	toml@0.8.23
	toml_datetime@0.6.11
	toml_edit@0.22.27
	tracing-attributes@0.1.31
	tracing-core@0.1.36
	tracing-subscriber@0.3.23
	tracing@0.1.44
	typenum@1.20.1
	unicode-ident@1.0.24
	unicode-xid@0.2.6
	untrusted@0.7.1
	untrusted@0.9.0
	url@2.5.8
	utf8_iter@1.0.4
	uuid@1.23.3
	vcpkg@0.2.15
	version_check@0.9.5
	walkdir@2.5.0
	wasi@0.11.1+wasi-snapshot-preview1
	wasi@0.14.2+wasi-0.2.4
	wasip2@1.0.3+wasi-0.2.9
	wasip3@0.4.0+wasi-0.3.0-rc-2026-01-06
	wasm-bindgen-macro-support@0.2.123
	wasm-bindgen-macro@0.2.123
	wasm-bindgen-shared@0.2.123
	wasm-bindgen@0.2.123
	wasm-encoder@0.244.0
	wasm-metadata@0.244.0
	wasmparser@0.244.0
	webpki-root-certs@0.26.11
	webpki-root-certs@1.0.1
	widestring@1.2.1
	winapi-util@0.1.11
	windows-link@0.2.1
	windows-registry@0.6.1
	windows-result@0.4.1
	windows-strings@0.5.1
	windows-sys@0.45.0
	windows-sys@0.52.0
	windows-sys@0.61.1
	windows-targets@0.42.2
	windows-targets@0.52.6
	windows_aarch64_gnullvm@0.42.2
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_msvc@0.42.2
	windows_aarch64_msvc@0.52.6
	windows_i686_gnu@0.42.2
	windows_i686_gnu@0.52.6
	windows_i686_gnullvm@0.52.6
	windows_i686_msvc@0.42.2
	windows_i686_msvc@0.52.6
	windows_x86_64_gnu@0.42.2
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnullvm@0.42.2
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_msvc@0.42.2
	windows_x86_64_msvc@0.52.6
	winnow@0.7.15
	wit-bindgen-core@0.51.0
	wit-bindgen-rt@0.39.0
	wit-bindgen-rust-macro@0.51.0
	wit-bindgen-rust@0.51.0
	wit-bindgen@0.51.0
	wit-bindgen@0.57.1
	wit-component@0.244.0
	wit-parser@0.244.0
	writeable@0.6.3
	yoke-derive@0.8.2
	yoke@0.8.3
	zerocopy-derive@0.8.52
	zerocopy@0.8.52
	zerofrom-derive@0.1.7
	zerofrom@0.1.8
	zeroize@1.8.2
	zerotrie@0.2.4
	zerovec-derive@0.11.3
	zerovec@0.11.6
	zmij@1.0.21
"

RUST_MIN_VER="1.88.0"

inherit cargo systemd

DESCRIPTION="Full-featured implementation of NTP with NTS support"
HOMEPAGE="https://github.com/pendulum-project/ntpd-rs"
SRC_URI="
	https://github.com/pendulum-project/${PN}/archive/v${PV}.tar.gz -> ${P}.tar.gz
	${CARGO_CRATE_URIS}
"

# Dual-licensed: the user may pick either license for ntpd-rs itself.
LICENSE="|| ( Apache-2.0 MIT )"
# Dependent crate licenses (generated from Cargo.lock via pycargoebuild)
LICENSE+=" Apache-2.0 BSD BSD-2 Boost-1.0 CDLA-Permissive-2.0 ISC MIT MPL-2.0 Unicode-3.0 ZLIB"
SLOT="0"
KEYWORDS="~amd64 ~arm64"
# NTS (RFC 8915) is always built in via rustls with the aws-lc-rs backend,
# which also enables post-quantum key exchange (prefer-post-quantum) for NTS-KE.
DEPEND="
	acct-group/ntpd-rs
	acct-group/ntpd-rs-observe
	acct-user/ntpd-rs
	acct-user/ntpd-rs-observe
"
RDEPEND="${DEPEND}"
BDEPEND="
	dev-build/cmake
	virtual/pkgconfig
"

# rust does not use *FLAGS from make.conf, silence portage QA warning
QA_FLAGS_IGNORED="usr/bin/ntp-.*"

src_configure() {
	# Build only the ntpd workspace member (provides all three binaries:
	# ntp-daemon, ntp-ctl, ntp-metrics-exporter).
	cargo_src_configure --package ntpd
}

src_install() {
	local tdir
	tdir="$(cargo_target_dir)"
	dobin "${tdir}"/ntp-daemon
	dobin "${tdir}"/ntp-ctl
	dobin "${tdir}"/ntp-metrics-exporter

	# Precompiled man pages shipped by upstream.
	doman docs/precompiled/man/ntp-ctl.8
	doman docs/precompiled/man/ntp-daemon.8
	doman docs/precompiled/man/ntp-metrics-exporter.8
	doman docs/precompiled/man/ntp.toml.5

	# Example configuration installed as a normal (CONFIG_PROTECT) config file.
	insinto /etc/ntpd-rs
	newins docs/examples/conf/ntp.toml.default ntp.toml

	# systemd units (systemd-only service integration).
	systemd_dounit docs/examples/conf/ntpd-rs.service
	systemd_dounit docs/examples/conf/ntpd-rs-metrics.service

	insinto /usr/lib/systemd/system-preset
	newins docs/examples/conf/ntpd-rs.preset 50-ntpd-rs.preset

	dodoc CHANGELOG.md README.md COPYRIGHT
	einstalldocs
}