Unverified Commit c55ab2d2 authored by K900's avatar K900 Committed by GitHub
Browse files

mangohud: 0.7.2 -> 0.8.0 (#381317)

parents df893ce3 b25b77a0
Loading
Loading
Loading
Loading
+100 −111
Original line number Diff line number Diff line
{ lib
, stdenv
, fetchFromGitLab
, fetchFromGitHub
, fetchurl
, replaceVars
, coreutils
, curl
, gnugrep
, gnused
, xdg-utils
, dbus
, hwdata
, mangohud32
, addDriverRunpath
, appstream
, git
, glslang
, mako
, mesa-demos
, meson
, ninja
, pkg-config
, unzip
, libXNVCtrl
, wayland
, libX11
, nlohmann_json
, spdlog
, glew
, glfw
, xorg
, gamescopeSupport ? true # build mangoapp and mangohudctl
, lowerBitnessSupport ? stdenv.hostPlatform.isx86_64 # Support 32 bit on 64bit
, nix-update-script
, libxkbcommon
{
  lib,
  stdenv,
  fetchFromGitHub,
  fetchurl,
  replaceVars,
  coreutils,
  curl,
  gnugrep,
  gnused,
  xdg-utils,
  dbus,
  hwdata,
  mangohud32,
  addDriverRunpath,
  appstream,
  glslang,
  mako,
  meson,
  ninja,
  pkg-config,
  unzip,
  libX11,
  libXNVCtrl,
  wayland,
  nlohmann_json,
  spdlog,
  glew,
  glfw,
  xorg,
  gamescopeSupport ? true, # build mangoapp and mangohudctl
  lowerBitnessSupport ? stdenv.hostPlatform.isx86_64, # Support 32 bit on 64bit
  nix-update-script,
  libxkbcommon,
}:

let
  # Derived from subprojects/cmocka.wrap
  cmocka = {
    src = fetchFromGitLab {
      owner = "cmocka";
      repo = "cmocka";
      rev = "59dc0013f9f29fcf212fe4911c78e734263ce24c";
      hash = "sha256-IbAZOC0Q60PrKlKVWsgg/PFDV0PLb/yy+Iz/4Iziny0=";
  # Derived from subprojects/imgui.wrap
  imgui = rec {
    version = "1.89.9";
    src = fetchFromGitHub {
      owner = "ocornut";
      repo = "imgui";
      tag = "v${version}";
      hash = "sha256-0k9jKrJUrG9piHNFQaBBY3zgNIKM23ZA879NY+MNYTU=";
    };
    patch = fetchurl {
      url = "https://wrapdb.mesonbuild.com/v2/imgui_${version}-1/get_patch";
      hash = "sha256-myEpDFl9dr+NTus/n/oCSxHZ6mxh6R1kjMyQtChD1YQ=";
    };
  };

@@ -53,7 +56,7 @@ let
    src = fetchFromGitHub {
      owner = "epezent";
      repo = "implot";
      rev = "refs/tags/v${version}";
      tag = "v${version}";
      hash = "sha256-/wkVsgz3wiUVZBCgRl2iDD6GWb+AoHN+u0aeqHHgem0=";
    };
    patch = fetchurl {
@@ -62,28 +65,13 @@ let
    };
  };

  # Derived from subprojects/imgui.wrap
  imgui = rec {
    version = "1.89.9";
    src = fetchFromGitHub {
      owner = "ocornut";
      repo = "imgui";
      rev = "refs/tags/v${version}";
      hash = "sha256-0k9jKrJUrG9piHNFQaBBY3zgNIKM23ZA879NY+MNYTU=";
    };
    patch = fetchurl {
      url = "https://wrapdb.mesonbuild.com/v2/imgui_${version}-1/get_patch";
      hash = "sha256-myEpDFl9dr+NTus/n/oCSxHZ6mxh6R1kjMyQtChD1YQ=";
    };
  };

  # Derived from subprojects/vulkan-headers.wrap
  vulkan-headers = rec {
    version = "1.2.158";
    src = fetchFromGitHub {
      owner = "KhronosGroup";
      repo = "Vulkan-Headers";
      rev = "refs/tags/v${version}";
      tag = "v${version}";
      hash = "sha256-5uyk2nMwV1MjXoa3hK/WUeGLwpINJJEvY16kc5DEaks=";
    };
    patch = fetchurl {
@@ -94,27 +82,28 @@ let
in
stdenv.mkDerivation (finalAttrs: {
  pname = "mangohud";
  version = "0.7.2";
  version = "0.8.0";

  src = fetchFromGitHub {
    owner = "flightlessmango";
    repo = "MangoHud";
    rev = "refs/tags/v${finalAttrs.version}";
    tag = "v${finalAttrs.version}";
    fetchSubmodules = true;
    hash = "sha256-cj/F/DWUDm2AHTJvHgkKa+KdIrfxPWLzI570Dp4VFhs=";
    hash = "sha256-yITiu+2l7PItAmL+6gX9p5Tvf/P8ovttGIo6kJAOqxs=";
  };

  outputs = [ "out" "doc" "man" ];
  outputs = [
    "out"
    "doc"
    "man"
  ];

  # Unpack subproject sources
  postUnpack = ''
    (
      cd "$sourceRoot/subprojects"
      ${lib.optionalString finalAttrs.finalPackage.doCheck ''
        cp -R --no-preserve=mode,ownership ${cmocka.src} cmocka
      ''}
      cp -R --no-preserve=mode,ownership ${implot.src} implot-${implot.version}
      cp -R --no-preserve=mode,ownership ${imgui.src} imgui-${imgui.version}
      cp -R --no-preserve=mode,ownership ${implot.src} implot-${implot.version}
      cp -R --no-preserve=mode,ownership ${vulkan-headers.src} Vulkan-Headers-${vulkan-headers.version}
    )
  '';
@@ -128,13 +117,11 @@ stdenv.mkDerivation (finalAttrs: {
    # Hard code dependencies. Can't use makeWrapper since the Vulkan
    # layer can be used without the mangohud executable by setting MANGOHUD=1.
    (replaceVars ./hardcode-dependencies.patch {

      path = lib.makeBinPath [
        coreutils
        curl
        gnugrep
        gnused
        mesa-demos
        xdg-utils
      ];

@@ -145,35 +132,38 @@ stdenv.mkDerivation (finalAttrs: {

  postPatch = ''
    substituteInPlace bin/mangohud.in \
      --subst-var-by libraryPath ${lib.makeSearchPath "lib/mangohud" ([
      --subst-var-by libraryPath ${
        lib.makeSearchPath "lib/mangohud" (
          [
            (placeholder "out")
      ] ++ lib.optionals lowerBitnessSupport [
        mangohud32
      ])} \
          ]
          ++ lib.optional lowerBitnessSupport mangohud32
        )
      } \
      --subst-var-by version "${finalAttrs.version}" \
      --subst-var-by dataDir ${placeholder "out"}/share

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

  mesonFlags = [
  mesonFlags =
    [
      "-Dwith_wayland=enabled"
      "-Duse_system_spdlog=enabled"
    "-Dtests=${if finalAttrs.finalPackage.doCheck then "enabled" else "disabled"}"
  ] ++ lib.optionals gamescopeSupport [
      "-Dtests=disabled" # amdgpu test segfaults in nix sandbox
    ]
    ++ lib.optionals gamescopeSupport [
      "-Dmangoapp=true"
    "-Dmangoapp_layer=true"
      "-Dmangohudctl=true"
    ];

  nativeBuildInputs = [
    addDriverRunpath
    git
    glslang
    mako
    meson
@@ -183,16 +173,18 @@ stdenv.mkDerivation (finalAttrs: {

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

  buildInputs = [
  buildInputs =
    [
      dbus
      nlohmann_json
      spdlog
  ] ++ lib.optionals gamescopeSupport [
    ]
    ++ lib.optionals gamescopeSupport [
      glew
      glfw
      xorg.libXrandr
@@ -210,11 +202,6 @@ stdenv.mkDerivation (finalAttrs: {
  postInstall = lib.optionalString lowerBitnessSupport ''
    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"
    ''}
  '';

  postFixup =
@@ -224,22 +211,21 @@ stdenv.mkDerivation (finalAttrs: {
        "i686-linux" = "x86";
      };
      layerPlatform = archMap."${stdenv.hostPlatform.system}" or null;
    in
    # We need to give the different layers separate names or else the loader
    # might try the 32-bit one first, fail and not attempt to load the 64-bit
    # layer under the same name.
    in
    lib.optionalString (layerPlatform != null) ''
      substituteInPlace $out/share/vulkan/implicit_layer.d/MangoHud.${layerPlatform}.json \
        --replace "VK_LAYER_MANGOHUD_overlay" "VK_LAYER_MANGOHUD_overlay_${toString stdenv.hostPlatform.parsed.cpu.bits}"
    '' + ''
    ''
    + ''
      # Add OpenGL driver and libXNVCtrl paths to RUNPATH to support NVIDIA cards
      addDriverRunpath "$out/lib/mangohud/libMangoHud.so"
      patchelf --add-rpath ${libXNVCtrl}/lib "$out/lib/mangohud/libMangoHud.so"
    '' + lib.optionalString gamescopeSupport ''
    ''
    + lib.optionalString gamescopeSupport ''
      addDriverRunpath "$out/bin/mangoapp"
    '' + lib.optionalString finalAttrs.finalPackage.doCheck ''
      # libcmocka.so is only used for tests
      rm "$out/lib/libcmocka.so"
    '';

  passthru.updateScript = nix-update-script { };
@@ -250,6 +236,9 @@ stdenv.mkDerivation (finalAttrs: {
    changelog = "https://github.com/flightlessmango/MangoHud/releases/tag/v${finalAttrs.version}";
    platforms = platforms.linux;
    license = licenses.mit;
    maintainers = with maintainers; [ kira-bruneau zeratax ];
    maintainers = with maintainers; [
      kira-bruneau
      zeratax
    ];
  };
})
+2 −2
Original line number Diff line number Diff line
@@ -12,10 +12,10 @@ index 7379af1..4eef3fe 100644
         return false;
     }
diff --git a/src/logging.cpp b/src/logging.cpp
index 7d4cb98..256128c 100644
index ca986d4..c4d99ea 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -27,8 +27,12 @@ string exec(string command) {
@@ -28,8 +28,12 @@ string exec(string command) {
 #endif
     std::array<char, 128> buffer;
     std::string result;
+8 −16
Original line number Diff line number Diff line
diff --git a/bin/mangohud.in b/bin/mangohud.in
index 53c72ef..18240ea 100755
index 4cffeed..c19b635 100755
--- a/bin/mangohud.in
+++ b/bin/mangohud.in
@@ -13,13 +13,15 @@ fi
@@ -13,7 +13,9 @@ fi
 DISABLE_LD_PRELOAD="cs2.sh
 some_other_exe"
 "
 
-MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_opengl.so"
-MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_shim.so"
+LD_LIBRARY_PATH="@libraryPath@${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
+XDG_DATA_DIRS="@dataDir@${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}"
+MANGOHUD_LIB_NAME="libMangoHud_opengl.so"
 
 if [ "$1" = "--dlsym" ]; then
-    MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
+    MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
     shift  # shift will only be executed if $1 is "--dlsym"
 elif [ "$MANGOHUD_DLSYM" = "1" ]; then
-    MANGOHUD_LIB_NAME="@ld_libdir_mangohud@libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
+    MANGOHUD_LIB_NAME="libMangoHud_dlsym.so:${MANGOHUD_LIB_NAME}"
 fi
+MANGOHUD_LIB_NAME="libMangoHud_shim.so"
 
 if [ "$1" = "--version" ]; then
@@ -41,7 +43,7 @@ for exe in $DISABLE_LD_PRELOAD; do
     echo @version@
@@ -39,7 +41,7 @@ for exe in $DISABLE_LD_PRELOAD; do
 done
 
 if [ "$disable_preload" = true ]; then
@@ -30,7 +22,7 @@ index 53c72ef..18240ea 100755
 else
     # Make sure we don't append mangohud lib multiple times
     # otherwise, this could cause issues with the steam runtime
@@ -54,5 +56,5 @@ else
@@ -52,5 +54,5 @@ else
             LD_PRELOAD="${LD_PRELOAD:+$LD_PRELOAD:}${MANGOHUD_LIB_NAME}"
     esac