# Copyright 1999-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

DESCRIPTION="Wireless driver for Oculus Quest"
HOMEPAGE="https://github.com/alvr-org/ALVR"
LICENSE="MIT"
SLOT="0"

IUSE="vaapi x264 x265"

RDEPEND="
	>=media-video/ffmpeg-4.3[encode,vulkan,x264?,x265?]
	vaapi? ( media-video/ffmpeg[libdrm,vaapi] )
	sys-libs/libunwind
	www-client/chromium
"

DEPEND="${RDEPEND}"

BDEPEND="${RDEPEND}
	virtual/pkgconfig
	dev-util/vulkan-headers
"

CRATES="
ab_glyph_rasterizer-0.1.4
addr2line-0.15.1
adler-1.0.2
ahash-0.3.8
aho-corasick-0.7.18
alcro-0.5.3
alsa-0.5.0
alsa-sys-0.3.1
andrew-0.3.1
android_logger-0.10.1
android_log-sys-0.2.0
ansi_term-0.11.0
anyhow-1.0.40
approx-0.4.0
arrayref-0.3.6
arrayvec-0.5.2
ash-0.31.0
associative-cache-1.0.1
atk-0.9.0
atk-sys-0.10.0
atty-0.2.14
autocfg-1.0.1
backtrace-0.3.59
base64-0.13.0
base-x-0.2.8
bincode-1.3.3
bindgen-0.56.0
bindgen-0.58.1
bitflags-1.2.1
blake2b_simd-0.5.11
block-0.1.6
block-buffer-0.9.0
bumpalo-3.6.1
byteorder-1.4.3
bytes-1.0.1
cairo-rs-0.9.1
cairo-sys-rs-0.10.0
calloop-0.6.5
cc-1.0.67
cesu8-1.1.0
cexpr-0.4.0
cfg-if-0.1.10
cfg-if-1.0.0
chrono-0.4.19
chunked_transfer-1.4.0
clang-sys-1.2.0
clap-2.33.3
claxon-0.4.3
cocoa-0.24.0
cocoa-foundation-0.1.0
combine-4.5.2
console_log-0.2.0
constant_time_eq-0.1.5
const_fn-0.4.7
coreaudio-rs-0.10.0
coreaudio-sys-0.2.8
core-foundation-0.7.0
core-foundation-0.9.1
core-foundation-sys-0.6.2
core-foundation-sys-0.7.0
core-foundation-sys-0.8.2
core-graphics-0.19.2
core-graphics-0.22.2
core-graphics-types-0.1.1
core-text-19.2.0
core-video-sys-0.1.4
cpal-0.13.3
cpufeatures-0.1.4
crossbeam-channel-0.5.1
crossbeam-deque-0.8.0
crossbeam-epoch-0.9.4
crossbeam-utils-0.8.4
darling-0.10.2
darling_core-0.10.2
darling_macro-0.10.2
dashmap-4.0.2
derivative-2.2.0
digest-0.9.0
dirs-1.0.5
dirs-3.0.2
dirs-sys-0.3.6
discard-1.0.4
dispatch-0.2.0
dlib-0.4.2
dlib-0.5.0
doc-comment-0.3.3
downcast-rs-1.2.0
druid-0.7.0
druid-derive-0.4.0
druid-shell-0.7.0
dwrote-0.11.0
either-1.6.1
encoding_rs-0.8.28
encoding_rs_io-0.1.7
env_logger-0.8.3
errno-0.2.7
errno-dragonfly-0.1.1
exec-0.3.1
failure-0.1.8
fern-0.6.0
fluent-bundle-0.12.0
fluent-langneg-0.13.0
fluent-syntax-0.9.3
fnv-1.0.7
foreign-types-0.3.2
foreign-types-shared-0.1.1
form_urlencoded-1.0.1
fs_extra-1.2.0
fuchsia-zircon-0.3.3
fuchsia-zircon-sys-0.3.3
futures-0.3.15
futures-channel-0.3.15
futures-core-0.3.15
futures-executor-0.3.15
futures-io-0.3.15
futures-macro-0.3.15
futures-sink-0.3.15
futures-task-0.3.15
futures-timer-3.0.2
futures-util-0.3.15
fxhash-0.2.1
gcc-0.3.55
gdk-0.13.2
gdk-pixbuf-0.9.0
gdk-pixbuf-sys-0.10.0
gdk-sys-0.10.0
generic-array-0.14.4
getrandom-0.1.16
getrandom-0.2.2
gfx-auxil-0.7.0
gfx-backend-dx11-0.6.17
gfx-backend-vulkan-0.6.5
gfx-hal-0.6.0
gimli-0.24.0
gio-0.9.1
gio-sys-0.10.1
glib-0.10.3
glib-macros-0.10.1
glib-sys-0.10.1
glob-0.3.0
gobject-sys-0.10.0
governor-0.3.2
gtk-0.9.2
gtk-sys-0.10.0
h2-0.3.3
hashbrown-0.8.2
hashbrown-0.9.1
headers-0.3.4
headers-core-0.2.0
heck-0.3.2
hermit-abi-0.1.18
hound-3.4.0
http-0.2.4
httparse-1.4.1
http-body-0.4.2
httpdate-1.0.0
humantime-2.1.0
hyper-0.14.7
hyper-tls-0.5.0
ident_case-1.0.1
idna-0.2.3
indexmap-1.6.2
inplace_it-0.3.3
input_buffer-0.4.0
instant-0.1.9
intl-memoizer-0.5.1
intl_pluralrules-7.0.1
iovec-0.1.4
ipnet-2.3.0
itertools-0.9.0
itoa-0.4.7
jni-0.18.0
jni-0.19.0
jni-sys-0.3.0
jobserver-0.1.22
js-sys-0.3.51
kernel32-sys-0.2.2
keyboard-types-0.5.0
kurbo-0.7.1
lazycell-1.3.0
lazy_static-1.4.0
lewton-0.10.2
libc-0.2.94
libloading-0.6.7
libloading-0.7.0
lock_api-0.4.4
log-0.4.14
mach-0.3.2
malloc_buf-0.0.6
matches-0.1.8
matrixmultiply-0.3.1
maybe-uninit-2.0.0
memchr-2.4.0
memmap2-0.1.0
memoffset-0.6.3
mime-0.3.16
minimp3-0.5.1
minimp3-sys-0.3.2
miniz_oxide-0.4.4
mio-0.6.23
mio-0.7.11
mio-extras-2.0.6
miow-0.2.2
miow-0.3.7
msgbox-0.6.0
nalgebra-0.26.2
native-tls-0.2.7
ndk-0.2.1
ndk-0.3.0
ndk-glue-0.2.1
ndk-glue-0.3.0
ndk-macro-0.2.0
ndk-sys-0.2.1
net2-0.2.37
nix-0.18.0
nix-0.19.1
nix-0.20.0
nom-5.1.2
nom-6.1.2
nonzero_ext-0.2.0
no-std-compat-0.4.1
ntapi-0.3.6
num-complex-0.3.1
num_cpus-1.13.0
num-derive-0.3.3
num_enum-0.4.3
num_enum-0.5.1
num_enum_derive-0.4.3
num_enum_derive-0.5.1
num-integer-0.1.44
num-rational-0.3.2
num-traits-0.2.14
objc-0.2.7
object-0.24.0
oboe-0.4.1
oboe-sys-0.4.0
ogg-0.8.0
once_cell-1.7.2
opaque-debug-0.3.0
openssl-0.10.34
openssl-probe-0.1.4
openssl-sys-0.9.63
os_str_bytes-3.1.0
owned_ttf_parser-0.6.0
pango-0.9.1
pango-sys-0.10.0
parking_lot-0.11.1
parking_lot_core-0.8.3
paste-1.0.5
peeking_take_while-0.1.2
pem-0.8.3
percent-encoding-2.1.0
pest-2.1.3
pico-args-0.4.1
piet-0.3.1
piet-cairo-0.3.0
piet-common-0.3.2
piet-coregraphics-0.3.0
piet-direct2d-0.3.0
piet-web-0.3.1
pin-project-1.0.7
pin-project-internal-1.0.7
pin-project-lite-0.2.6
pin-utils-0.1.0
pkg-config-0.3.19
ppv-lite86-0.2.10
proc-macro2-1.0.26
proc-macro-crate-0.1.5
proc-macro-error-1.0.4
proc-macro-error-attr-1.0.4
proc-macro-hack-0.5.19
proc-macro-nested-0.1.7
quanta-0.4.1
quote-1.0.9
rand-0.8.3
rand_chacha-0.3.0
rand_core-0.6.2
rand_hc-0.3.0
range-alloc-0.1.2
rawpointer-0.2.1
raw-window-handle-0.3.3
rayon-1.5.0
rayon-core-1.9.0
rcgen-0.8.11
redox_syscall-0.1.57
redox_syscall-0.2.8
redox_users-0.3.5
redox_users-0.4.0
regex-1.5.4
regex-syntax-0.6.25
remove_dir_all-0.5.3
rental-0.5.6
rental-impl-0.5.5
reqwest-0.11.3
ring-0.16.20
rodio-0.13.1
runas-0.2.1
rust-argon2-0.8.3
rustc-demangle-0.1.19
rustc-hash-1.1.0
rustc_version-0.2.3
rustls-0.19.1
rusttype-0.9.2
ryu-1.0.5
same-file-1.0.6
schannel-0.1.19
scoped-tls-1.0.0
scopeguard-1.1.0
sct-0.6.1
security-framework-2.2.0
security-framework-sys-2.2.0
semver-0.11.0
semver-0.9.0
semver-parser-0.10.2
semver-parser-0.7.0
serde-1.0.126
serde_derive-1.0.126
serde_json-1.0.64
serde_urlencoded-0.7.0
sha1-0.6.0
sha-1-0.9.6
shlex-0.1.1
shlex-1.0.0
signal-hook-registry-1.3.0
simba-0.4.0
simple_logger-1.11.0
single-instance-0.3.1
slab-0.4.3
slice-deque-0.3.0
smallvec-1.6.1
smithay-client-toolkit-0.12.3
socket2-0.4.0
spin-0.5.2
spirv_cross-0.22.2
stable_deref_trait-1.2.0
standback-0.2.17
stdweb-0.1.3
stdweb-0.4.20
stdweb-derive-0.5.3
stdweb-internal-macros-0.2.9
stdweb-internal-runtime-0.1.5
strsim-0.8.0
strsim-0.9.3
strum-0.18.0
strum_macros-0.18.0
syn-1.0.72
sysinfo-0.17.5
system-deps-1.3.2
tempfile-3.2.0
termcolor-1.1.2
textwrap-0.11.0
thiserror-1.0.24
thiserror-impl-1.0.24
thunderdome-0.3.0
time-0.1.43
time-0.2.26
time-macros-0.1.1
time-macros-impl-0.1.1
tinyfiledialogs-3.3.10
tinystr-0.3.4
tinyvec-1.2.0
tinyvec_macros-0.1.0
tokio-1.6.0
tokio-macros-1.2.0
tokio-native-tls-0.3.0
tokio-tungstenite-0.14.0
tokio-util-0.6.7
toml-0.5.8
tower-service-0.3.1
tracing-0.1.26
tracing-core-0.1.18
try-lock-0.2.3
ttf-parser-0.6.2
tungstenite-0.13.0
type-map-0.4.0
typenum-1.13.0
ucd-trie-0.1.3
unic-bidi-0.9.0
unic-char-property-0.9.0
unic-char-range-0.9.0
unic-common-0.9.0
unic-langid-0.9.0
unic-langid-impl-0.9.0
unicode-bidi-0.3.5
unicode-normalization-0.1.17
unicode-segmentation-1.7.1
unicode-width-0.1.8
unicode-xid-0.2.2
unic-ucd-bidi-0.9.0
unic-ucd-version-0.9.0
untrusted-0.7.1
ureq-2.1.1
url-2.2.2
utf16_lit-1.0.1
utf-8-0.7.6
vcpkg-0.2.12
vec_map-0.8.2
version_check-0.9.3
version-compare-0.0.10
walkdir-2.3.2
want-0.3.0
wasi-0.10.2+wasi-snapshot-preview1
wasi-0.9.0+wasi-snapshot-preview1
wasm-bindgen-0.2.74
wasm-bindgen-backend-0.2.74
wasm-bindgen-futures-0.4.24
wasm-bindgen-macro-0.2.74
wasm-bindgen-macro-support-0.2.74
wasm-bindgen-shared-0.2.74
wayland-client-0.28.5
wayland-commons-0.28.5
wayland-cursor-0.28.5
wayland-protocols-0.28.5
wayland-scanner-0.28.5
wayland-sys-0.28.5
webbrowser-0.5.5
webpki-0.21.4
webpki-roots-0.21.1
web-sys-0.3.51
which-3.1.1
widestring-0.4.3
winapi-0.2.8
winapi-0.3.9
winapi-build-0.1.1
winapi-i686-pc-windows-gnu-0.4.0
winapi-util-0.1.5
winapi-x86_64-pc-windows-gnu-0.4.0
winit-0.24.0
winreg-0.7.0
winreg-0.8.0
winres-0.1.11
wio-0.2.2
ws2_32-sys-0.2.1
x11-dl-2.18.5
xcursor-0.3.3
xdg-2.2.0
xi-unicode-0.2.1
xi-unicode-0.3.0
xml-rs-0.8.3
yasna-0.4.0
"

inherit cargo

if [[ ${PV} == 9999 ]]; then
	EGIT_REPO_URI="https://github.com/alvr-org/ALVR.git"
	inherit git-r3
else
	COMMIT="ab9f6eb78114181ff3e8252706e578bb5de6343c"
	#SRC_URI="https://github.com/alvr-org/ALVR/archive/refs/tags/v${PV}.tar.gz"
	SRC_URI="https://github.com/alvr-org/ALVR/archive/${COMMIT}.tar.gz -> ${P}-${COMMIT}.tar.gz"
	S="${WORKDIR}/${PN}-${COMMIT}"
	KEYWORDS="~amd64"
fi

SRC_URI="${SRC_URI} $(cargo_crate_uris ${CRATES})"
RESTRICT="mirror"

src_unpack() {
	git-r3_src_unpack
	cargo_src_unpack
}

src_compile() {
	export CARGO_NET_OFFLINE=true
	cargo xtask build-server --release || die
}

src_install() {
	cp -r "${S}/build/alvr_server_linux" "${D}/usr" || die
}
