Skip to content

Commit

Permalink
[Backport release-24.11] glfw3: general improvements (#358521)
Browse files Browse the repository at this point in the history
  • Loading branch information
Scrumplex authored Nov 23, 2024
2 parents 17dc6e4 + a5eb95b commit 747409c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 62 deletions.
137 changes: 77 additions & 60 deletions pkgs/by-name/gl/glfw3/package.nix
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
{ stdenv
, lib
, fetchFromGitHub
, cmake
, pkg-config
, libGL
, vulkan-loader
, libXrandr
, libXinerama
, libXcursor
, libX11
, libXi
, libXext
, darwin
, 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";
Expand All @@ -35,59 +36,75 @@ 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 ];

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
];

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\"'"
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 \
--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
(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?
];
};

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;
};
}
7 changes: 5 additions & 2 deletions pkgs/by-name/gl/glfw3/x11.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 747409c

Please sign in to comment.