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

# Autogenerated by pycargoebuild 0.15.0

EAPI=8

RUST_MULTILIB=1
RUST_MIN_VER="1.88"
inherit cargo multilib-minimal

DESCRIPTION="OpenVR over OpenXR compatibility layer"
HOMEPAGE="https://github.com/Supreeeme/xrizer/"
MY_PV="$(ver_cut 1-2)"
OPENXR_SDK_VER="1.1.40"

if [[ ${PV} != 9999 ]]; then
	SRC_URI="
		https://github.com/Supreeeme/xrizer/archive/refs/tags/v${MY_PV}.tar.gz
			-> ${P}.tar.gz
		https://codeberg.org/TheGreatMcPain/guru-distfiles/releases/download/${P}/${P}-vendored.tar.xz
	"
	S="${WORKDIR}/${PN}-${MY_PV}"
fi

LICENSE="GPL-3+"
# Dependent crate licenses
LICENSE+="
	Apache-2.0 BSD Boost-1.0 ISC MIT OFL-1.1 UbuntuFontLicense-1.0
	Unicode-3.0 ZLIB
"
SLOT="0"

if [[ ${PV} == 9999 ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/Supreeeme/xrizer.git"
else
	KEYWORDS="~amd64"
fi

src_unpack() {
	if [[ ${PV} == 9999 ]]; then
		git-r3_src_unpack
		cargo_live_src_unpack
	else
		cargo_src_unpack

		ln -s "${WORKDIR}/vendor" "${S}/" || die

		sed -i "${ECARGO_HOME}/config.toml" -e '/source.crates-io/d'  || die
		sed -i "${ECARGO_HOME}/config.toml" -e '/replace-with = "gentoo"/d'  || die
		sed -i "${ECARGO_HOME}/config.toml" -e '/local-registry = "\/nonexistent"/d'  || die
		cat "${WORKDIR}/vendor/vendor-config.toml" >> "${ECARGO_HOME}/config.toml" || die
	fi
}

src_prepare() {
	default
	multilib_copy_sources
}

multilib_src_compile() {
	cargo_src_compile
}

multilib_src_install() {
	# OpenVR expects this particular directory structure.
	exeinto "/opt/${PN}/bin$(multilib_is_native_abi && echo /linux64)"
	newexe "$(cargo_target_dir)"/libxrizer.so vrclient.so
	touch "${ED}/opt/${PN}/version.txt"
}