Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pkgs/by-name/sd/sdl2-compat/find-headers.patch
Original file line number Diff line number Diff line change
@@ -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@
20 changes: 10 additions & 10 deletions pkgs/by-name/sd/sdl2-compat/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ 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 ]))
];

# skip timing-based tests as those are flaky
env.SDL_TESTS_QUICK = 1;

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;

passthru = {
tests =
Expand Down Expand Up @@ -92,7 +92,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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you test this, especially on darwin?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't use nix on darwin so I don't have any way to test this currently. I've tested the change on linux.

Note that this line doesn't add darwin to platforms - darwin is unix so it was already there - effectively it only adds windows which I wanted to test but I was blocked by #388297, I will try again shortly now that it's fixed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, good point. If it was previously unix it should be fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I managed to cross compile the package itself for windows after fixing the rpath setting, but cross compiling anything dependent on it is problematic, since I realized that the setup hook assumes that host == target. I've tried building a simple game by supplying necessary flags manually but it failed to run in wine with Failed to initialize registry display settings for L"\\\\.\\DISPLAY1". I'm still leaving the platforms set to all since there is nothing unixy required by the library, and the issues are likely caused by cross compiling.

pkgConfigModules = [ "sdl2_compat" ];
};
})
7 changes: 7 additions & 0 deletions pkgs/by-name/sd/sdl2-compat/setup-hook.sh
Original file line number Diff line number Diff line change
@@ -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