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

# Autogenerated by pycargoebuild 0.15.0

EAPI=8

RUST_MIN_VER="1.88.0"

# apply-crates-fixes start
LLVM_COMPAT=( {19..22} )
# apply-crates-fixes end
CRATES=" "

# apply-crates-fixes start
inherit llvm-r2
# apply-crates-fixes end

inherit cargo shell-completion desktop xdg

DESCRIPTION="A beautiful and configurable TUI client for MPD"
HOMEPAGE="https://mierak.github.io/rmpc/"
LICENSE="BSD"

# Dependent crate licenses
LICENSE+="
	Apache-2.0 BSD-2 BSD CC0-1.0 CDLA-Permissive-2.0 ISC LGPL-3+ MIT
	UoI-NCSA openssl Unicode-3.0 Unicode-DFS-2016 WTFPL-2 ZLIB
"

if [[ "${PV}" == *9999* ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/mierak/${PN}"
else
	SRC_URI="https://github.com/mierak/${PN}/archive/refs/tags/v${PV}.tar.gz -> ${P}.tar.gz
		${CARGO_CRATE_URIS}"
	KEYWORDS="~amd64"
	RESTRICT="mirror"
fi

SLOT="0"
# apply-crates-fixes start
DEPEND="
	$(llvm_gen_dep 'llvm-runtimes/compiler-rt-sanitizers:${LLVM_SLOT}[libfuzzer]')
"
BDEPEND="
	$(llvm_gen_dep 'llvm-core/clang:${LLVM_SLOT}')
	virtual/pkgconfig
"
# apply-crates-fixes end

DOCS=( README.md CHANGELOG.md )

src_unpack() {
	if [[ "${PV}" == *9999* ]];then
		git-r3_src_unpack
		cargo_live_src_unpack
	else
		cargo_src_unpack
	fi
}
# apply-crates-fixes start
src_compile(){
	CUSTOM_LIBFUZZER_PATH="$(clang --print-file-name "libclang_rt.fuzzer-${CHOST%%-*}.a" )"
	[[ -f "${CUSTOM_LIBFUZZER_PATH}" ]] || die "trying to set CUSTOM_LIBFUZZER_PATH failed"
	export CUSTOM_LIBFUZZER_PATH
	export AWS_LC_SYS_CFLAGS="${CFLAGS} -O0"
	# aws-lc-sys bundles aws-lc, which bundles quite a lot of dependencies, jitterentropy among them
	# https://github.com/aws/aws-lc-rs/issues/936 -> "Please add support to use system-provided aws-lc library"
	# jitterentropy can not be built without -O0, the script does not have the logic to unbundle dependencies right now
	# but what it can do is use set the AWS_LC_SYS_CFLAGS var to override CFLAGS
	cargo_src_compile
}
# apply-crates-fixes end

src_install() {
	cargo_src_install
	einstalldocs
	doman target/man/*
	newbashcomp target/completions/"${PN}".bash "${PN}"
	dozshcomp target/completions/_"${PN}"
	dofishcomp target/completions/"${PN}".fish
	domenu assets/"${PN}".desktop
}