From 67cc93c902624278fd027e0a311f0b80b477359d Mon Sep 17 00:00:00 2001 From: Marcin Serwin Date: Sun, 2 Mar 2025 23:56:44 +0100 Subject: [PATCH 1/3] sdl2-compat: add setup hook This adds a setup hook analogous to the one used by SDL2 package that picks up satelitte libraries during build time. This makes it possible to replace SDL2 with sdl2-compat in packages using satelitte libraries without further changes to build flags. --- .../by-name/sd/sdl2-compat/find-headers.patch | 31 +++++++++++++++++++ pkgs/by-name/sd/sdl2-compat/package.nix | 3 ++ pkgs/by-name/sd/sdl2-compat/setup-hook.sh | 7 +++++ 3 files changed, 41 insertions(+) create mode 100644 pkgs/by-name/sd/sdl2-compat/find-headers.patch create mode 100644 pkgs/by-name/sd/sdl2-compat/setup-hook.sh diff --git a/pkgs/by-name/sd/sdl2-compat/find-headers.patch b/pkgs/by-name/sd/sdl2-compat/find-headers.patch new file mode 100644 index 000000000000..4b6687cc4078 --- /dev/null +++ b/pkgs/by-name/sd/sdl2-compat/find-headers.patch @@ -0,0 +1,31 @@ +diff --git a/SDL2Config.cmake.in b/SDL2Config.cmake.in +index 80c1b99..54f50e6 100644 +--- a/SDL2Config.cmake.in ++++ b/SDL2Config.cmake.in +@@ -45,7 +45,8 @@ endif() + set(SDL2_PREFIX "@PACKAGE_CMAKE_INSTALL_PREFIX@") + set(SDL2_EXEC_PREFIX "@PACKAGE_CMAKE_INSTALL_PREFIX@") + set(SDL2_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@/SDL2") +-set(SDL2_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@;@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@/SDL2") ++set(SDL2_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@;@PACKAGE_CMAKE_INSTALL_FULL_INCLUDEDIR@/SDL2" $ENV{SDL2_PATH}) ++separate_arguments(SDL2_INCLUDE_DIRS) + set(SDL2_BINDIR "@PACKAGE_CMAKE_INSTALL_FULL_BINDIR@") + set(SDL2_LIBDIR "@PACKAGE_CMAKE_INSTALL_FULL_LIBDIR@") + set(SDL2_LIBRARIES SDL2::SDL2) +diff --git a/sdl2-config.in b/sdl2-config.in +index d21b1b2..bb0d624 100644 +--- a/sdl2-config.in ++++ b/sdl2-config.in +@@ -50,7 +50,11 @@ while test $# -gt 0; do + echo @PROJECT_VERSION@ + ;; + --cflags) +- echo -I${includedir}/SDL2 @SDL_CFLAGS@ ++ SDL_CFLAGS="" ++ for i in @includedir@/SDL2 $SDL2_PATH; do ++ SDL_CFLAGS="$SDL_CFLAGS -I$i" ++ done ++ echo $SDL_CFLAGS @SDL_CFLAGS@ + ;; + @ENABLE_SHARED_TRUE@ --libs) + @ENABLE_SHARED_TRUE@ echo -L${libdir} @SDL_RLD_FLAGS@ @SDL_LIBS@ diff --git a/pkgs/by-name/sd/sdl2-compat/package.nix b/pkgs/by-name/sd/sdl2-compat/package.nix index 6d4507dc41ae..3f74992d4195 100644 --- a/pkgs/by-name/sd/sdl2-compat/package.nix +++ b/pkgs/by-name/sd/sdl2-compat/package.nix @@ -60,6 +60,9 @@ stdenv.mkDerivation (finalAttrs: { patchelf --add-rpath ${lib.makeLibraryPath [ sdl3 ]} $out/lib/libSDL2.so ''; + patches = [ ./find-headers.patch ]; + setupHook = ./setup-hook.sh; + passthru = { tests = let diff --git a/pkgs/by-name/sd/sdl2-compat/setup-hook.sh b/pkgs/by-name/sd/sdl2-compat/setup-hook.sh new file mode 100644 index 000000000000..0119926491af --- /dev/null +++ b/pkgs/by-name/sd/sdl2-compat/setup-hook.sh @@ -0,0 +1,7 @@ +addSDL2Path () { + if [ -e "$1/include/SDL2" ]; then + export SDL2_PATH="${SDL2_PATH-}${SDL2_PATH:+ }$1/include/SDL2" + fi +} + +addEnvHooks "$hostOffset" addSDL2Path From 8ce347392b447282291cbb3c377d856b8707ffa0 Mon Sep 17 00:00:00 2001 From: Marcin Serwin Date: Sun, 2 Mar 2025 23:56:44 +0100 Subject: [PATCH 2/3] sdl2-compat: specify as compatible with all platforms The SDL library has backends for many platforms, not just unix ones, however, it's currently restricted by its dependencies. --- pkgs/by-name/sd/sdl2-compat/package.nix | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/pkgs/by-name/sd/sdl2-compat/package.nix b/pkgs/by-name/sd/sdl2-compat/package.nix index 3f74992d4195..29a9fa63028f 100644 --- a/pkgs/by-name/sd/sdl2-compat/package.nix +++ b/pkgs/by-name/sd/sdl2-compat/package.nix @@ -44,22 +44,16 @@ stdenv.mkDerivation (finalAttrs: { outputBin = "dev"; + # SDL3 is dlopened at runtime, leave it in runpath + dontPatchELF = true; + cmakeFlags = [ (lib.cmakeBool "SDL2COMPAT_TESTS" finalAttrs.finalPackage.doCheck) + (lib.cmakeFeature "CMAKE_INSTALL_RPATH" (lib.makeLibraryPath [ sdl3 ])) ]; doCheck = testSupport && stdenv.buildPlatform.canExecute stdenv.hostPlatform; - postFixup = - if stdenv.hostPlatform.isDarwin then - '' - install_name_tool -add_rpath ${lib.makeLibraryPath [ sdl3 ]} $out/lib/libSDL2.dylib - '' - else - '' - patchelf --add-rpath ${lib.makeLibraryPath [ sdl3 ]} $out/lib/libSDL2.so - ''; - patches = [ ./find-headers.patch ]; setupHook = ./setup-hook.sh; @@ -95,7 +89,7 @@ stdenv.mkDerivation (finalAttrs: { changelog = "https://github.com/libsdl-org/sdl2-compat/releases/tag/${finalAttrs.src.tag}"; license = lib.licenses.zlib; maintainers = with lib.maintainers; [ nadiaholmquist ]; - platforms = lib.platforms.unix; + platforms = lib.platforms.all; pkgConfigModules = [ "sdl2_compat" ]; }; }) From c6e964d39268f26d6731ca1ada32fad67691e3ec Mon Sep 17 00:00:00 2001 From: Marcin Serwin Date: Wed, 12 Mar 2025 21:48:40 +0100 Subject: [PATCH 3/3] sdl2-compat: skip slow tests The slow tests rely on timers executing within a specified time which is not necessarily true if system is under a heavy load [1]. These tests are also disabled in the official CI pipeline [2]. [1]: https://github.com/NixOS/nixpkgs/pull/386759#issuecomment-2707779101 [2]: https://github.com/libsdl-org/sdl2-compat/blob/9544651fb39deefb2dd1aed9113af3b60898a1bb/.github/workflows/main.yml#L116 --- pkgs/by-name/sd/sdl2-compat/package.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/by-name/sd/sdl2-compat/package.nix b/pkgs/by-name/sd/sdl2-compat/package.nix index 29a9fa63028f..392641b68f36 100644 --- a/pkgs/by-name/sd/sdl2-compat/package.nix +++ b/pkgs/by-name/sd/sdl2-compat/package.nix @@ -52,6 +52,9 @@ stdenv.mkDerivation (finalAttrs: { (lib.cmakeFeature "CMAKE_INSTALL_RPATH" (lib.makeLibraryPath [ sdl3 ])) ]; + # skip timing-based tests as those are flaky + env.SDL_TESTS_QUICK = 1; + doCheck = testSupport && stdenv.buildPlatform.canExecute stdenv.hostPlatform; patches = [ ./find-headers.patch ];