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

# Autogenerated by pycargoebuild 0.13.4

EAPI=8

CRATES="
"

declare -A GIT_CRATES=(
	[boring-noise]='https://github.com/Watfaq/boring-noise;1f57e8830ea2aea09c3b2f2d990bf3097ceb1bf5;boring-noise-%commit%'
	[netstack-lwip]='https://github.com/eycorsican/netstack-lwip;f434fefd6c227c9dfbec84c364452ba6c1532779;netstack-lwip-%commit%'
	[quinn-proto]='https://github.com/spongebob888/quinn-jls;3364498f3376432dc8d27ed2fb74b4695506288c;quinn-jls-%commit%/quinn-proto'
	[quinn-udp]='https://github.com/spongebob888/quinn-jls;3364498f3376432dc8d27ed2fb74b4695506288c;quinn-jls-%commit%/quinn-udp'
	[quinn]='https://github.com/spongebob888/quinn-jls;3364498f3376432dc8d27ed2fb74b4695506288c;quinn-jls-%commit%/quinn'
	[rustls]='https://github.com/spongebob888/rustls-jls;70e0553c809ae4a6a3eb1229e864f20d4fc5e611;rustls-jls-%commit%/rustls'
	[shadowquic-macros]='https://github.com/spongebob888/shadowquic;cb6f3f258e798b7572138071642a9455851b30c7;shadowquic-%commit%/shadowquic-macros'
	[shadowquic]='https://github.com/spongebob888/shadowquic;cb6f3f258e798b7572138071642a9455851b30c7;shadowquic-%commit%/shadowquic'
	[smoltcp]='https://github.com/smoltcp-rs/smoltcp;ac32e643a4b7e09161193071526b3ca5a0deedb5;smoltcp-%commit%'
	[tokio-watfaq-rustls]='https://github.com/Watfaq/tokio-rustls;638db32084d7ecf9c2660847b55d48d1186b4055;tokio-rustls-%commit%'
	[tuic-quinn]='https://github.com/Itsusinn/tuic;3591624c0ab5abcdfc47256fb74ada440699593f;tuic-%commit%/tuic-quinn'
	[tuic]='https://github.com/Itsusinn/tuic;3591624c0ab5abcdfc47256fb74ada440699593f;tuic-%commit%/tuic'
	[unix-udp-sock]='https://github.com/Watfaq/unix-udp-sock;847c80b519f0fd8cff5c887ae708429897d08671;unix-udp-sock-%commit%'
	[watfaq-rustls]='https://github.com/Watfaq/rustls;4cae3aa2e84ea29d8a74b495793773bdb0a72206;rustls-%commit%/rustls'
)

RUST_MIN_VER="1.85.0"

inherit cargo systemd

DESCRIPTION="Custom protocol, rule based network proxy"
HOMEPAGE="
	https://watfaq.gitbook.io/clashrs-user-manual/
	https://github.com/Watfaq/clash-rs/
"
SRC_URI="
	https://github.com/Watfaq/clash-rs/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
	${CARGO_CRATE_URIS}
"

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

IUSE="+lto +standard plus perf bench"
REQUIRED_USE="
	debug? ( !lto )
"

BDEPEND="dev-libs/protobuf"

src_configure() {
	local myfeatures=(
		$(usev standard)
		$(usev plus)
		$(usev perf)
		$(usev bench)
	)
	cargo_src_configure
}

src_compile() {
	if use !debug; then
		# let portage do the strip
		export CARGO_PROFILE_RELEASE_STRIP=false
		if use !lto; then
			export CARGO_PROFILE_RELEASE_LTO=false
		fi
	fi

	# enable unstable features

	export RUSTC_BOOTSTRAP=1

	cargo_src_compile --package=clash-rs --bin=clash-rs
}

src_install() {
	dobin "$(cargo_target_dir)"/clash-rs
	insinto "/etc/clash-rs"
	doins "${FILESDIR}/config.example.yaml"
	systemd_dounit "${FILESDIR}/clash-rs.service"
}