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

# Autogenerated by pycargoebuild 0.13.2

EAPI=8

CRATES="
"

declare -A GIT_CRATES=(
	[android-wakelock]='https://github.com/rustdesk-org/android-wakelock;d0292e5a367e627c4fa6f1ca6bdfad005dca7d90;android-wakelock-%commit%'
	[arboard]='https://github.com/rustdesk-org/arboard;4e16bad260ea05dd7dcdb68cc7549dad3920b940;arboard-%commit%'
	[cacao]='https://github.com/clslaid/cacao;05e1536b0b43aaae308ec72c0eed703e875b7b95;cacao-%commit%'
	[cidre-macros]='https://github.com/yury/cidre;f05c4288f9870c9fab53272ddafd6ec01c7b2dbf;cidre-%commit%/cidre-macros'
	[cidre]='https://github.com/yury/cidre;f05c4288f9870c9fab53272ddafd6ec01c7b2dbf;cidre-%commit%/cidre'
	[clipboard-master]='https://github.com/rustdesk-org/clipboard-master;4fb62e5b62fb6350d82b571ec7ba94b3cd466695;clipboard-master-%commit%'
	[confy]='https://github.com/rustdesk-org/confy;83db9ec19a2f97e9718aef69e4fc5611bb382479;confy-%commit%'
	[core-foundation-sys]='https://github.com/madsmtm/core-foundation-rs;7d593d016175755e492a92ef89edca68ac3bd5cd;core-foundation-rs-%commit%/core-foundation-sys'
	[core-foundation]='https://github.com/madsmtm/core-foundation-rs;7d593d016175755e492a92ef89edca68ac3bd5cd;core-foundation-rs-%commit%/core-foundation'
	[core-graphics-types]='https://github.com/madsmtm/core-foundation-rs;7d593d016175755e492a92ef89edca68ac3bd5cd;core-foundation-rs-%commit%/core-graphics-types'
	[core-graphics]='https://github.com/madsmtm/core-foundation-rs;7d593d016175755e492a92ef89edca68ac3bd5cd;core-foundation-rs-%commit%/core-graphics'
	[cpal]='https://github.com/rustdesk-org/cpal;6b374bcaed076750ca8fce6da518ab39b882e14a;cpal-%commit%'
	[default_net]='https://github.com/rustdesk-org/default_net;78f8f70cd85151a3a2c4a3230d80d5272703c02e;default_net-%commit%'
	[evdev]='https://github.com/rustdesk-org/evdev;cec616e37790293d2cd2aa54a96601ed6b1b35a9;evdev-%commit%'
	[hwcodec]='https://github.com/rustdesk-org/hwcodec;0ea7e709d3c48bb6446e33a9cc8fd0e0da5709b9;hwcodec-%commit%'
	[impersonate_system]='https://github.com/rustdesk-org/impersonate-system;2f429010a5a10b1fe5eceb553c6672fd53d20167;impersonate-system-%commit%'
	[keepawake]='https://github.com/rustdesk-org/keepawake-rs;64d568586dd16551d02120e19668d2b0fec8e3c9;keepawake-rs-%commit%'
	[machine-uid]='https://github.com/rustdesk-org/machine-uid;381ff579c1dc3a6c54db9dfec47c44bcb0246542;machine-uid-%commit%'
	[magnum-opus]='https://github.com/rustdesk-org/magnum-opus;5cd2bf989c148662fa3a2d9d539a71d71fd1d256;magnum-opus-%commit%'
	[nokhwa-bindings-linux]='https://github.com/rustdesk-org/nokhwa;3e2512074bc57d5df011363a26a8ee8959dc7969;nokhwa-%commit%/nokhwa-bindings-linux'
	[nokhwa-bindings-macos]='https://github.com/rustdesk-org/nokhwa;3e2512074bc57d5df011363a26a8ee8959dc7969;nokhwa-%commit%/nokhwa-bindings-macos'
	[nokhwa-bindings-windows]='https://github.com/rustdesk-org/nokhwa;3e2512074bc57d5df011363a26a8ee8959dc7969;nokhwa-%commit%/nokhwa-bindings-windows'
	[nokhwa-core]='https://github.com/rustdesk-org/nokhwa;3e2512074bc57d5df011363a26a8ee8959dc7969;nokhwa-%commit%/nokhwa-core'
	[nokhwa]='https://github.com/rustdesk-org/nokhwa;3e2512074bc57d5df011363a26a8ee8959dc7969;nokhwa-%commit%'
	[pam-sys]='https://github.com/rustdesk-org/pam-sys;3337c9bb9a9c68d7497ec8c93cad2368c26091b7;pam-sys-%commit%'
	[pam]='https://github.com/rustdesk-org/pam;7bfd25510202cd269292cbdd7c71f3977a6fd762;pam-%commit%'
	[parity-tokio-ipc]='https://github.com/rustdesk-org/parity-tokio-ipc;3623ec9ebef50c9b118e03b03df831008a4d1441;parity-tokio-ipc-%commit%'
	[rdev]='https://github.com/rustdesk-org/rdev;f9b60b1dd0f3300a1b797d7a74c116683cd232c8;rdev-%commit%'
	[reqwest]='https://github.com/rustdesk-org/reqwest;9cb758c9fb2f4edc62eb790acfd45a6a3da21ed3;reqwest-%commit%'
	[rust-pulsectl]='https://github.com/rustdesk-org/pulsectl;aa34dde499aa912a3abc5289cc0b547bd07dd6e2;pulsectl-%commit%'
	[sciter-rs]='https://github.com/rustdesk-org/rust-sciter;5322f3a755a0e6bf999fbc60d1efc35246c0f821;rust-sciter-%commit%'
	[sysinfo]='https://github.com/rustdesk-org/sysinfo;90b1705d909a4902dbbbdea37ee64db17841077d;sysinfo-%commit%'
	[tao-macros]='https://github.com/rustdesk-org/tao;288c219cb0527e509590c2b2d8e7072aa9feb2d3;tao-%commit%/tao-macros'
	[tao]='https://github.com/rustdesk-org/tao;288c219cb0527e509590c2b2d8e7072aa9feb2d3;tao-%commit%'
	[tfc]='https://github.com/rustdesk-org/The-Fat-Controller;78bb80a8e596e4c14ae57c8448f5fca75f91f2b0;The-Fat-Controller-%commit%'
	[tokio-socks]='https://github.com/rustdesk-org/tokio-socks;94e97c6d7c93b0bcbfa54f2dc397c1da0a6e43d3;tokio-socks-%commit%'
	[tray-icon]='https://github.com/tauri-apps/tray-icon;d4078696edba67b0ab42cef67e6a421a0332c96f;tray-icon-%commit%'
	[wallpaper]='https://github.com/rustdesk-org/wallpaper.rs;ce4a0cd3f58327c7cc44d15a63706fb0c022bacf;wallpaper.rs-%commit%'
	[webm-sys]='https://github.com/rustdesk-org/rust-webm;d2c4d3ac133c7b0e4c0f656da710b48391981e64;rust-webm-%commit%/src/sys'
	[webm]='https://github.com/rustdesk-org/rust-webm;d2c4d3ac133c7b0e4c0f656da710b48391981e64;rust-webm-%commit%'
	[x11-clipboard]='https://github.com/clslaid/x11-clipboard;5fc2e73bc01ada3681159b34cf3ea8f0d14cd904;x11-clipboard-%commit%'
	[x11]='https://github.com/bjornsnoen/x11-rs;c2e9bfaa7b196938f8700245564d8ac5d447786a;x11-rs-%commit%/x11'
)

LLVM_COMPAT=( 17 18 19 )
RUST_MIN_VER="1.75.0"
RUST_NEEDS_LLVM=1
inherit cargo desktop llvm-r1 systemd xdg

DESCRIPTION="An open-source remote desktop, and alternative to TeamViewer."
HOMEPAGE="https://rustdesk.com/"
_WEBM_PV="1.0.0.31"
_VCPKG_COMMIT="2024.11.16"
_HWCODEC_EXTERNALS_COMMIT="a0ff168b672ab57c50f09dbe128608e45a1c4a52"
_HBB_COMMON_COMMIT="81b932b7bfa2ff8bc60189625fd6538db2fa9ea1"
SRC_URI="
	https://github.com/rustdesk/rustdesk/archive/refs/tags/${PV}.tar.gz
		-> ${P}.tar.gz
	https://distfiles.gentoocn.org/~jinqiang/distfiles/${PN}-1.3.6-vcpkg-${_VCPKG_COMMIT}-lite.tar.gz
	https://github.com/webmproject/libwebm/archive/refs/tags/libwebm-${_WEBM_PV}.tar.gz
	https://github.com/rustdesk/hbb_common/archive/${_HBB_COMMON_COMMIT}.tar.gz
		-> hbb_common-${_HBB_COMMON_COMMIT}.tar.gz
	https://github.com/rustdesk-org/externals/archive/${_HWCODEC_EXTERNALS_COMMIT}.tar.gz
		-> hwcodec-externals-${_HWCODEC_EXTERNALS_COMMIT}.tar.gz
	https://raw.githubusercontent.com/c-smile/sciter-sdk/master/bin.lnx/x64/libsciter-gtk.so
		-> ${P}-libsciter-gtk.so
	https://distfiles.gentoocn.org/~jinqiang/distfiles/${P}-crates.tar.xz
	${CARGO_CRATE_URIS}
"

LICENSE="AGPL-3"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 Apache-2.0-with-LLVM-exceptions BSD-2 BSD Boost-1.0
	CC0-1.0 GPL-3+ IJG ISC MIT MIT-0 MPL-2.0 Unicode-DFS-2016 Unlicense
	ZLIB
"
SLOT="0"
KEYWORDS="~amd64"

IUSE="wayland +hwaccel"

RDEPEND="
	media-libs/alsa-lib
	x11-libs/gtk+:3
	x11-libs/libxcb
	x11-libs/libXfixes
	media-libs/libpulse
	x11-misc/xdotool
	media-libs/libva[X]
	wayland? ( media-video/pipewire[gstreamer] )
	hwaccel? ( x11-libs/libvdpau )
"
BDEPEND="
	dev-lang/nasm
	dev-lang/yasm
	media-libs/alsa-lib
	media-libs/libpulse
	dev-build/cmake
	dev-build/ninja
	media-libs/gstreamer
	media-libs/gst-plugins-base
	$(llvm_gen_dep '
		llvm-core/clang:${LLVM_SLOT}
		llvm-core/llvm:${LLVM_SLOT}
	')
"

QA_PRESTRIPPED="
	/usr/share/${PN}/${PN}
	/usr/share/${PN}/libsciter-gtk.so
"

pkg_setup() {
	llvm-r1_pkg_setup
	rust_pkg_setup
}

src_prepare() {
	PATCHES+=(
		"${FILESDIR}"/rust-sciter.patch
	)
	cd "${S}"/.. || die

	default

	cd - || die

	rm -rf libs/hbb_common || die
	ln -s "${WORKDIR}"/hbb_common-${_HBB_COMMON_COMMIT} libs/hbb_common || die

	cd ../rust-webm-*/src/sys || die
	rm -rf libwebm/ || die
	ln -s "${WORKDIR}"/libwebm-libwebm-*/ libwebm || die

	local _HWCODEC_COMMIT=`echo "${GIT_CRATES[hwcodec]}" | awk -F';' '{print $2}'`
	rm -rf "${WORKDIR}"/hwcodec-${_HWCODEC_COMMIT}/externals || die
	ln -s "${WORKDIR}"/externals-${_HWCODEC_EXTERNALS_COMMIT} "${WORKDIR}"/hwcodec-${_HWCODEC_COMMIT}/externals || die
}

src_configure() {
	if use hwaccel ;then
		local myfeatures=(hwcodec)
	fi

	cargo_src_configure
}

src_compile() {
	VCPKG_ROOT="$WORKDIR"/vcpkg cargo_src_compile
}

src_install() {
	local rustdesk_dir="/usr/share/${PN}"

	exeinto "${rustdesk_dir}"
	insinto "${rustdesk_dir}"
	doexe $(cargo_target_dir)/rustdesk
	newins "${DISTDIR}/${P}-libsciter-gtk.so" libsciter-gtk.so
	rm src/ui/*.rs || die
	newbin "${FILESDIR}/rustdesk.sh" rustdesk
	insinto "${rustdesk_dir}/src"
	doins -r src/ui

	newicon -s 32 $(realpath res/32x32.png || die) rustdesk.png
	newicon -s 128 $(realpath res/128x128.png || die) rustdesk.png
	newicon -s 256 $(realpath res/128x128@2x.png || die) rustdesk.png

	domenu "${FILESDIR}"/rustdesk{,-link}.desktop
	systemd_dounit "${FILESDIR}"/rustdesk.service

	einstalldocs
}
