From 08f421b63cdb1a4500e6406242e63b4cfe4ac9ac Mon Sep 17 00:00:00 2001 From: AngelBePro Date: Tue, 1 Dec 2026 03:35:09 +0200 Subject: [PATCH] shell: resolve symlinked OpenXR active runtime library paths manifest_library() anchored a relative runtime.library_path to manifest.parent(), which is lexical. When the active runtime is the common ~/.config/openxr/1/active_runtime.json symlink (e.g. WiVRn, SteamVR), that resolved against the symlink's directory and reported a missing library even though the target manifest's relative path was valid. Canonicalize the manifest before taking its parent, falling back to the original path on failure. Adds a regression test covering the symlinked active-runtime case. --- crates/cordial-shell/src/vr.rs | 105 ++++++++++++++++++++++++++------- 1 file changed, 84 insertions(+), 21 deletions(-) diff --git a/crates/cordial-shell/src/vr.rs b/crates/cordial-shell/src/vr.rs index 6741a682..40e2ea14 100644 --- a/crates/cordial-shell/src/vr.rs +++ b/crates/cordial-shell/src/vr.rs @@ -95,8 +95,13 @@ impl Places { config_dirs: dirs("XDG_CONFIG_DIRS", "/etc/xdg"), data_home: under_home("XDG_DATA_HOME", ".local/share"), data_dirs: dirs("XDG_DATA_DIRS", "/usr/local/share:/usr/share"), - wivrn_flatpak: wivrn_flatpak_location() - .or_else(|| flatpak_install_on_disk(home.as_deref(), Path::new("/var/lib/flatpak"), WIVRN_FLATPAK)), + wivrn_flatpak: wivrn_flatpak_location().or_else(|| { + flatpak_install_on_disk( + home.as_deref(), + Path::new("/var/lib/flatpak"), + WIVRN_FLATPAK, + ) + }), sandboxed: Path::new("/.flatpak-info").exists(), runtime_dir: std::env::var_os("XDG_RUNTIME_DIR").map(PathBuf::from), home, @@ -248,14 +253,17 @@ pub fn manifest_name(path: &Path) -> String { /// The library a manifest names, resolved as the loader resolves it: an /// absolute path as given, a relative one against the manifest's directory. +/// The manifest is canonicalized first, so a symlinked active_runtime.json +/// (common in ~/.config/openxr/1) resolves relative paths against the target +/// manifest's directory, not the symlink's. pub fn manifest_library(manifest: &Path) -> Option { let v = read_manifest(manifest)?; let lib = PathBuf::from(v.pointer("/runtime/library_path")?.as_str()?); - Some(if lib.is_absolute() { - lib - } else { - manifest.parent()?.join(lib) - }) + if lib.is_absolute() { + return Some(lib); + } + let base = std::fs::canonicalize(manifest).unwrap_or_else(|_| manifest.to_path_buf()); + Some(base.parent()?.join(lib)) } /// What a launch should use, from the setting's value. @@ -370,7 +378,8 @@ pub fn wivrn_start_command(places: &Places) -> String { /// What Settings → VR's Play in VR row says when no Quest build has been imported, which is the /// first thing missing on every machine that has never been set up for VR. -pub const NO_QUEST_BUILD: &str = "Import the Quest build of Roblox from your headset in Settings → VR."; +pub const NO_QUEST_BUILD: &str = + "Import the Quest build of Roblox from your headset in Settings → VR."; /// Everything Play in VR needs, gathered once. #[derive(Debug, Clone)] @@ -387,13 +396,18 @@ impl Readiness { pub fn gather(setting: Option<&str>) -> Self { let places = Places::of_this_machine(); let (sandboxed, runtime_dir) = (places.sandboxed, places.runtime_dir.clone()); - Self::gather_in(setting, &places, cordial_update::quest::current(), move || { - if sandboxed { - wivrn_socket_present(runtime_dir.as_deref()) - } else { - wivrn_server_running() - } - }) + Self::gather_in( + setting, + &places, + cordial_update::quest::current(), + move || { + if sandboxed { + wivrn_socket_present(runtime_dir.as_deref()) + } else { + wivrn_server_running() + } + }, + ) } pub fn gather_in( @@ -525,6 +539,36 @@ mod tests { } } + #[test] + fn a_symlinked_active_runtime_resolves_relative_library_paths_against_the_target() { + let root = scratch("symlink-runtime"); + let p = places(&root); + // The real manifest lives under /usr/share, like a distro-packaged + // runtime, and names its library with a relative path. + manifest( + &root.join("usr/share/openxr/1/openxr_wivrn.json"), + "WiVRn", + "../../../lib/wivrn/libopenxr_wivrn.so", + ); + library(&root.join("usr/lib/wivrn/libopenxr_wivrn.so")); + // The user's active runtime is a symlink to that manifest, which is how + // WiVRn and others register themselves in ~/.config/openxr/1. + let link = root.join("home/.config/openxr/1/active_runtime.json"); + std::fs::create_dir_all(link.parent().unwrap()).unwrap(); + #[cfg(unix)] + std::os::unix::fs::symlink(root.join("usr/share/openxr/1/openxr_wivrn.json"), &link) + .unwrap(); + + match resolve(None, &p) { + Chosen::System(r) => { + assert_eq!(r.name, "WiVRn"); + assert_eq!(r.manifest, link); + } + other => panic!("{other:?}"), + } + let _ = std::fs::remove_dir_all(&root); + } + #[test] fn the_users_active_runtime_wins_over_the_systems() { let root = scratch("active"); @@ -671,7 +715,11 @@ mod tests { // user's ~/.config beside it, which does. p.config_home = Some(root.join("home/.var/app/io.github.luohoa97.Cordial/config")); library(&root.join("lib/w.so")); - manifest(&root.join("home/.config/openxr/1/active_runtime.json"), "WiVRn", &root.join("lib/w.so").to_string_lossy()); + manifest( + &root.join("home/.config/openxr/1/active_runtime.json"), + "WiVRn", + &root.join("lib/w.so").to_string_lossy(), + ); let users = root.join("home/.config/openxr/1/active_runtime.json"); assert_ne!( system_active(&p).map(|r| r.manifest), @@ -712,13 +760,28 @@ mod tests { let root = scratch("fpdisk"); let home = root.join("home"); let system = root.join("var/lib/flatpak"); - assert_eq!(flatpak_install_on_disk(Some(&home), &system, WIVRN_FLATPAK), None); - let sys = system.join("app").join(WIVRN_FLATPAK).join("current/active"); + assert_eq!( + flatpak_install_on_disk(Some(&home), &system, WIVRN_FLATPAK), + None + ); + let sys = system + .join("app") + .join(WIVRN_FLATPAK) + .join("current/active"); std::fs::create_dir_all(sys.join("files")).unwrap(); - assert_eq!(flatpak_install_on_disk(Some(&home), &system, WIVRN_FLATPAK), Some(sys)); - let user = home.join(".local/share/flatpak/app").join(WIVRN_FLATPAK).join("current/active"); + assert_eq!( + flatpak_install_on_disk(Some(&home), &system, WIVRN_FLATPAK), + Some(sys) + ); + let user = home + .join(".local/share/flatpak/app") + .join(WIVRN_FLATPAK) + .join("current/active"); std::fs::create_dir_all(user.join("files")).unwrap(); - assert_eq!(flatpak_install_on_disk(Some(&home), &system, WIVRN_FLATPAK), Some(user)); + assert_eq!( + flatpak_install_on_disk(Some(&home), &system, WIVRN_FLATPAK), + Some(user) + ); let _ = std::fs::remove_dir_all(&root); }