Unverified Commit 1ec96f77 authored by Thiago Kenji Okada's avatar Thiago Kenji Okada Committed by GitHub
Browse files

Merge pull request #198271 from thiagokokada/retroarch-improvements

retroarch,libretro: general improvements
parents 6ddd77b4 784c363b
Loading
Loading
Loading
Loading
+462 −347

File changed.

Preview size limit exceeded, changes collapsed.

+23 −55
Original line number Diff line number Diff line
@@ -6,18 +6,17 @@
, withVulkan ? stdenv.isLinux
, withWayland ? stdenv.isLinux
, alsa-lib
, AppKit
, dbus
, fetchFromGitHub
, ffmpeg_4
, Foundation
, flac
, freetype
, gamemode
, libdrm
, libGL
, libGLU
, libobjc
, libpulseaudio
, libretro-core-info
, libv4l
, libX11
, libXdmcp
@@ -26,71 +25,61 @@
, libxml2
, libXxf86vm
, makeWrapper
, mbedtls
, mesa
, nvidia_cg_toolkit
, pkg-config
, python3
, SDL2
, substituteAll
, udev
, vulkan-loader
, wayland
, zlib
}:

let
  version = "1.12.0";
  libretroCoreInfo = fetchFromGitHub {
    owner = "libretro";
    repo = "libretro-core-info";
    sha256 = "sha256-9Sfp/JkMJIe34YGNRxf93fONOBuQxR2pduoJU+xtuF0=";
    # Upstream didn't tag a new libretro-core-info in 1.12.0 release
    rev = "v1.11.1";
  };
  runtimeLibs =
    lib.optional withVulkan vulkan-loader ++
    lib.optional withGamemode (lib.getLib gamemode);
in
stdenv.mkDerivation rec {
  pname = "retroarch-bare";
  inherit version;
  version = "1.12.0";

  src = fetchFromGitHub {
    owner = "libretro";
    repo = "RetroArch";
    sha256 = "sha256-doLWNA8aTAllxx3zABtvZaegBQEPIi8276zbytPSdBU=";
    hash = "sha256-doLWNA8aTAllxx3zABtvZaegBQEPIi8276zbytPSdBU=";
    rev = "v${version}";
  };

  patches = [
    ./use-fixed-paths.patch
    (substituteAll {
      src = ./use-fixed-path-for-libretro_core_info.patch;
      libretro_info_path = libretro-core-info;
    })
  ];

  postPatch = ''
    substituteInPlace "frontend/drivers/platform_unix.c" \
      --subst-var-by libretro_directory "$out/lib" \
      --subst-var-by libretro_info_path "$out/share/libretro/info" \
      --subst-var-by out "$out"
    substituteInPlace "frontend/drivers/platform_darwin.m" \
      --subst-var-by libretro_directory "$out/lib" \
      --subst-var-by libretro_info_path "$out/share/libretro/info"
  '';

  nativeBuildInputs = [ pkg-config ] ++
    lib.optional withWayland wayland ++
    lib.optional (runtimeLibs != [ ]) makeWrapper;

  buildInputs = [
    ffmpeg_4
    flac
    freetype
    libGL
    libGLU
    libxml2
    mbedtls
    python3
    SDL2
    zlib
  ] ++
  lib.optional enableNvidiaCgToolkit nvidia_cg_toolkit ++
  lib.optional withVulkan vulkan-loader ++
  lib.optional withWayland wayland ++
  lib.optionals stdenv.isDarwin [ libobjc AppKit Foundation ] ++
  lib.optionals stdenv.isLinux [
    alsa-lib
    dbus
@@ -110,6 +99,9 @@ stdenv.mkDerivation rec {

  configureFlags = [
    "--disable-update_cores"
    "--disable-builtinmbedtls"
    "--disable-builtinzlib"
    "--disable-builtinflac"
  ] ++
  lib.optionals stdenv.isLinux [
    "--enable-dbus"
@@ -117,39 +109,13 @@ stdenv.mkDerivation rec {
    "--enable-kms"
  ];

  postInstall = ''
    # TODO: ideally each core should have its own core information
    mkdir -p $out/share/libretro/info
    cp -r ${libretroCoreInfo}/* $out/share/libretro/info
  '' +
  lib.optionalString (runtimeLibs != [ ]) ''
  postInstall = lib.optionalString (runtimeLibs != [ ]) ''
    wrapProgram $out/bin/retroarch \
      --prefix LD_LIBRARY_PATH ':' ${lib.makeLibraryPath runtimeLibs}
  '' +
  lib.optionalString stdenv.isDarwin ''
    # https://github.com/libretro/RetroArch/blob/master/retroarch-apple-packaging.sh
    app=$out/Applications/RetroArch.app
    mkdir -p $app/Contents/MacOS
    cp -r pkg/apple/OSX/* $app/Contents
    cp $out/bin/retroarch $app/Contents/MacOS
    # FIXME: using Info_Metal.plist results in input not working
    # mv $app/Contents/Info_Metal.plist $app/Contents/Info.plist

    substituteInPlace $app/Contents/Info.plist \
      --replace '${"\${EXECUTABLE_NAME}"}' 'RetroArch' \
      --replace '$(PRODUCT_BUNDLE_IDENTIFIER)' 'com.libretro.RetroArch' \
      --replace '${"\${PRODUCT_NAME}"}' 'RetroArch' \
      --replace '${"\${MACOSX_DEPLOYMENT_TARGET}"}' '10.13'

    cp media/retroarch.icns $app/Contents/Resources/
  '';

  preFixup = "rm $out/bin/retroarch-cg2glsl";

  # Workaround for the following error affecting newer versions of Clang:
  # ./config.def.h:xxx:x: error: 'TARGET_OS_TV' is not defined, evaluates to 0 [-Werror,-Wundef-prefix=TARGET_OS_]
  NIX_CFLAGS_COMPILE = lib.optionals stdenv.cc.isClang [ "-Wno-undef-prefix" ];

  passthru.tests = nixosTests.retroarch;

  meta = with lib; {
@@ -159,9 +125,11 @@ stdenv.mkDerivation rec {
    platforms = platforms.unix;
    changelog = "https://github.com/libretro/RetroArch/blob/v${version}/CHANGES.md";
    maintainers = with maintainers; teams.libretro.members ++ [ matthewbauer kolbycrouch ];
    # FIXME: error while building in macOS:
    # "Undefined symbols for architecture <arch>"
    # See also retroarch/wrapper.nix that is also broken in macOS
    mainProgram = "retroarch";
    # If you want to (re)-add support for macOS, see:
    # https://docs.libretro.com/development/retroarch/compilation/osx/
    # and
    # https://github.com/libretro/RetroArch/blob/71eb74d256cb4dc5b8b43991aec74980547c5069/.gitlab-ci.yml#L330
    broken = stdenv.isDarwin;
  };
}
+28 −0
Original line number Diff line number Diff line
{ lib
, stdenvNoCC
, fetchFromGitHub
}:

stdenvNoCC.mkDerivation rec {
  pname = "libretro-core-info";
  version = "1.12.0";

  src = fetchFromGitHub {
    owner = "libretro";
    repo = "libretro-core-info";
    hash = "sha256-ByATDM0V40UJxigqVLyTWkHY5tiCC2dvZebksl8GsUI=";
    rev = "v${version}";
  };

  makeFlags = [ "PREFIX=$(out)" ];

  dontBuild = true;

  meta = with lib; {
    description = "Libretro's core info files";
    homepage = "https://libretro.com";
    license = licenses.mit;
    maintainers = with maintainers; teams.libretro.members ++ [ ];
    platforms = platforms.all;
  };
}
+80 −0
Original line number Diff line number Diff line
{ lib
, stdenv
, core
, makeWrapper
, retroarch
, zlib
, makefile ? "Makefile.libretro"
, extraBuildInputs ? [ ]
, extraNativeBuildInputs ? [ ]
  # Location of resulting RetroArch core on $out
, libretroCore ? "/lib/retroarch/cores"
  # The core filename is derivated from the core name
  # Setting `normalizeCore` to `true` will convert `-` to `_` on the core filename
, normalizeCore ? true
, ...
}@args:

let
  d2u = if normalizeCore then (lib.replaceChars [ "-" ] [ "_" ]) else (x: x);
  coreDir = placeholder "out" + libretroCore;
  coreFilename = "${d2u core}_libretro${stdenv.hostPlatform.extensions.sharedLibrary}";
  mainProgram = "retroarch-${core}";
  extraArgs = builtins.removeAttrs args [
    "lib"
    "stdenv"
    "core"
    "makeWrapper"
    "retroarch"
    "zlib"
    "makefile"
    "extraBuildInputs"
    "extraNativeBuildInputs"
    "libretroCore"
    "normalizeCore"
    "makeFlags"
    "meta"
  ];
in
stdenv.mkDerivation ({
  pname = "libretro-${core}";

  buildInputs = [ zlib ] ++ extraBuildInputs;
  nativeBuildInputs = [ makeWrapper ] ++ extraNativeBuildInputs;

  inherit makefile;

  makeFlags = [
    "platform=${{
      linux = "unix";
      darwin = "osx";
      windows = "win";
    }.${stdenv.hostPlatform.parsed.kernel.name} or stdenv.hostPlatform.parsed.kernel.name}"
    "ARCH=${{
      armv7l = "arm";
      armv6l = "arm";
      i686 = "x86";
    }.${stdenv.hostPlatform.parsed.cpu.name} or stdenv.hostPlatform.parsed.cpu.name}"
  ] ++ (args.makeFlags or [ ]);

  installPhase = ''
    runHook preInstall

    install -Dt ${coreDir} ${coreFilename}
    makeWrapper ${retroarch}/bin/retroarch $out/bin/${mainProgram} \
      --add-flags "-L ${coreDir}/${coreFilename} $@"

    runHook postInstall
  '';

  enableParallelBuilding = true;

  passthru = { inherit core libretroCore; };

  meta = with lib; {
    inherit mainProgram;
    inherit (retroarch.meta) platforms;
    homepage = "https://www.libretro.com/";
    maintainers = with maintainers; teams.libretro.members ++ [ hrdinka ];
  } // (args.meta or { });
} // extraArgs)
+41 −0
Original line number Diff line number Diff line
From 6145cb9ed935621f1974655fe1ab44cf2f0fbcce Mon Sep 17 00:00:00 2001
From: Thiago Kenji Okada <thiagokokada@gmail.com>
Date: Sat, 29 Oct 2022 12:27:55 +0100
Subject: [PATCH] Use fixed path for libretro_core_info

---
 configuration.c                  | 2 +-
 frontend/drivers/platform_unix.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configuration.c b/configuration.c
index af3fc8f43c..c6d56308b3 100644
--- a/configuration.c
+++ b/configuration.c
@@ -1468,7 +1468,7 @@ static struct config_path_setting *populate_settings_path(
    SETTING_PATH("core_options_path",
          settings->paths.path_core_options, false, NULL, true);
    SETTING_PATH("libretro_info_path",
-         settings->paths.path_libretro_info, false, NULL, true);
+         settings->paths.path_libretro_info, false, NULL, false);
    SETTING_PATH("content_database_path",
          settings->paths.path_content_database, false, NULL, true);
    SETTING_PATH("cheat_database_path",
diff --git a/frontend/drivers/platform_unix.c b/frontend/drivers/platform_unix.c
index fe5f7341c9..c2a91f8c99 100644
--- a/frontend/drivers/platform_unix.c
+++ b/frontend/drivers/platform_unix.c
@@ -1799,8 +1799,8 @@ static void frontend_unix_get_env(int *argc,
    fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], base_path,
          "core_info", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_INFO]));
 #else
-   fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], base_path,
-         "cores", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_INFO]));
+   fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_CORE_INFO], "@libretro_info_path@",
+         "share/libretro/info", sizeof(g_defaults.dirs[DEFAULT_DIR_CORE_INFO]));
 #endif
    fill_pathname_join(g_defaults.dirs[DEFAULT_DIR_AUTOCONFIG], base_path,
          "autoconfig", sizeof(g_defaults.dirs[DEFAULT_DIR_AUTOCONFIG]));
-- 
2.38.0
Loading