summaryrefslogtreecommitdiffstats
path: root/pkgs/development/libraries/mesa/darwin.nix
blob: c0376c69cb2b3289306a4e478fd23cc2a42c61e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# The Darwin build of Mesa is different enough that we just give it an entire separate expression.
{
  lib,
  stdenv,
  fetchFromGitLab,
  apple-sdk_26,
  bison,
  darwinMinVersionHook,
  flex,
  glslang,
  libpng,
  libxml2,
  llvmPackages,
  meson,
  ninja,
  pkg-config,
  python3Packages,
  libxfixes,
  libxext,
  libx11,
  libxcb,
  libxshmfence,
  mesa-libclc,
  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
stdenv.mkDerivation {
  inherit (common)
    pname
    version
    src
    meta
    ;

  patches = [
    # Required to build KosmicKrisp
    ./opencl.patch
  ];

  outputs = [
    "out"
    "dev"
  ];

  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
    python3Packages.packaging
    python3Packages.python
    python3Packages.mako
    python3Packages.pyyaml
  ];

  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.libllvm
    mesa-libclc
    python3Packages.python # for shebang
    spirv-llvm-translator
    spirv-tools
    libx11
    libxext
    libxfixes
    libxcb
    libxshmfence
    zlib
  ];

  mesonAutoFeatures = "disabled";

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

  postFixup = ''
    install_name_tool -add_rpath "$out/lib" "$out/lib/libGL.dylib"
  '';

  passthru = {
    # needed to pass evaluation of bad platforms
    driverLink = throw "driverLink not supported on darwin";
    # Don't need this on Darwin.
    llvmpipeHook = null;
  };

}