From a913a8d655dcf1ecccd8ce7853478ee2fe332c5e Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 21 Nov 2024 22:49:23 +0100 Subject: [PATCH 1/7] glfw3: fix library name overrides CMAKE_C_FLAGS did not work previously, as it was defined multiple times. Instead of fixing it, it is much more readable to use NIX_CFLAGS_COMPILE instead of having to escape special characters across Nix, Bash and CMake Signed-off-by: Sefa Eyeoglu --- pkgs/by-name/gl/glfw3/package.nix | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/pkgs/by-name/gl/glfw3/package.nix b/pkgs/by-name/gl/glfw3/package.nix index 08a7aef50665..b098896a9859 100644 --- a/pkgs/by-name/gl/glfw3/package.nix +++ b/pkgs/by-name/gl/glfw3/package.nix @@ -61,14 +61,6 @@ stdenv.mkDerivation { libXext ]; - cmakeFlags = [ - "-DBUILD_SHARED_LIBS=ON" - ] ++ lib.optionals (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows) [ - "-DCMAKE_C_FLAGS=-D_GLFW_GLX_LIBRARY='\"${lib.getLib libGL}/lib/libGL.so.1\"'" - "-DCMAKE_C_FLAGS=-D_GLFW_EGL_LIBRARY='\"${lib.getLib libGL}/lib/libEGL.so.1\"'" - "-DCMAKE_C_FLAGS=-D_GLFW_VULKAN_LIBRARY='\"${lib.getLib vulkan-loader}/lib/libvulkan.so.1\"'" - ]; - postPatch = lib.optionalString stdenv.hostPlatform.isLinux '' substituteInPlace src/wl_init.c \ --replace-fail "libxkbcommon.so.0" "${lib.getLib libxkbcommon}/lib/libxkbcommon.so.0" \ @@ -83,6 +75,23 @@ stdenv.mkDerivation { patchelf ''${!outputLib}/lib/libglfw.so --add-rpath ${lib.getLib wayland}/lib ''; + cmakeFlags = [ + # Static linking isn't supported + (lib.cmakeBool "BUILD_SHARED_LIBS" true) + ]; + + env = lib.optionalAttrs (!stdenv.hostPlatform.isDarwin && !stdenv.hostPlatform.isWindows) { + NIX_CFLAGS_COMPILE = toString [ + "-D_GLFW_GLX_LIBRARY=\"${lib.getLib libGL}/lib/libGLX.so.0\"" + "-D_GLFW_EGL_LIBRARY=\"${lib.getLib libGL}/lib/libEGL.so.1\"" + "-D_GLFW_OPENGL_LIBRARY=\"${lib.getLib libGL}/lib/libGL.so.1\"" + "-D_GLFW_GLESV1_LIBRARY=\"${lib.getLib libGL}/lib/libGLESv1_CM.so.1\"" + "-D_GLFW_GLESV2_LIBRARY=\"${lib.getLib libGL}/lib/libGLESv2.so.2\"" + "-D_GLFW_VULKAN_LIBRARY=\"${lib.getLib vulkan-loader}/lib/libvulkan.so.1\"" + # This currently omits _GLFW_OSMESA_LIBRARY. Is it even used? + ]; + }; + meta = with lib; { description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time"; homepage = "https://www.glfw.org/"; From fbf94f5a7d3d77debd3eab96b601df077953ae44 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 21 Nov 2024 22:50:06 +0100 Subject: [PATCH 2/7] glfw3: harden wayland substitutions Including quotes around the library names should make these substitutions stricter. Signed-off-by: Sefa Eyeoglu --- pkgs/by-name/gl/glfw3/package.nix | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pkgs/by-name/gl/glfw3/package.nix b/pkgs/by-name/gl/glfw3/package.nix index b098896a9859..d597d79aaa61 100644 --- a/pkgs/by-name/gl/glfw3/package.nix +++ b/pkgs/by-name/gl/glfw3/package.nix @@ -63,17 +63,13 @@ stdenv.mkDerivation { postPatch = lib.optionalString stdenv.hostPlatform.isLinux '' substituteInPlace src/wl_init.c \ - --replace-fail "libxkbcommon.so.0" "${lib.getLib libxkbcommon}/lib/libxkbcommon.so.0" \ - --replace-fail "libdecor-0.so.0" "${lib.getLib libdecor}/lib/libdecor-0.so.0" \ - --replace-fail "libwayland-client.so.0" "${lib.getLib wayland}/lib/libwayland-client.so.0" \ - --replace-fail "libwayland-cursor.so.0" "${lib.getLib wayland}/lib/libwayland-cursor.so.0" \ - --replace-fail "libwayland-egl.so.1" "${lib.getLib wayland}/lib/libwayland-egl.so.1" + --replace-fail '"libdecor-0.so.0"' '"${lib.getLib libdecor}/lib/libdecor-0.so.0"' \ + --replace-fail '"libwayland-client.so.0"' '"${lib.getLib wayland}/lib/libwayland-client.so.0"' \ + --replace-fail '"libwayland-cursor.so.0"' '"${lib.getLib wayland}/lib/libwayland-cursor.so.0"' \ + --replace-fail '"libwayland-egl.so.1"' '"${lib.getLib wayland}/lib/libwayland-egl.so.1"' \ + --replace-fail '"libxkbcommon.so.0"' '"${lib.getLib libxkbcommon}/lib/libxkbcommon.so.0"' ''; - # glfw may dlopen libwayland-client.so: - postFixup = lib.optionalString stdenv.hostPlatform.isLinux '' - patchelf ''${!outputLib}/lib/libglfw.so --add-rpath ${lib.getLib wayland}/lib - ''; cmakeFlags = [ # Static linking isn't supported From 4347d8dee515d4e37588cba0a6ce1afdae074c3a Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 21 Nov 2024 22:50:30 +0100 Subject: [PATCH 3/7] glfw3: add missing X11 substitutions libX11-xcb.so.1 and libXxf86vm.so.1 are dlopen-ed at runtime, but are not linked by the linker. Let's hardcode their library paths into the code. Signed-off-by: Sefa Eyeoglu --- pkgs/by-name/gl/glfw3/package.nix | 2 ++ pkgs/by-name/gl/glfw3/x11.patch | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkgs/by-name/gl/glfw3/package.nix b/pkgs/by-name/gl/glfw3/package.nix index d597d79aaa61..da53f5dc447e 100644 --- a/pkgs/by-name/gl/glfw3/package.nix +++ b/pkgs/by-name/gl/glfw3/package.nix @@ -11,6 +11,7 @@ , libX11 , libXi , libXext +, libXxf86vm , darwin , fixDarwinDylibNames , wayland @@ -59,6 +60,7 @@ stdenv.mkDerivation { libXcursor libXi libXext + libXxf86vm ]; postPatch = lib.optionalString stdenv.hostPlatform.isLinux '' diff --git a/pkgs/by-name/gl/glfw3/x11.patch b/pkgs/by-name/gl/glfw3/x11.patch index 5cadf53bfe70..2471814f219f 100644 --- a/pkgs/by-name/gl/glfw3/x11.patch +++ b/pkgs/by-name/gl/glfw3/x11.patch @@ -2,17 +2,20 @@ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a0be580e..ba143851 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt -@@ -219,6 +219,13 @@ if (GLFW_BUILD_X11) +@@ -219,6 +219,16 @@ if (GLFW_BUILD_X11) if (NOT X11_Xshape_INCLUDE_PATH) message(FATAL_ERROR "X Shape headers not found; install libxext development package") endif() + + target_link_libraries(glfw PRIVATE ${X11_Xrandr_LIB} + ${X11_Xinerama_LIB} ++ ${X11_X11_xcb_LIB} ++ ${X11_Xrender_LIB} + ${X11_Xkb_LIB} + ${X11_Xcursor_LIB} + ${X11_Xi_LIB} -+ ${X11_Xshape_LIB}) ++ ${X11_Xxf86vm_LIB} ++ ${X11_Xext_LIB}) endif() if (UNIX AND NOT APPLE) From bc33d600bd94d7547692a247a37082b0ce4710dc Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 21 Nov 2024 23:09:26 +0100 Subject: [PATCH 4/7] glfw3: remove darwin build inputs The new apple-sdk pattern doesn't require this anymore. Signed-off-by: Sefa Eyeoglu --- pkgs/by-name/gl/glfw3/package.nix | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/pkgs/by-name/gl/glfw3/package.nix b/pkgs/by-name/gl/glfw3/package.nix index da53f5dc447e..82f88e0328e6 100644 --- a/pkgs/by-name/gl/glfw3/package.nix +++ b/pkgs/by-name/gl/glfw3/package.nix @@ -12,7 +12,6 @@ , libXi , libXext , libXxf86vm -, darwin , fixDarwinDylibNames , wayland , wayland-scanner @@ -48,20 +47,18 @@ stdenv.mkDerivation { ++ lib.optionals stdenv.hostPlatform.isDarwin [ fixDarwinDylibNames ] ++ lib.optionals stdenv.hostPlatform.isLinux [ wayland-scanner ]; - buildInputs = - lib.optionals stdenv.hostPlatform.isDarwin (with darwin.apple_sdk.frameworks; [ Carbon Cocoa Kernel ]) - ++ lib.optionals stdenv.hostPlatform.isLinux [ - wayland - wayland-protocols - libxkbcommon - libX11 - libXrandr - libXinerama - libXcursor - libXi - libXext - libXxf86vm - ]; + buildInputs = lib.optionals stdenv.hostPlatform.isLinux [ + wayland + wayland-protocols + libxkbcommon + libX11 + libXrandr + libXinerama + libXcursor + libXi + libXext + libXxf86vm + ]; postPatch = lib.optionalString stdenv.hostPlatform.isLinux '' substituteInPlace src/wl_init.c \ From 1c6ac264654e6d821097e54ad005877a27cc3097 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 21 Nov 2024 22:51:35 +0100 Subject: [PATCH 5/7] glfw3: enable strictDeps and __structuredAttrs Signed-off-by: Sefa Eyeoglu --- pkgs/by-name/gl/glfw3/package.nix | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pkgs/by-name/gl/glfw3/package.nix b/pkgs/by-name/gl/glfw3/package.nix index 82f88e0328e6..df7bcdbdaaa5 100644 --- a/pkgs/by-name/gl/glfw3/package.nix +++ b/pkgs/by-name/gl/glfw3/package.nix @@ -87,6 +87,9 @@ stdenv.mkDerivation { ]; }; + strictDeps = true; + __structuredAttrs = true; + meta = with lib; { description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time"; homepage = "https://www.glfw.org/"; From e584de581643ec8d3548670bf8ceb00f714a0600 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 21 Nov 2024 22:55:46 +0100 Subject: [PATCH 6/7] glfw3: remove with lib Signed-off-by: Sefa Eyeoglu --- pkgs/by-name/gl/glfw3/package.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkgs/by-name/gl/glfw3/package.nix b/pkgs/by-name/gl/glfw3/package.nix index df7bcdbdaaa5..0a815a4a5956 100644 --- a/pkgs/by-name/gl/glfw3/package.nix +++ b/pkgs/by-name/gl/glfw3/package.nix @@ -90,11 +90,11 @@ stdenv.mkDerivation { strictDeps = true; __structuredAttrs = true; - meta = with lib; { + meta = { description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time"; homepage = "https://www.glfw.org/"; - license = licenses.zlib; - maintainers = with maintainers; [ marcweber Scrumplex twey ]; - platforms = platforms.unix ++ platforms.windows; + license = lib.licenses.zlib; + maintainers = with lib.maintainers; [ marcweber Scrumplex twey ]; + platforms = lib.platforms.unix ++ lib.platforms.windows; }; } From 00b5f4e199b78cf6406e9796b10a0bbd555c8457 Mon Sep 17 00:00:00 2001 From: Sefa Eyeoglu Date: Thu, 21 Nov 2024 23:09:53 +0100 Subject: [PATCH 7/7] glfw3: nixfmt Signed-off-by: Sefa Eyeoglu --- pkgs/by-name/gl/glfw3/package.nix | 68 ++++++++++++++++++------------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/pkgs/by-name/gl/glfw3/package.nix b/pkgs/by-name/gl/glfw3/package.nix index 0a815a4a5956..fa740ddbaccf 100644 --- a/pkgs/by-name/gl/glfw3/package.nix +++ b/pkgs/by-name/gl/glfw3/package.nix @@ -1,24 +1,25 @@ -{ stdenv -, lib -, fetchFromGitHub -, cmake -, pkg-config -, libGL -, vulkan-loader -, libXrandr -, libXinerama -, libXcursor -, libX11 -, libXi -, libXext -, libXxf86vm -, fixDarwinDylibNames -, wayland -, wayland-scanner -, wayland-protocols -, libxkbcommon -, libdecor -, withMinecraftPatch ? false +{ + stdenv, + lib, + fetchFromGitHub, + cmake, + pkg-config, + libGL, + vulkan-loader, + libXrandr, + libXinerama, + libXcursor, + libX11, + libXi, + libXext, + libXxf86vm, + fixDarwinDylibNames, + wayland, + wayland-scanner, + wayland-protocols, + libxkbcommon, + libdecor, + withMinecraftPatch ? false, }: let version = "3.4"; @@ -35,15 +36,21 @@ stdenv.mkDerivation { }; # Fix linkage issues on X11 (https://github.com/NixOS/nixpkgs/issues/142583) - patches = [ - ./x11.patch - ] ++ lib.optionals withMinecraftPatch [ - ./0009-Defer-setting-cursor-position-until-the-cursor-is-lo.patch - ]; + patches = + [ + ./x11.patch + ] + ++ lib.optionals withMinecraftPatch [ + ./0009-Defer-setting-cursor-position-until-the-cursor-is-lo.patch + ]; propagatedBuildInputs = lib.optionals (!stdenv.hostPlatform.isWindows) [ libGL ]; - nativeBuildInputs = [ cmake pkg-config ] + nativeBuildInputs = + [ + cmake + pkg-config + ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ fixDarwinDylibNames ] ++ lib.optionals stdenv.hostPlatform.isLinux [ wayland-scanner ]; @@ -69,7 +76,6 @@ stdenv.mkDerivation { --replace-fail '"libxkbcommon.so.0"' '"${lib.getLib libxkbcommon}/lib/libxkbcommon.so.0"' ''; - cmakeFlags = [ # Static linking isn't supported (lib.cmakeBool "BUILD_SHARED_LIBS" true) @@ -94,7 +100,11 @@ stdenv.mkDerivation { description = "Multi-platform library for creating OpenGL contexts and managing input, including keyboard, mouse, joystick and time"; homepage = "https://www.glfw.org/"; license = lib.licenses.zlib; - maintainers = with lib.maintainers; [ marcweber Scrumplex twey ]; + maintainers = with lib.maintainers; [ + marcweber + Scrumplex + twey + ]; platforms = lib.platforms.unix ++ lib.platforms.windows; }; }