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

# Autogenerated by pycargoebuild 0.15.0

EAPI=8

CRATES="
	aho-corasick@1.1.3
	anstream@0.6.20
	anstyle-parse@0.2.7
	anstyle-query@1.1.4
	anstyle-wincon@3.0.10
	anstyle@1.0.11
	anyhow@1.0.99
	ash@0.38.0+1.3.281
	bindgen@0.72.1
	bitflags@2.9.4
	bytemuck@1.23.2
	bytemuck_derive@1.10.1
	cc@1.2.36
	cexpr@0.6.0
	cfg-if@1.0.3
	cfg_aliases@0.2.1
	clang-sys@1.8.1
	clap@4.5.47
	clap_builder@4.5.47
	clap_complete@4.5.57
	clap_derive@4.5.47
	clap_lex@0.7.5
	colorchoice@1.0.4
	deranged@0.5.3
	downcast-rs@1.2.1
	drm-ffi@0.9.0
	drm-fourcc@2.2.0
	drm-sys@0.8.0
	drm@0.14.1
	either@1.15.0
	errno@0.3.14
	ffmpeg-next@8.0.0
	find-msvc-tools@0.1.1
	glob@0.3.3
	heck@0.5.0
	hermit-abi@0.5.2
	human-size@0.4.3
	is_terminal_polyfill@1.70.1
	itertools@0.13.0
	itoa@1.0.15
	libc@0.2.175
	libloading@0.8.8
	linux-raw-sys@0.4.15
	linux-raw-sys@0.6.5
	linux-raw-sys@0.9.4
	log-once@0.4.1
	log@0.4.28
	memchr@2.7.5
	minimal-lexical@0.2.1
	mio@1.0.4
	nix@0.30.1
	nom@7.1.3
	num-conv@0.1.0
	num_cpus@1.17.0
	num_threads@0.1.7
	once_cell_polyfill@1.70.1
	pkg-config@0.3.32
	powerfmt@0.2.0
	proc-macro2@1.0.101
	quick-xml@0.37.5
	quote@1.0.40
	regex-automata@0.4.10
	regex-syntax@0.8.6
	regex@1.11.2
	rustc-hash@2.1.1
	rustix@0.38.44
	rustix@1.0.8
	ryu@1.0.20
	serde@1.0.219
	serde_derive@1.0.219
	serde_json@1.0.143
	shlex@1.3.0
	signal-hook-mio@0.2.4
	signal-hook-registry@1.4.6
	signal-hook@0.3.18
	simplelog@0.12.2
	smallvec@1.15.1
	strsim@0.11.1
	syn@2.0.106
	termcolor@1.4.1
	thiserror-impl@2.0.16
	thiserror@2.0.16
	time-core@0.1.6
	time-macros@0.2.24
	time@0.3.43
	unicode-ident@1.0.18
	utf8parse@0.2.2
	vcpkg@0.2.15
	wasi@0.11.1+wasi-snapshot-preview1
	wayland-backend@0.3.11
	wayland-client@0.31.11
	wayland-protocols-wlr@0.3.9
	wayland-protocols@0.32.9
	wayland-scanner@0.31.7
	wayland-sys@0.31.7
	winapi-util@0.1.11
	windows-link@0.1.3
	windows-link@0.2.0
	windows-sys@0.59.0
	windows-sys@0.60.2
	windows-sys@0.61.0
	windows-targets@0.52.6
	windows-targets@0.53.3
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_gnullvm@0.53.0
	windows_aarch64_msvc@0.52.6
	windows_aarch64_msvc@0.53.0
	windows_i686_gnu@0.52.6
	windows_i686_gnu@0.53.0
	windows_i686_gnullvm@0.52.6
	windows_i686_gnullvm@0.53.0
	windows_i686_msvc@0.52.6
	windows_i686_msvc@0.53.0
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnu@0.53.0
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_gnullvm@0.53.0
	windows_x86_64_msvc@0.52.6
	windows_x86_64_msvc@0.53.0
"

declare -A GIT_CRATES=(
	[ffmpeg-sys-next]='https://github.com/russelltg/rust-ffmpeg-sys;ff4b564de3c3cca2c5e3dac955482ae81c9e12f5;rust-ffmpeg-sys-%commit%'
)

RUST_MIN_VER="1.85.0"
LLVM_COMPAT=( {19..22} )

inherit cargo shell-completion llvm-r2

DESCRIPTION="High performance screen/audio recorder for wlroots"
HOMEPAGE="https://github.com/russelltg/wl-screenrec"
SRC_URI="
	https://github.com/russelltg/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.gh.tar.gz
	${CARGO_CRATE_URIS}
"

LICENSE="Apache-2.0 BSD ISC MIT Unicode-3.0 WTFPL-2"
SLOT="0"
KEYWORDS="~amd64"
# We need a running Wayland compositor for the tests to work
RESTRICT="test"

PATCHES=("${FILESDIR}/${P}-custom_ffmpeg.patch")

BDEPEND="
	$(llvm_gen_dep '
		llvm-core/clang:${LLVM_SLOT}
	')
"
RDEPEND="
	media-video/ffmpeg:=[vaapi]
	x11-libs/libdrm
"
DEPEND="
	${RDEPEND}
"

QA_FLAGS_IGNORED="usr/bin/${PN}"

pkg_setup() {
	llvm-r2_pkg_setup
	rust_pkg_setup
}

src_prepare() {
	default

	CUSTOM_FFMPEG="rust-ffmpeg-sys-ff4b564de3c3cca2c5e3dac955482ae81c9e12f5"
	PACKAGE_HASH="7a2a9eb3135a9ec64df9164b15781df2d8bb7a52ad76738bf0c2d65df3f36df3"
	FFMPEG_VENDOR="${ECARGO_VENDOR}/ffmpeg-sys-next-8.0.1"

	# ${ECARGO_VENDOR} is defined in cargo.eclass
	cp -r "${WORKDIR}/${CUSTOM_FFMPEG}" "${FFMPEG_VENDOR}" || \
		die "Could not move the patched version of ffmpeg-sys-next into the vendor directory"
	echo "{\"package\": \"${PACKAGE_HASH}\", \"files\": {}}" > "${FFMPEG_VENDOR}/.cargo-checksum.json"
}

src_compile() {
	cargo_src_compile

	./"$(cargo_target_dir)/${PN}" --generate-completions bash > "${S}/wl-screenrec" || \
		die "Could not generate bash completion"
	./"$(cargo_target_dir)/${PN}" --generate-completions fish > "${S}/wl-screenrec.fish" || \
		die "Could not generate fish completion"
	./"$(cargo_target_dir)/${PN}" --generate-completions zsh > "${S}/_wl-screenrec" || \
		die "Could not generate zsh completion"
}

src_install() {
	cargo_src_install

	dobashcomp "${S}/wl-screenrec" || die "Could not install bash completion"
	dofishcomp "${S}/wl-screenrec.fish" || die "Could not install fish completion"
	dozshcomp "${S}/_wl-screenrec" || die "Could not install zsh completion"
}

pkg_postinst() {
	elog "You need a wayland compositor that supports the"
	elog "following unstable protocols:"
	elog "  - wlr-output-management-unstable-v1"
	elog "  - wlr-screencopy-unstable-v1"
	elog "You should also make sure you have the correct librairies"
	elog "installed. See: https://trac.ffmpeg.org/wiki/Hardware/VAAPI"
}
