|
| 1 | +{ |
| 2 | + lib, |
| 3 | + stdenv, |
| 4 | + config, |
| 5 | + alsa-lib, |
| 6 | + apple-sdk_11, |
| 7 | + cmake, |
| 8 | + darwinMinVersionHook, |
| 9 | + dbus, |
| 10 | + fcitx5, |
| 11 | + fetchFromGitHub, |
| 12 | + ibus, |
| 13 | + installShellFiles, |
| 14 | + libGL, |
| 15 | + libayatana-appindicator, |
| 16 | + libdecor, |
| 17 | + libdrm, |
| 18 | + libjack2, |
| 19 | + libpulseaudio, |
| 20 | + libusb1, |
| 21 | + libxkbcommon, |
| 22 | + mesa, |
| 23 | + ninja, |
| 24 | + nix-update-script, |
| 25 | + nixosTests, |
| 26 | + pipewire, |
| 27 | + sndio, |
| 28 | + systemdLibs, |
| 29 | + testers, |
| 30 | + validatePkgConfig, |
| 31 | + wayland, |
| 32 | + wayland-scanner, |
| 33 | + xorg, |
| 34 | + zenity, |
| 35 | + alsaSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid, |
| 36 | + dbusSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid, |
| 37 | + drmSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid, |
| 38 | + ibusSupport ? stdenv.hostPlatform.isUnix && !stdenv.hostPlatform.isDarwin, |
| 39 | + jackSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid, |
| 40 | + libdecorSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid, |
| 41 | + openglSupport ? lib.meta.availableOn stdenv.hostPlatform mesa, |
| 42 | + pipewireSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid, |
| 43 | + pulseaudioSupport ? |
| 44 | + config.pulseaudio or stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid, |
| 45 | + libudevSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid, |
| 46 | + sndioSupport ? false, |
| 47 | + testSupport ? true, |
| 48 | + waylandSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid, |
| 49 | + x11Support ? !stdenv.hostPlatform.isAndroid && !stdenv.hostPlatform.isWindows, |
| 50 | +}: |
| 51 | + |
| 52 | +stdenv.mkDerivation (finalAttrs: { |
| 53 | + pname = "sdl3"; |
| 54 | + version = "3.1.8"; |
| 55 | + |
| 56 | + outputs = [ |
| 57 | + "lib" |
| 58 | + "dev" |
| 59 | + "out" |
| 60 | + ]; |
| 61 | + |
| 62 | + src = fetchFromGitHub { |
| 63 | + owner = "libsdl-org"; |
| 64 | + repo = "SDL"; |
| 65 | + tag = "preview-${finalAttrs.version}"; |
| 66 | + hash = "sha256-yfnW5y99EegifRavvZWmXPH2NFPKWoe90RmGDGk6PI4="; |
| 67 | + }; |
| 68 | + |
| 69 | + postPatch = |
| 70 | + # Tests timeout on Darwin |
| 71 | + lib.optionalString testSupport '' |
| 72 | + substituteInPlace test/CMakeLists.txt \ |
| 73 | + --replace-fail 'set(noninteractive_timeout 10)' 'set(noninteractive_timeout 30)' |
| 74 | + '' |
| 75 | + + lib.optionalString waylandSupport '' |
| 76 | + substituteInPlace src/video/wayland/SDL_waylandmessagebox.c \ |
| 77 | + --replace-fail '"zenity"' '"${lib.getExe zenity}"' |
| 78 | + ''; |
| 79 | + |
| 80 | + strictDeps = true; |
| 81 | + |
| 82 | + nativeBuildInputs = [ |
| 83 | + cmake |
| 84 | + ninja |
| 85 | + validatePkgConfig |
| 86 | + ] ++ lib.optional waylandSupport wayland-scanner; |
| 87 | + |
| 88 | + buildInputs = |
| 89 | + finalAttrs.dlopenBuildInputs |
| 90 | + ++ lib.optionals stdenv.hostPlatform.isDarwin [ |
| 91 | + # error: 'MTLPixelFormatASTC_4x4_LDR' is unavailable: not available on macOS |
| 92 | + (darwinMinVersionHook "11.0") |
| 93 | + |
| 94 | + apple-sdk_11 |
| 95 | + ] |
| 96 | + ++ lib.optionals ibusSupport [ |
| 97 | + fcitx5 |
| 98 | + ibus |
| 99 | + ] |
| 100 | + ++ lib.optional waylandSupport zenity; |
| 101 | + |
| 102 | + dlopenBuildInputs = |
| 103 | + lib.optionals stdenv.hostPlatform.isLinux [ |
| 104 | + libusb1 |
| 105 | + ] |
| 106 | + ++ lib.optional ( |
| 107 | + stdenv.hostPlatform.isUnix && !stdenv.hostPlatform.isDarwin |
| 108 | + ) libayatana-appindicator |
| 109 | + ++ lib.optional alsaSupport alsa-lib |
| 110 | + ++ lib.optional dbusSupport dbus |
| 111 | + ++ lib.optionals drmSupport [ |
| 112 | + libdrm |
| 113 | + mesa # libgbm |
| 114 | + ] |
| 115 | + ++ lib.optional jackSupport libjack2 |
| 116 | + ++ lib.optional libdecorSupport libdecor |
| 117 | + ++ lib.optional libudevSupport systemdLibs |
| 118 | + ++ lib.optional openglSupport libGL |
| 119 | + ++ lib.optional pipewireSupport pipewire |
| 120 | + ++ lib.optional pulseaudioSupport libpulseaudio |
| 121 | + ++ lib.optional sndioSupport sndio |
| 122 | + ++ lib.optionals waylandSupport [ |
| 123 | + libxkbcommon |
| 124 | + wayland |
| 125 | + ] |
| 126 | + ++ lib.optionals x11Support [ |
| 127 | + xorg.libX11 |
| 128 | + xorg.libXScrnSaver |
| 129 | + xorg.libXcursor |
| 130 | + xorg.libXext |
| 131 | + xorg.libXfixes |
| 132 | + xorg.libXi |
| 133 | + xorg.libXrandr |
| 134 | + ]; |
| 135 | + |
| 136 | + propagatedBuildInputs = finalAttrs.dlopenPropagatedBuildInputs; |
| 137 | + |
| 138 | + dlopenPropagatedBuildInputs = |
| 139 | + lib.optional (openglSupport && !stdenv.hostPlatform.isDarwin) libGL |
| 140 | + ++ lib.optional x11Support xorg.libX11; |
| 141 | + |
| 142 | + cmakeFlags = [ |
| 143 | + (lib.cmakeBool "SDL_ALSA" alsaSupport) |
| 144 | + (lib.cmakeBool "SDL_DBUS" dbusSupport) |
| 145 | + (lib.cmakeBool "SDL_IBUS" ibusSupport) |
| 146 | + (lib.cmakeBool "SDL_JACK" jackSupport) |
| 147 | + (lib.cmakeBool "SDL_KMSDRM" drmSupport) |
| 148 | + (lib.cmakeBool "SDL_LIBUDEV" libudevSupport) |
| 149 | + (lib.cmakeBool "SDL_OPENGL" openglSupport) |
| 150 | + (lib.cmakeBool "SDL_PIPEWIRE" pipewireSupport) |
| 151 | + (lib.cmakeBool "SDL_PULSEAUDIO" pulseaudioSupport) |
| 152 | + (lib.cmakeBool "SDL_SNDIO" sndioSupport) |
| 153 | + (lib.cmakeBool "SDL_TEST_LIBRARY" testSupport) |
| 154 | + (lib.cmakeBool "SDL_WAYLAND" waylandSupport) |
| 155 | + (lib.cmakeBool "SDL_WAYLAND_LIBDECOR" libdecorSupport) |
| 156 | + (lib.cmakeBool "SDL_X11" x11Support) |
| 157 | + |
| 158 | + (lib.cmakeBool "SDL_TESTS" finalAttrs.finalPackage.doCheck) |
| 159 | + ]; |
| 160 | + |
| 161 | + doCheck = testSupport && stdenv.buildPlatform.canExecute stdenv.hostPlatform; |
| 162 | + |
| 163 | + # See comment below. We actually *do* need these RPATH entries |
| 164 | + dontPatchELF = true; |
| 165 | + |
| 166 | + env = { |
| 167 | + # Many dependencies are not directly linked to, but dlopen()'d at runtime. Adding them to the RPATH |
| 168 | + # helps them be found |
| 169 | + NIX_LDFLAGS = |
| 170 | + lib.optionalString (stdenv.hostPlatform.extensions.sharedLibrary == ".so") |
| 171 | + "-rpath ${ |
| 172 | + lib.makeLibraryPath (finalAttrs.dlopenBuildInputs ++ finalAttrs.dlopenPropagatedBuildInputs) |
| 173 | + }"; |
| 174 | + }; |
| 175 | + |
| 176 | + passthru = { |
| 177 | + # Building this in its own derivation to make sure the rpath hack above propagate to users |
| 178 | + debug-text-example = stdenv.mkDerivation (finalAttrs': { |
| 179 | + pname = "sdl3-debug-text-example"; |
| 180 | + inherit (finalAttrs) version src; |
| 181 | + |
| 182 | + sourceRoot = "${finalAttrs'.src.name}/examples/renderer/18-debug-text"; |
| 183 | + |
| 184 | + nativeBuildInputs = [ |
| 185 | + installShellFiles |
| 186 | + ]; |
| 187 | + |
| 188 | + buildInputs = [ finalAttrs.finalPackage ]; |
| 189 | + |
| 190 | + postBuild = '' |
| 191 | + $CC -lSDL3 -o debug-text{,.c} |
| 192 | + ''; |
| 193 | + |
| 194 | + postInstall = '' |
| 195 | + installBin debug-text |
| 196 | + ''; |
| 197 | + |
| 198 | + meta = { |
| 199 | + inherit (finalAttrs.meta) maintainers platforms; |
| 200 | + mainProgram = "debug-text"; |
| 201 | + }; |
| 202 | + }); |
| 203 | + |
| 204 | + tests = |
| 205 | + { |
| 206 | + pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; }; |
| 207 | + inherit (finalAttrs.passthru) debug-text-example; |
| 208 | + } |
| 209 | + // lib.optionalAttrs stdenv.hostPlatform.isLinux { |
| 210 | + nixosTest = nixosTests.sdl3; |
| 211 | + }; |
| 212 | + |
| 213 | + updateScript = nix-update-script { |
| 214 | + extraArgs = [ |
| 215 | + "--version-regex" |
| 216 | + "'preview-(.*)'" |
| 217 | + ]; |
| 218 | + }; |
| 219 | + }; |
| 220 | + |
| 221 | + meta = { |
| 222 | + description = "Cross-platform development library (Preview version)"; |
| 223 | + homepage = "https://libsdl.org"; |
| 224 | + changelog = "https://github.com/libsdl-org/SDL/releases/tag/${finalAttrs.src.tag}"; |
| 225 | + license = lib.licenses.zlib; |
| 226 | + maintainers = with lib.maintainers; [ getchoo ]; |
| 227 | + platforms = lib.platforms.unix; |
| 228 | + pkgConfigModules = [ "sdl3" ]; |
| 229 | + }; |
| 230 | +}) |
0 commit comments