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

# Autogenerated by pycargoebuild 0.15.0

EAPI=8

OPENXR_COMMIT="d0afdd3365bc1e14de28f6a3a21f457e788a702e"

if [[ ${PV} != 9999 ]]; then

CRATES="
	ab_glyph@0.2.29
	ab_glyph_rasterizer@0.1.8
	ahash@0.8.12
	aho-corasick@1.1.3
	anstream@0.6.19
	anstyle-parse@0.2.7
	anstyle-query@1.1.3
	anstyle-wincon@3.0.9
	anstyle@1.0.11
	ash@0.38.0+1.3.281
	autocfg@1.5.0
	bindgen@0.69.5
	bitflags@2.9.1
	block2@0.5.1
	bumpalo@3.19.0
	bytemuck@1.23.1
	bytemuck_derive@1.9.3
	bytes@1.10.1
	calloop-wayland-source@0.3.0
	calloop@0.13.0
	cargo_metadata@0.9.1
	cc@1.2.27
	cesu8@1.1.0
	cexpr@0.6.0
	cfg-if@1.0.1
	clang-sys@1.8.1
	clipboard-win@5.4.0
	cmake@0.1.54
	colorchoice@1.0.4
	combine@4.6.7
	concurrent-queue@2.5.0
	copypasta@0.10.2
	core-foundation-sys@0.8.7
	core-foundation@0.10.1
	crossbeam-utils@0.8.21
	cursor-icon@1.2.0
	deranged@0.4.0
	derive_more-impl@2.0.1
	derive_more@2.0.1
	displaydoc@0.2.5
	dlib@0.5.2
	downcast-rs@1.2.1
	ecolor@0.31.1
	egui-miniquad@0.16.0
	egui@0.31.1
	either@1.15.0
	emath@0.31.1
	env_filter@0.1.3
	env_logger@0.11.8
	epaint@0.31.1
	epaint_default_fonts@0.31.1
	errno@0.3.13
	error-code@3.3.2
	form_urlencoded@1.2.1
	generator@0.8.5
	gethostname@0.4.3
	getrandom@0.2.16
	gl@0.14.0
	gl_generator@0.14.0
	glam@0.30.4
	glob@0.3.2
	glutin_glx_sys@0.6.1
	hermit-abi@0.5.2
	home@0.5.11
	icu_collections@2.0.0
	icu_locale_core@2.0.0
	icu_normalizer@2.0.0
	icu_normalizer_data@2.0.0
	icu_properties@2.0.1
	icu_properties_data@2.0.1
	icu_provider@2.0.0
	idna@1.0.3
	idna_adapter@1.2.1
	is_terminal_polyfill@1.70.1
	itertools@0.12.1
	itoa@1.0.15
	jiff-static@0.2.15
	jiff@0.2.15
	jni-sys@0.3.0
	jni@0.21.1
	js-sys@0.3.77
	khronos_api@3.1.0
	lazy_static@1.5.0
	lazycell@1.3.0
	libc@0.2.174
	libloading@0.8.8
	linux-raw-sys@0.4.15
	linux-raw-sys@0.9.4
	litemap@0.8.0
	lock_api@0.4.13
	log@0.4.27
	loom@0.7.2
	malloc_buf@0.0.6
	matchers@0.1.0
	memchr@2.7.5
	memmap2@0.9.5
	minimal-lexical@0.2.1
	miniquad@0.4.8
	nanoserde-derive@0.2.1
	nanoserde@0.2.1
	ndk-context@0.1.1
	ndk-sys@0.2.2
	nohash-hasher@0.2.0
	nom@7.1.3
	nu-ansi-term@0.46.0
	num-conv@0.1.0
	num_threads@0.1.7
	objc-rs@0.2.8
	objc-sys@0.3.5
	objc2-app-kit@0.2.2
	objc2-core-data@0.2.2
	objc2-core-image@0.2.2
	objc2-encode@4.1.0
	objc2-foundation@0.2.2
	objc2-foundation@0.3.1
	objc2-metal@0.2.2
	objc2-quartz-core@0.2.2
	objc2@0.5.2
	objc2@0.6.1
	once_cell@1.21.3
	once_cell_polyfill@1.70.1
	overload@0.1.1
	owned_ttf_parser@0.25.0
	parking_lot@0.12.4
	parking_lot_core@0.9.11
	paste@1.0.15
	percent-encoding@2.3.1
	pin-project-lite@0.2.16
	pkg-config@0.3.32
	polling@3.8.0
	portable-atomic-util@0.2.4
	portable-atomic@1.11.1
	potential_utf@0.1.2
	powerfmt@0.2.0
	prettyplease@0.2.35
	proc-macro2@1.0.95
	profiling@1.0.17
	quad-rand@0.2.3
	quad-url@0.1.2
	quick-xml@0.37.5
	quote@1.0.40
	redox_syscall@0.5.13
	regex-automata@0.1.10
	regex-automata@0.4.9
	regex-syntax@0.6.29
	regex-syntax@0.8.5
	regex@1.11.1
	rustc-demangle@0.1.25
	rustc-hash@1.1.0
	rustix@0.38.44
	rustix@1.0.7
	rustversion@1.0.21
	ryu@1.0.20
	same-file@1.0.6
	sapp-jsutils@0.1.7
	scoped-tls@1.0.1
	scopeguard@1.2.0
	semver-parser@0.7.0
	semver@0.9.0
	seq-macro@0.3.6
	serde@1.0.219
	serde_derive@1.0.219
	serde_json@1.0.140
	sharded-slab@0.1.7
	shlex@1.3.0
	slab@0.4.10
	slotmap@1.0.7
	smallvec@1.15.1
	smithay-client-toolkit@0.19.2
	smithay-clipboard@0.7.2
	stable_deref_trait@1.2.0
	syn@2.0.104
	synstructure@0.13.2
	test-cdylib@1.1.0
	thiserror-impl@1.0.69
	thiserror@1.0.69
	thread_local@1.1.9
	time-core@0.1.4
	time-macros@0.2.22
	time@0.3.41
	tinystr@0.8.1
	toml@0.5.11
	tracing-core@0.1.34
	tracing-log@0.2.0
	tracing-subscriber@0.3.19
	tracing@0.1.41
	tracy-client-sys@0.24.3
	tracy-client@0.17.6
	ttf-parser@0.25.1
	unicode-ident@1.0.18
	url@2.5.4
	utf8_iter@1.0.4
	utf8parse@0.2.2
	valuable@0.1.1
	version_check@0.9.5
	walkdir@2.5.0
	wasi@0.11.1+wasi-snapshot-preview1
	wasm-bindgen-backend@0.2.100
	wasm-bindgen-macro-support@0.2.100
	wasm-bindgen-macro@0.2.100
	wasm-bindgen-shared@0.2.100
	wasm-bindgen@0.2.100
	wayland-backend@0.3.10
	wayland-client@0.31.10
	wayland-csd-frame@0.3.0
	wayland-cursor@0.31.10
	wayland-protocols-wlr@0.3.8
	wayland-protocols@0.32.8
	wayland-scanner@0.31.6
	wayland-sys@0.31.6
	web-sys@0.3.77
	webbrowser@0.5.5
	webbrowser@1.0.5
	which@4.4.2
	widestring@0.4.3
	winapi-i686-pc-windows-gnu@0.4.0
	winapi-util@0.1.9
	winapi-x86_64-pc-windows-gnu@0.4.0
	winapi@0.3.9
	windows-collections@0.2.0
	windows-core@0.61.2
	windows-future@0.2.1
	windows-implement@0.60.0
	windows-interface@0.59.1
	windows-link@0.1.3
	windows-numerics@0.2.0
	windows-result@0.3.4
	windows-strings@0.4.2
	windows-sys@0.45.0
	windows-sys@0.59.0
	windows-sys@0.60.2
	windows-targets@0.42.2
	windows-targets@0.48.5
	windows-targets@0.52.6
	windows-targets@0.53.2
	windows-threading@0.1.0
	windows@0.61.3
	windows_aarch64_gnullvm@0.42.2
	windows_aarch64_gnullvm@0.48.5
	windows_aarch64_gnullvm@0.52.6
	windows_aarch64_gnullvm@0.53.0
	windows_aarch64_msvc@0.42.2
	windows_aarch64_msvc@0.48.5
	windows_aarch64_msvc@0.52.6
	windows_aarch64_msvc@0.53.0
	windows_i686_gnu@0.42.2
	windows_i686_gnu@0.48.5
	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.42.2
	windows_i686_msvc@0.48.5
	windows_i686_msvc@0.52.6
	windows_i686_msvc@0.53.0
	windows_x86_64_gnu@0.42.2
	windows_x86_64_gnu@0.48.5
	windows_x86_64_gnu@0.52.6
	windows_x86_64_gnu@0.53.0
	windows_x86_64_gnullvm@0.42.2
	windows_x86_64_gnullvm@0.48.5
	windows_x86_64_gnullvm@0.52.6
	windows_x86_64_gnullvm@0.53.0
	windows_x86_64_msvc@0.42.2
	windows_x86_64_msvc@0.48.5
	windows_x86_64_msvc@0.52.6
	windows_x86_64_msvc@0.53.0
	writeable@0.6.1
	x11-clipboard@0.9.3
	x11-dl@2.21.0
	x11rb-protocol@0.13.1
	x11rb@0.13.1
	xcursor@0.3.10
	xkeysym@0.2.1
	xml-rs@0.8.26
	yoke-derive@0.8.0
	yoke@0.8.0
	zerocopy-derive@0.8.26
	zerocopy@0.8.26
	zerofrom-derive@0.1.6
	zerofrom@0.1.6
	zerotrie@0.2.2
	zerovec-derive@0.11.1
	zerovec@0.11.2
"

declare -A GIT_CRATES=(
	[openxr-sys]="https://github.com/ralith/openxrs;${OPENXR_COMMIT};openxrs-%commit%/sys"
	[openxr]="https://github.com/ralith/openxrs;${OPENXR_COMMIT};openxrs-%commit%/openxr"
)
fi

RUST_MULTILIB=1
RUST_MIN_VER="1.83.0"
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="
		${CARGO_CRATE_URIS}
		https://github.com/Supreeeme/xrizer/archive/refs/tags/v${MY_PV}.tar.gz
			-> ${P}.tar.gz
		https://github.com/KhronosGroup/OpenXR-SDK/archive/refs/tags/release-${OPENXR_SDK_VER}.tar.gz
			-> openxr-sdk-${OPENXR_SDK_VER}.tar.gz
	"
	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
		rm -fd "${WORKDIR}/openxrs-${OPENXR_COMMIT}/sys/OpenXR-SDK"
		mv "${WORKDIR}/OpenXR-SDK-release-${OPENXR_SDK_VER}" \
			"${WORKDIR}/openxrs-${OPENXR_COMMIT}/sys/OpenXR-SDK"
	fi
}

src_prepare() {
	default
	multilib_copy_sources
}

multilib_src_compile() {
	cargo_src_compile
}

multilib_src_install() {
	# OpenVR expects this particular directory structure.
	if [[ ${ABI} == amd64 ]] ; then
		exeinto "/opt/${PN}/bin/linux64"
		newexe $(cargo_target_dir)/libxrizer.so vrclient.so || die
	elif [[ ${ABI} == x86 ]] ; then
		exeinto "/opt/${PN}/bin"
		newexe $(cargo_target_dir)/libxrizer.so vrclient.so || die
	fi
	touch "${D}/opt/${PN}/version.txt"
}