Merge branch 'feat/libmonado-manifest' into 'main'

Feat/libmonado manifest

See merge request gabmus/envision!53

Related to https://gitlab.freedesktop.org/monado/monado/-/merge_requests/2285
This commit is contained in:
GabMus 2024-07-21 06:25:20 +00:00
commit 6162a1cf3c

View file

@ -4,13 +4,15 @@ use crate::{
profile::{Profile, XRServiceType}, profile::{Profile, XRServiceType},
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::path::Path; use std::path::{Path, PathBuf};
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ActiveRuntimeInnerRuntime { pub struct ActiveRuntimeInnerRuntime {
#[serde(rename = "VALVE_runtime_is_steamvr")] #[serde(rename = "VALVE_runtime_is_steamvr")]
pub valve_runtime_is_steamvr: Option<bool>, pub valve_runtime_is_steamvr: Option<bool>,
pub library_path: String, pub library_path: String,
#[serde(rename = "MND_libmonado_path")]
pub libmonado_path: Option<PathBuf>,
pub name: Option<String>, pub name: Option<String>,
} }
@ -91,6 +93,7 @@ fn build_steam_active_runtime() -> ActiveRuntime {
"{data}/Steam/steamapps/common/SteamVR/bin/linux64/vrclient.so", "{data}/Steam/steamapps/common/SteamVR/bin/linux64/vrclient.so",
data = get_xdg_data_dir() data = get_xdg_data_dir()
), ),
libmonado_path: None,
name: Some("SteamVR".into()), name: Some("SteamVR".into()),
}, },
} }
@ -103,36 +106,45 @@ pub fn set_current_active_runtime_to_steam() -> anyhow::Result<()> {
} }
pub fn build_profile_active_runtime(profile: &Profile) -> ActiveRuntime { pub fn build_profile_active_runtime(profile: &Profile) -> ActiveRuntime {
let build_oxr_so_path = |lib64: bool| { let build_path = |lib64: bool, prefix: &str| {
format!( PathBuf::from(profile.prefix.clone())
"{prefix}/{libdir}/libopenxr_{xrservice}.so", .join(match lib64 {
prefix = profile.prefix,
xrservice = match profile.xrservice_type {
XRServiceType::Monado => "monado",
XRServiceType::Wivrn => "wivrn",
},
libdir = match lib64 {
true => "lib64", true => "lib64",
false => "lib", false => "lib",
} })
.join(
prefix.to_string()
+ match profile.xrservice_type {
XRServiceType::Monado => "monado.so",
XRServiceType::Wivrn => "wivrn.so",
},
) )
}; };
let mut oxr_so = build_oxr_so_path(false); let mut oxr_so = build_path(false, "libopenxr_");
if !oxr_so.exists() {
if !Path::new(&oxr_so).is_file() { let alt = build_path(true, "libopenxr_");
let alt = build_oxr_so_path(true); if alt.exists() {
if Path::new(&alt).is_file() {
oxr_so = alt; oxr_so = alt;
} }
} }
let mut monado_so = Some(build_path(false, "lib"));
if !monado_so.as_ref().unwrap().exists() {
let alt = build_path(true, "lib");
if alt.exists() {
monado_so = Some(alt);
} else {
monado_so = None;
}
}
ActiveRuntime { ActiveRuntime {
file_format_version: "1.0.0".into(), file_format_version: "1.0.0".into(),
runtime: ActiveRuntimeInnerRuntime { runtime: ActiveRuntimeInnerRuntime {
name: None, name: None,
valve_runtime_is_steamvr: None, valve_runtime_is_steamvr: None,
library_path: oxr_so, libmonado_path: monado_so,
library_path: oxr_so.to_string_lossy().into_owned(),
}, },
} }
} }
@ -199,6 +211,7 @@ mod tests {
library_path: library_path:
"/home/user/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrclient.so" "/home/user/.local/share/Steam/steamapps/common/SteamVR/bin/linux64/vrclient.so"
.into(), .into(),
libmonado_path: None,
name: Some("SteamVR".into()), name: Some("SteamVR".into()),
}, },
}; };
@ -213,6 +226,7 @@ mod tests {
runtime: ActiveRuntimeInnerRuntime { runtime: ActiveRuntimeInnerRuntime {
valve_runtime_is_steamvr: None, valve_runtime_is_steamvr: None,
library_path: "/usr/lib64/libopenxr_monado.so".into(), library_path: "/usr/lib64/libopenxr_monado.so".into(),
libmonado_path: None,
name: None, name: None,
}, },
}; };