From 755c400a929002ece6219e76e7130b9f66ce9ba9 Mon Sep 17 00:00:00 2001 From: Emily Date: Sat, 22 Jun 2024 08:33:02 +0100 Subject: [PATCH] {libGL,libGLU}: use the OpenGL framework on Darwin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reduces the reverse closure of Mesa on Darwin considerably. As a result, we can also drop the Mesa stubs package entirely, as its output on Linux is functionally identical to libglvnd. It should no longer be necessary for packages to switch between libGL and darwin.apple_sdk.frameworks.OpenGL depending on the platform. A cross‐platform libGLX alias is added for packages that specifically need it (mostly old X11 applications that barely know what a macOS is). Co-authored-by: K900 --- pkgs/top-level/all-packages.nix | 43 ++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 40bc3cfd006c..c10805a5b3f6 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -23210,16 +23210,41 @@ with pkgs; ## libGL/libGLU/Mesa stuff - # Default libGL implementation, should provide headers and - # libGL.so/libEGL.so/... to link agains them. Android NDK provides - # an OpenGL implementation, we can just use that. - libGL = if stdenv.hostPlatform.useAndroidPrebuilt then stdenv - else callPackage ../development/libraries/mesa/stubs.nix { - inherit (darwin.apple_sdk.frameworks) OpenGL; - }; + # Default libGL implementation. + # + # Android NDK provides an OpenGL implementation, we can just use that. + # + # On macOS, we use the OpenGL framework. Packages that still need GLX + # specifically can pull in libGLX instead. If you have a package that + # should work without X11 but it can’t find the library, it may help + # to add the path to `NIX_CFLAGS_COMPILE`: + # + # -L${libGL}/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries + # + # If you still can’t get it working, please don’t hesitate to ping + # @NixOS/darwin-maintainers to ask an expert to take a look. + libGL = + if stdenv.hostPlatform.useAndroidPrebuilt then + stdenv + else if stdenv.hostPlatform.isDarwin then + darwin.apple_sdk.frameworks.OpenGL + else + libglvnd; - # Default libGLU - libGLU = mesa_glu; + # On macOS, we use the OpenGL framework. Packages that use libGLX on + # macOS may need to depend on mesa_glu directly if this doesn’t work. + libGLU = + if stdenv.hostPlatform.isDarwin then + darwin.apple_sdk.frameworks.OpenGL + else + mesa_glu; + + # libglvnd does not work (yet?) on macOS. + libGLX = + if stdenv.hostPlatform.isDarwin then + mesa + else + libglvnd; mesa = if stdenv.isDarwin then darwin.apple_sdk_11_0.callPackage ../development/libraries/mesa/darwin.nix {