Unverified Commit fe3df077 authored by Kira Bruneau's avatar Kira Bruneau Committed by GitHub
Browse files

Merge pull request #226170 from kira-bruneau/mangohud

mangohud: 0.6.8 -> 0.6.9
parents 7ecb9bdf 332d775c
Loading
Loading
Loading
Loading
+62 −77
Original line number Diff line number Diff line
@@ -11,11 +11,9 @@
, xdg-utils
, dbus
, hwdata
, libX11
, mangohud32
, appstream
, addOpenGLRunpath
, glslang
, makeWrapper
, mako
, meson
, ninja
@@ -23,12 +21,14 @@
, unzip
, libXNVCtrl
, wayland
, libX11
, nlohmann_json
, spdlog
, glew
, glfw
, nlohmann_json
, xorg
, addOpenGLRunpath
, gamescopeSupport ? true # build mangoapp and mangohudctl
, nix-update-script
}:

let
@@ -39,32 +39,11 @@ let
      owner = "ocornut";
      repo = "imgui";
      rev = "refs/tags/v${version}";
      sha256 = "sha256-rRkayXk3xz758v6vlMSaUu5fui6NR8Md3njhDB0gJ18=";
      hash = "sha256-rRkayXk3xz758v6vlMSaUu5fui6NR8Md3njhDB0gJ18=";
    };
    patch = fetchurl {
      url = "https://wrapdb.mesonbuild.com/v2/imgui_${version}-1/get_patch";
      sha256 = "sha256-bQC0QmkLalxdj4mDEdqvvOFtNwz2T1MpTDuMXGYeQ18=";
    };
  };

  # Derived from subprojects/spdlog.wrap
  #
  # NOTE: We only statically link spdlog due to a bug in pressure-vessel:
  # https://github.com/ValveSoftware/steam-runtime/issues/511
  #
  # Once this fix is released upstream, we should switch back to using
  # the system provided spdlog
  spdlog = rec {
    version = "1.8.5";
    src = fetchFromGitHub {
      owner = "gabime";
      repo = "spdlog";
      rev = "refs/tags/v${version}";
      sha256 = "sha256-D29jvDZQhPscaOHlrzGN1s7/mXlcsovjbqYpXd7OM50=";
    };
    patch = fetchurl {
      url = "https://wrapdb.mesonbuild.com/v2/spdlog_${version}-1/get_patch";
      sha256 = "sha256-PDjyddV5KxKGORECWUMp6YsXc3kks0T5gxKrCZKbdL4=";
      hash = "sha256-bQC0QmkLalxdj4mDEdqvvOFtNwz2T1MpTDuMXGYeQ18=";
    };
  };

@@ -82,16 +61,17 @@ let
      hash = "sha256-hgNYz15z9FjNHoj4w4EW0SOrQh1c4uQSnsOOrt2CDhc=";
    };
  };
in stdenv.mkDerivation rec {
in
stdenv.mkDerivation (finalAttrs: {
  pname = "mangohud";
  version = "0.6.8";
  version = "0.6.9";

  src = fetchFromGitHub {
    owner = "flightlessmango";
    repo = "MangoHud";
    rev = "refs/tags/v${version}";
    rev = "refs/tags/v${finalAttrs.version}";
    fetchSubmodules = true;
    sha256 = "sha256-jfmgN90kViHa7vMOjo2x4bNY2QbLk93uYEvaA4DxYvg=";
    hash = "sha256-wvidO9LAZwVUZhYYWnelSiP0Q1WTPoCg6pMXsoJBPPg=";
  };

  outputs = [ "out" "doc" "man" ];
@@ -100,13 +80,15 @@ in stdenv.mkDerivation rec {
  postUnpack = ''(
    cd "$sourceRoot/subprojects"
    cp -R --no-preserve=mode,ownership ${imgui.src} imgui-${imgui.version}
    cp -R --no-preserve=mode,ownership ${spdlog.src} spdlog-${spdlog.version}
    cp -R --no-preserve=mode,ownership ${vulkan-headers.src} Vulkan-Headers-${vulkan-headers.version}
  )'';

  env.NIX_CFLAGS_COMPILE = "-I${vulkan-headers.src}/include";

  patches = [
    # Add @libraryPath@ template variable to fix loading the preload
    # library and @dataPath@ to support overlaying Vulkan apps without
    # requiring MangoHud to be installed
    ./preload-nix-workaround.patch

    # Hard code dependencies. Can't use makeWrapper since the Vulkan
    # layer can be used without the mangohud executable by setting MANGOHUD=1.
    (substituteAll {
@@ -122,81 +104,84 @@ in stdenv.mkDerivation rec {
      ];

      libdbus = dbus.lib;
      inherit hwdata libX11;
    })
  ] ++ lib.optionals (stdenv.hostPlatform.system == "x86_64-linux") [
    # Support 32bit OpenGL applications by appending the mangohud32
    # lib path to LD_LIBRARY_PATH.
    #
    # This workaround is necessary since on Nix's build of ld.so, $LIB
    # always expands to lib even when running an 32bit application.
    #
    # See https://github.com/NixOS/nixpkgs/issues/101597.
    (substituteAll {
      src = ./opengl32-nix-workaround.patch;
      inherit mangohud32;
      inherit hwdata;
    })
  ];

  postPatch = ''(
  postPatch = ''
    substituteInPlace bin/mangohud.in \
      --subst-var-by libraryPath ${lib.makeSearchPath "lib/mangohud" ([
        (placeholder "out")
      ] ++ lib.optionals (stdenv.hostPlatform.system == "x86_64-linux") [
        mangohud32
      ])} \
      --subst-var-by dataDir ${placeholder "out"}/share

    (
      cd subprojects
      unzip ${imgui.patch}
    unzip ${spdlog.patch}
      unzip ${vulkan-headers.patch}
  )'';
    )
  '';

  mesonFlags = [
    "-Dwith_wayland=enabled"
    "-Duse_system_spdlog=enabled"
    "-Dtests=disabled" # Tests require AMD GPU
  ] ++ lib.optionals gamescopeSupport [
    "-Dmangoapp_layer=true"
    "-Dmangoapp=true"
    "-Dmangoapp_layer=true"
    "-Dmangohudctl=true"
  ];

  nativeBuildInputs = [
    appstream
    addOpenGLRunpath
    glslang
    makeWrapper
    mako
    meson
    ninja
    pkg-config
    unzip

    # Only the headers are used from these packages
    # The corresponding libraries are loaded at runtime from the app's runpath
    libXNVCtrl
    wayland
    libX11
  ];

  buildInputs = [
    dbus
    libX11
    libXNVCtrl
    wayland
    nlohmann_json
    spdlog
  ] ++ lib.optionals gamescopeSupport [
    glew
    glfw
    nlohmann_json
    xorg.libXrandr
  ];

  # Support 32bit Vulkan applications by linking in 32bit Vulkan layer
  # This is needed for the same reason the 32bit OpenGL workaround is needed.
  # Support 32bit Vulkan applications by linking in 32bit Vulkan layers
  # This is needed for the same reason the 32bit preload workaround is needed.
  postInstall = lib.optionalString (stdenv.hostPlatform.system == "x86_64-linux") ''
    ln -s ${mangohud32}/share/vulkan/implicit_layer.d/MangoHud.json \
      "$out/share/vulkan/implicit_layer.d/MangoHud.x86.json"
    ln -s ${mangohud32}/share/vulkan/implicit_layer.d/MangoHud.x86.json \
      "$out/share/vulkan/implicit_layer.d"

    ${lib.optionalString gamescopeSupport ''
      ln -s ${mangohud32}/share/vulkan/implicit_layer.d/libMangoApp.x86.json \
        "$out/share/vulkan/implicit_layer.d"
    ''}
  '';

  # Support Nvidia cards by adding OpenGL path and support overlaying
  # Vulkan applications without requiring MangoHud to be installed
  # Add OpenGL driver path to RUNPATH to support NVIDIA cards
  postFixup = ''
    wrapProgram "$out/bin/mangohud" \
      --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ addOpenGLRunpath.driverLink ]} \
      --prefix XDG_DATA_DIRS : "$out/share"
  '' + lib.optionalString (gamescopeSupport) ''
    if [[ -e "$out/bin/mangoapp" ]]; then
      wrapProgram "$out/bin/mangoapp" \
        --prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ addOpenGLRunpath.driverLink ]} \
        --prefix XDG_DATA_DIRS : "$out/share"
    fi
    addOpenGLRunpath "$out/lib/mangohud/libMangoHud.so"
    ${lib.optionalString gamescopeSupport ''
      addOpenGLRunpath "$out/bin/mangoapp"
    ''}
  '';

  passthru.updateScript = nix-update-script { };

  meta = with lib; {
    description = "A Vulkan and OpenGL overlay for monitoring FPS, temperatures, CPU/GPU load and more";
    homepage = "https://github.com/flightlessmango/MangoHud";
@@ -204,4 +189,4 @@ in stdenv.mkDerivation rec {
    license = licenses.mit;
    maintainers = with maintainers; [ kira-bruneau zeratax ];
  };
}
})
+5 −15
Original line number Diff line number Diff line
diff --git a/src/dbus.cpp b/src/dbus.cpp
index 3b3cccb..1405725 100644
index 7379af1..4eef3fe 100644
--- a/src/dbus.cpp
+++ b/src/dbus.cpp
@@ -152,7 +152,7 @@ bool dbus_manager::get_media_player_metadata(metadata& meta, std::string name) {
@@ -11,21 +11,11 @@ index 3b3cccb..1405725 100644
         SPDLOG_ERROR("Could not load libdbus-1.so.3");
         return false;
     }
diff --git a/src/loaders/loader_x11.cpp b/src/loaders/loader_x11.cpp
index 4db6f78..c60d08c 100644
--- a/src/loaders/loader_x11.cpp
+++ b/src/loaders/loader_x11.cpp
@@ -89,4 +89,4 @@ void libx11_loader::CleanUp(bool unload) {
 
 }
 
-std::shared_ptr<libx11_loader> g_x11(new libx11_loader("libX11.so.6"));
+std::shared_ptr<libx11_loader> g_x11(new libx11_loader("@libX11@/lib/libX11.so.6"));
diff --git a/src/logging.cpp b/src/logging.cpp
index 1668226..f0c8df5 100644
index 046c847..42782be 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -24,7 +24,11 @@ string exec(string command) {
@@ -26,7 +26,11 @@ string exec(string command) {
 #endif
     std::array<char, 128> buffer;
     std::string result;
@@ -38,10 +28,10 @@ index 1668226..f0c8df5 100644
       return "popen failed!";
     }
diff --git a/src/pci_ids.cpp b/src/pci_ids.cpp
index feec222..6baa707 100644
index 002a843..5a6262b 100644
--- a/src/pci_ids.cpp
+++ b/src/pci_ids.cpp
@@ -24,11 +24,9 @@ std::istream& get_uncommented_line(std::istream& is, std::string &line)
@@ -24,11 +24,9 @@ static std::istream& get_uncommented_line(std::istream& is, std::string &line)
 void parse_pciids()
 {
     std::ifstream file;
+0 −12
Original line number Diff line number Diff line
diff --git a/bin/mangohud.in b/bin/mangohud.in
index e13da99..086443c 100755
--- a/bin/mangohud.in
+++ b/bin/mangohud.in
@@ -23,6 +23,6 @@ fi
 # figure out whether the 32 or 64 bit version should be used, and will search
 # for it in the correct directory
 LD_PRELOAD="${LD_PRELOAD}${LD_PRELOAD:+:}${MANGOHUD_LIB_NAME}"
-LD_LIBRARY_PATH="${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}@ld_libdir_mangohud@"
+LD_LIBRARY_PATH="${LD_LIBRARY_PATH}${LD_LIBRARY_PATH:+:}@ld_libdir_mangohud@:@mangohud32@/lib/mangohud"
 
 exec env MANGOHUD=1 LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" LD_PRELOAD="${LD_PRELOAD}" "$@"
+26 −0
Original line number Diff line number Diff line
diff --git a/bin/mangohud.in b/bin/mangohud.in
index f975224..24936eb 100755
--- a/bin/mangohud.in
+++ b/bin/mangohud.in
@@ -8,16 +8,18 @@ if [ "$#" -eq 0 ]; then
 	exit 1
 fi
 
-MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud.so"
+MANGOHUD_LIB_NAME="libMangoHud.so"
 
 if [ "$1" = "--dlsym" ]; then
 	MANGOHUD_DLSYM=1
-	MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
+	MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
 	shift
 fi
 
 # Preload using the plain filenames of the libs, the dynamic linker will
 # figure out whether the 32 or 64 bit version should be used
 LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}${MANGOHUD_LIB_NAME}"
+LD_LIBRARY_PATH="@libraryPath@${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
+XDG_DATA_DIRS="@dataDir@${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
 
-exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" "$@"
+exec env MANGOHUD=1 LD_PRELOAD="${LD_PRELOAD}" LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" XDG_DATA_DIRS="${XDG_DATA_DIRS}" "$@"