From 43537cf6b1817baf5e1192c3bb99b67edd1c5c36 Mon Sep 17 00:00:00 2001 From: Randy Eckenrode Date: Mon, 17 Nov 2025 20:25:22 -0500 Subject: [PATCH] mesa: build KosmicKrisp on Darwin --- pkgs/development/libraries/mesa/darwin.nix | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/pkgs/development/libraries/mesa/darwin.nix b/pkgs/development/libraries/mesa/darwin.nix index 83f3e16bf4ad..5e7743f117b6 100644 --- a/pkgs/development/libraries/mesa/darwin.nix +++ b/pkgs/development/libraries/mesa/darwin.nix @@ -3,8 +3,12 @@ lib, stdenv, fetchFromGitLab, + apple-sdk_26, bison, + darwinMinVersionHook, flex, + glslang, + libpng, libxml2, llvmPackages, meson, @@ -15,8 +19,30 @@ libxext, libx11, libxcb, + libxshmfence, + spirv-llvm-translator, + spirv-tools, zlib, + eglPlatforms ? [ + "macos" + "x11" + ], + galliumDrivers ? [ + "llvmpipe" # software renderer + "softpipe" # older software renderer + ], + vulkanDrivers ? [ + "kosmickrisp" # Vulkan on Metal + ], + vulkanLayers ? [ + "anti-lag" + "intel-nullhw" + "overlay" + "screenshot" + "vram-report-limit" + ], }: + let common = import ./common.nix { inherit lib fetchFromGitLab; }; in @@ -28,6 +54,11 @@ stdenv.mkDerivation { meta ; + patches = [ + # Required to build KosmicKrisp + ./opencl.patch + ]; + outputs = [ "out" "dev" @@ -36,6 +67,9 @@ stdenv.mkDerivation { nativeBuildInputs = [ bison flex + # Use bin output from glslang to not propagate the dev output at + # the build time with the host glslang. + (lib.getBin glslang) meson ninja pkg-config @@ -46,12 +80,21 @@ stdenv.mkDerivation { ]; buildInputs = [ + apple-sdk_26 # KosmicKrisp requires Metal 4 to build, but … + (darwinMinVersionHook "15.0") # … it supports back to Metal 3.2, which requires macOS 15. + libpng libxml2 # should be propagated from libllvm + llvmPackages.libclang + llvmPackages.libclc llvmPackages.libllvm + python3Packages.python # for shebang + spirv-llvm-translator + spirv-tools libx11 libxext libxfixes libxcb + libxshmfence zlib ]; @@ -60,10 +103,30 @@ stdenv.mkDerivation { mesonFlags = [ "--sysconfdir=/etc" "--datadir=${placeholder "out"}/share" + + # What to build + (lib.mesonOption "platforms" (lib.concatStringsSep "," eglPlatforms)) + (lib.mesonOption "gallium-drivers" (lib.concatStringsSep "," galliumDrivers)) + (lib.mesonOption "vulkan-drivers" (lib.concatStringsSep "," vulkanDrivers)) + (lib.mesonOption "vulkan-layers" (lib.concatStringsSep "," vulkanLayers)) + + # Disable glvnd on Darwin (lib.mesonEnable "glvnd" false) + (lib.mesonEnable "gbm" false) + (lib.mesonBool "libgbm-external" false) + + # Needed for KosmicKrisp + (lib.mesonOption "clang-libdir" "${lib.getLib llvmPackages.libclang}/lib") (lib.mesonEnable "llvm" true) + (lib.mesonEnable "shared-llvm" true) + (lib.mesonEnable "spirv-tools" true) + + # Needed for Apple GLX support + (lib.mesonOption "glx" "dri") ]; + mesonBuildType = "release"; + passthru = { # needed to pass evaluation of bad platforms driverLink = throw "driverLink not supported on darwin";