Add support for per-ABI OpenXR manifest
This commit is contained in:
@@ -67,6 +67,7 @@ set(WIVRN_OPENXR_MANIFEST_TYPE "relative" CACHE STRING "How to reference librari
|
||||
if (NOT WIVRN_OPENXR_MANIFEST_TYPE IN_LIST WIVRN_OPENXR_MANIFEST_TYPE_VALUES)
|
||||
message(FATAL_ERROR "WIVRN_OPENXR_MANIFEST_TYPE must be one of ${WIVRN_OPENXR_MANIFEST_TYPE_VALUES}")
|
||||
endif()
|
||||
option(WIVRN_OPENXR_MANIFEST_ABI "Generate an ABI specific OpenXR manifest")
|
||||
|
||||
option(ENABLE_COLOURED_OUTPUT "Always produce ANSI-coloured output (GNU/Clang only)." ON)
|
||||
|
||||
|
||||
@@ -263,12 +263,23 @@ if (WIVRN_BUILD_SERVER_LIBRARY)
|
||||
# Workaround as generate_openxr_runtime_manifest_at_install uses target name as library path
|
||||
add_library(monado_wivrn ALIAS monado)
|
||||
|
||||
if (WIVRN_OPENXR_MANIFEST_ABI)
|
||||
if (CMAKE_C_COMPILER_ARCHITECTURE_ID MATCHES "i.86")
|
||||
set(_filename openxr_wivrn.i686.json)
|
||||
else()
|
||||
set(_filename openxr_wivrn.${CMAKE_C_COMPILER_ARCHITECTURE_ID}.json)
|
||||
endif()
|
||||
else()
|
||||
set(_filename openxr_wivrn.json)
|
||||
endif()
|
||||
|
||||
generate_openxr_runtime_manifest_at_install(
|
||||
${_extra_args}
|
||||
RUNTIME_TARGET ${RUNTIME_TARGET}
|
||||
DESTINATION share/openxr/1
|
||||
RELATIVE_RUNTIME_DIR ${CMAKE_INSTALL_LIBDIR}/wivrn
|
||||
LIBMONADO monado_wivrn
|
||||
OUT_FILENAME ${_filename}
|
||||
)
|
||||
|
||||
install(TARGETS ${RUNTIME_TARGET} monado
|
||||
|
||||
+67
-21
@@ -23,29 +23,42 @@
|
||||
#include "utils/overloaded.h"
|
||||
#include "utils/xdg_base_directory.h"
|
||||
#include "wivrn_config.h"
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
static std::vector<std::filesystem::path> filter_files(const std::filesystem::path & directory, const std::string prefix)
|
||||
{
|
||||
std::vector<std::filesystem::path> result;
|
||||
for (const auto & file: std::filesystem::directory_iterator{directory})
|
||||
{
|
||||
if (file.path().filename().native().starts_with(prefix))
|
||||
result.push_back(file.path());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
std::filesystem::path active_runtime::manifest_path()
|
||||
std::vector<std::filesystem::path> active_runtime::manifest_path()
|
||||
{
|
||||
const std::filesystem::path install_location = "share/openxr/1/openxr_wivrn.json";
|
||||
const std::filesystem::path location = "share/openxr/1";
|
||||
const std::filesystem::path prefix = "openxr_wivrn";
|
||||
// Check if in a flatpak
|
||||
if (auto path = flatpak_key(flatpak::section::instance, "app-path"))
|
||||
return *path / install_location.relative_path();
|
||||
return filter_files(*path / location, prefix);
|
||||
|
||||
// Check if running from build directory
|
||||
auto exe = std::filesystem::read_symlink("/proc/self/exe");
|
||||
auto dev_manifest = exe.parent_path().parent_path() / "openxr_wivrn-dev.json";
|
||||
if (std::filesystem::exists(dev_manifest))
|
||||
return dev_manifest;
|
||||
return {dev_manifest};
|
||||
|
||||
// Assume we are installed
|
||||
return std::filesystem::path(WIVRN_INSTALL_PREFIX) / install_location;
|
||||
return filter_files(WIVRN_INSTALL_PREFIX / location, prefix);
|
||||
}
|
||||
|
||||
std::filesystem::path active_runtime::openvr_compat_path()
|
||||
@@ -111,18 +124,51 @@ static const std::filesystem::path & backup_and_symlink(
|
||||
return location;
|
||||
}
|
||||
|
||||
static std::string get_abi(const std::filesystem::path & filename)
|
||||
{
|
||||
std::string abi = filename.stem().extension();
|
||||
// https://registry.khronos.org/OpenXR/specs/1.0/loader.html#architecture-identifiers
|
||||
if (not abi.empty() and
|
||||
std::ranges::contains(std::array{
|
||||
"x32",
|
||||
"x86_64",
|
||||
"i686",
|
||||
"aarch64",
|
||||
"armv7a-vfp",
|
||||
"armv5te",
|
||||
"mips64",
|
||||
"mips",
|
||||
"ppc64",
|
||||
"ppc64el",
|
||||
"s390x",
|
||||
"hppa",
|
||||
"alpha",
|
||||
"ia64",
|
||||
"m68k",
|
||||
"m68k",
|
||||
"riscv64",
|
||||
"sparc64",
|
||||
},
|
||||
abi.substr(1)))
|
||||
return abi;
|
||||
return "";
|
||||
}
|
||||
|
||||
active_runtime::active_runtime() :
|
||||
pid(getpid())
|
||||
{
|
||||
try
|
||||
for (const auto & manifest: manifest_path())
|
||||
{
|
||||
this->active_runtime_json = backup_and_symlink(
|
||||
xdg_config_home() / "openxr/1/active_runtime.json",
|
||||
manifest_path());
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
std::cerr << "Cannot set active OpenXR runtime: " << e.what() << std::endl;
|
||||
try
|
||||
{
|
||||
active_runtime_json.push_back(backup_and_symlink(
|
||||
xdg_config_home() / ("openxr/1/active_runtime" + get_abi(manifest) + ".json"),
|
||||
manifest));
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
std::cerr << "Cannot set active OpenXR runtime: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
@@ -153,17 +199,17 @@ active_runtime::~active_runtime()
|
||||
{
|
||||
if (pid != getpid())
|
||||
return;
|
||||
try
|
||||
for (const auto & manifest: active_runtime_json)
|
||||
{
|
||||
if (not active_runtime_json.empty())
|
||||
try
|
||||
{
|
||||
std::filesystem::remove(active_runtime_json);
|
||||
move_file(backup_name(active_runtime_json), active_runtime_json);
|
||||
std::filesystem::remove(manifest);
|
||||
move_file(backup_name(manifest), manifest);
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
std::cerr << "Cannot unset active OpenXR runtime " << manifest << ": " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception & e)
|
||||
{
|
||||
std::cerr << "Cannot unset active OpenXR runtime: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
try
|
||||
|
||||
@@ -20,13 +20,14 @@
|
||||
|
||||
#include <filesystem>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
namespace wivrn
|
||||
{
|
||||
|
||||
class active_runtime
|
||||
{
|
||||
std::filesystem::path active_runtime_json;
|
||||
std::vector<std::filesystem::path> active_runtime_json;
|
||||
std::filesystem::path openvr_manifest;
|
||||
pid_t pid;
|
||||
|
||||
@@ -36,7 +37,7 @@ public:
|
||||
active_runtime & operator=(const active_runtime &) = delete;
|
||||
~active_runtime();
|
||||
|
||||
static std::filesystem::path manifest_path();
|
||||
static std::vector<std::filesystem::path> manifest_path();
|
||||
static std::filesystem::path openvr_compat_path();
|
||||
};
|
||||
} // namespace wivrn
|
||||
|
||||
Reference in New Issue
Block a user