diff --git a/client/scenes/lobby.cpp b/client/scenes/lobby.cpp index 4db1456d..f2358ecd 100644 --- a/client/scenes/lobby.cpp +++ b/client/scenes/lobby.cpp @@ -25,13 +25,12 @@ #include "imgui.h" #include "input_profile.h" #include "openxr/openxr.h" +#include "protocol_version.h" #include "render/scene_data.h" #include "render/scene_renderer.h" #include "stream.h" #include "utils/overloaded.h" -#include "version.h" #include "wivrn_client.h" -#include "wivrn_packets.h" #include "xr/passthrough.h" #include "xr/space.h" #include diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 9e0b7751..032564e8 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -23,6 +23,12 @@ endif() configure_file(wivrn_config.h.in wivrn_config.h) +add_library(wivrn-common-base STATIC + utils/xdg_base_directory.cpp + utils/flatpak.cpp + ${CMAKE_CURRENT_BINARY_DIR}/version.cpp +) + add_library(wivrn-common STATIC wivrn_sockets.cpp utils/xdg_base_directory.cpp @@ -30,7 +36,6 @@ add_library(wivrn-common STATIC vk/error_category.cpp vk/vk_allocator.cpp vk/vk_mem_alloc.cpp - ${CMAKE_CURRENT_BINARY_DIR}/version.cpp ) if(ANDROID) @@ -55,8 +60,7 @@ else() target_link_libraries(wivrn-common PUBLIC Vulkan::Headers) endif() -target_link_libraries(wivrn-common PUBLIC Boost::pfr wivrn-external) +target_include_directories(wivrn-common-base PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) +target_link_libraries(wivrn-common PUBLIC Boost::pfr wivrn-external wivrn-common-base) target_compile_features(wivrn-common PRIVATE cxx_std_20) target_compile_definitions(wivrn-common PUBLIC VULKAN_HPP_NO_STRUCT_CONSTRUCTORS) - -target_include_directories(wivrn-common PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/common/protocol_version.h b/common/protocol_version.h new file mode 100644 index 00000000..a6740d40 --- /dev/null +++ b/common/protocol_version.h @@ -0,0 +1,10 @@ +#include "wivrn_packets.h" +#include "wivrn_serialization.h" + +#pragma once + +namespace wivrn +{ +using protocol = std::variant; +static inline const constinit auto protocol_version = serialization_type_hash(); +} // namespace wivrn diff --git a/dashboard/version.cpp.in b/common/utils/flatpak.cpp similarity index 54% rename from dashboard/version.cpp.in rename to common/utils/flatpak.cpp index 206da0cb..466db655 100644 --- a/dashboard/version.cpp.in +++ b/common/utils/flatpak.cpp @@ -1,7 +1,7 @@ /* * WiVRn VR streaming - * Copyright (C) 2022 Guillaume Meunier - * Copyright (C) 2022 Patrick Nicolas + * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2024 Patrick Nicolas * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,10 +17,27 @@ * along with this program. If not, see . */ -#include "version.h" +#include "flatpak.h" -namespace wivrn +#include +#include + +static const std::filesystem::path info_path = "/.flatpak-info"; + +bool wivrn::is_flatpak() { -const char git_version[] = "@GIT_DESC@"; -const char git_commit[] = "@GIT_COMMIT@"; -} // namespace wivrn + return std::filesystem::exists(info_path); +} + +std::optional wivrn::flatpak_key(std::string key) +{ + key += "="; + std::string line; + std::ifstream info(info_path); + while (std::getline(info, line)) + { + if (line.starts_with(key)) + return line.substr(key.size()); + } + return {}; +} diff --git a/dashboard/version.h b/common/utils/flatpak.h similarity index 75% rename from dashboard/version.h rename to common/utils/flatpak.h index 6142992c..0e1a686c 100644 --- a/dashboard/version.h +++ b/common/utils/flatpak.h @@ -1,7 +1,7 @@ /* * WiVRn VR streaming - * Copyright (C) 2022 Guillaume Meunier - * Copyright (C) 2022 Patrick Nicolas + * Copyright (C) 2024 Guillaume Meunier + * Copyright (C) 2024 Patrick Nicolas * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,8 +19,11 @@ #pragma once +#include +#include + namespace wivrn { -extern const char git_version[]; -extern const char git_commit[]; +bool is_flatpak(); +std::optional flatpak_key(std::string key); } // namespace wivrn diff --git a/common/version.h b/common/version.h index 6f9a2aa3..4e33d8ea 100644 --- a/common/version.h +++ b/common/version.h @@ -1,13 +1,7 @@ #pragma once -#include "wivrn_packets.h" -#include "wivrn_serialization.h" - namespace wivrn { -using protocol = std::variant; - extern const char git_version[]; extern const char git_commit[]; -static inline const constinit auto protocol_version = serialization_type_hash(); } // namespace wivrn diff --git a/dashboard/CMakeLists.txt b/dashboard/CMakeLists.txt index 50021eef..ea4dd93f 100644 --- a/dashboard/CMakeLists.txt +++ b/dashboard/CMakeLists.txt @@ -1,18 +1,3 @@ -if (GIT_DESC) - configure_file(version.cpp.in version.cpp) -else () - add_custom_target(wivrn-dashboard-version ALL - COMMAND ${CMAKE_COMMAND} - -D GIT_EXECUTABLE=${GIT_EXECUTABLE} - -D INPUT_FILE=${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in - -D OUTPUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/version.cpp - -D CMAKE_PROJECT_VERSION=${CMAKE_PROJECT_VERSION} - -P ${CMAKE_SOURCE_DIR}/cmake/GitVersion.cmake - BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/version.cpp - SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/version.cpp.in - ) -endif() - # Qt 6.7 changed qt_add_translations() try_compile(AT_LEAST_QT67 SOURCE_FROM_CONTENT check-qt-version.cpp " #include @@ -43,7 +28,6 @@ qt_add_executable(wivrn-dashboard steam_app.h adb.cpp adb.h - ${CMAKE_CURRENT_BINARY_DIR}/version.cpp ) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/wivrn.png @@ -81,6 +65,7 @@ target_link_libraries(wivrn-dashboard PRIVATE Qt6::DBus Qt6::Network nlohmann_json + wivrn-common-base ) if (WIVRN_CHECK_CAPSYSNICE) diff --git a/dashboard/adb.cpp b/dashboard/adb.cpp index c83e601e..89054a2a 100644 --- a/dashboard/adb.cpp +++ b/dashboard/adb.cpp @@ -18,6 +18,8 @@ #include "adb.h" +#include "utils/flatpak.h" + #include #include #include @@ -31,7 +33,7 @@ std::unique_ptr escape_sandbox(const std::string & executable, Args && auto process = std::make_unique(); QStringList args; - if (std::filesystem::exists("/.flatpak-info")) + if (wivrn::is_flatpak()) { process->setProgram("flatpak-spawn"); args.push_back("--host"); diff --git a/dashboard/steam_app.cpp b/dashboard/steam_app.cpp index 1d76c75e..1490c90f 100644 --- a/dashboard/steam_app.cpp +++ b/dashboard/steam_app.cpp @@ -17,6 +17,7 @@ */ #include "steam_app.h" +#include "utils/flatpak.h" #include #include #include @@ -34,7 +35,7 @@ std::string read_vr_manifest() std::filesystem::path vrmanifest = std::string{home ? home : ""} + "/.steam/steam/config/steamapps.vrmanifest"; - if (std::filesystem::exists("/.flatpak-info")) + if (wivrn::is_flatpak()) { QProcess flatpak_spawn; flatpak_spawn.start("flatpak-spawn", {"--host", "cat", QString::fromStdString(vrmanifest)}); diff --git a/server/active_runtime.cpp b/server/active_runtime.cpp index 795d15e4..73939e46 100644 --- a/server/active_runtime.cpp +++ b/server/active_runtime.cpp @@ -18,10 +18,10 @@ */ #include "active_runtime.h" +#include "utils/flatpak.h" #include "utils/xdg_base_directory.h" #include "wivrn_config.h" #include -#include #include namespace wivrn @@ -31,17 +31,8 @@ std::filesystem::path active_runtime::manifest_path() { const std::filesystem::path install_location = "share/openxr/1/openxr_wivrn.json"; // Check if in a flatpak - if (std::filesystem::exists("/.flatpak-info")) - { - const std::string key("app-path="); - std::string line; - std::ifstream info("/.flatpak-info"); - while (std::getline(info, line)) - { - if (line.starts_with(key)) - return line.substr(key.size()) / install_location.relative_path(); - } - } + if (auto path = flatpak_key("app-path")) + return *path / install_location.relative_path(); // Check if running from build directory auto exe = std::filesystem::read_symlink("/proc/self/exe"); diff --git a/server/main.cpp b/server/main.cpp index 0890fa54..7bbf02bc 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -14,7 +14,9 @@ #include "driver/configuration.h" #include "exit_codes.h" #include "hostname.h" +#include "protocol_version.h" #include "start_application.h" +#include "utils/flatpak.h" #include "version.h" #include "wivrn_config.h" #include "wivrn_ipc.h" @@ -131,19 +133,13 @@ void display_child_status(int wstatus, const std::string & name) static std::filesystem::path flatpak_app_path() { - const std::string key("app-path="); - std::string line; - std::ifstream info("/.flatpak-info"); - while (std::getline(info, line)) + if (auto value = flatpak_key("app-path")) { - if (line.starts_with(key)) - { - std::filesystem::path path = line.substr(key.size()); - while (path != "" and path != path.parent_path() and path.filename() != "io.github.wivrn.wivrn") - path = path.parent_path(); + std::filesystem::path path = *value; + while (path != "" and path != path.parent_path() and path.filename() != "io.github.wivrn.wivrn") + path = path.parent_path(); - return path; - } + return path; } return "/"; @@ -154,7 +150,7 @@ static std::string steam_command() std::string pressure_vessel_filesystems_rw = "$XDG_RUNTIME_DIR/" XRT_IPC_MSG_SOCK_FILENAME; // Check if in a flatpak - if (std::filesystem::exists("/.flatpak-info")) + if (is_flatpak()) { std::string app_path = flatpak_app_path().string(); // /usr and /var are remapped by steam diff --git a/server/start_application.cpp b/server/start_application.cpp index 29af037c..6a8c2efa 100644 --- a/server/start_application.cpp +++ b/server/start_application.cpp @@ -9,8 +9,8 @@ #include "start_application.h" #include "driver/configuration.h" +#include "utils/flatpak.h" -#include #include #include #include @@ -235,7 +235,7 @@ int wivrn::exec_application(configuration config) std::string executable; std::vector args; - if (std::filesystem::exists("/.flatpak-info")) + if (is_flatpak()) { executable = "flatpak-spawn"; args.push_back("flatpak-spawn");