Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sdl3: init at 3.1.8 #326699

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ in {
scion-freestanding-deployment = handleTest ./scion/freestanding-deployment {};
scrutiny = handleTest ./scrutiny.nix {};
sddm = handleTest ./sddm.nix {};
sdl3 = handleTest ./sdl3.nix { };
seafile = handleTest ./seafile.nix {};
searx = runTest ./searx.nix;
seatd = handleTest ./seatd.nix {};
Expand Down
28 changes: 28 additions & 0 deletions nixos/tests/sdl3.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import ./make-test-python.nix (
{ pkgs, ... }:
{
name = "sdl3";
meta.maintainers = pkgs.sdl3.meta.maintainers;

nodes.machine =
{ pkgs, ... }:
{
imports = [ ./common/x11.nix ];

environment.systemPackages = [ pkgs.sdl3.passthru.debug-text-example ];
};

enableOCR = true;

testScript = ''
machine.wait_for_x()

machine.execute("debug-text >&2 &")

machine.wait_for_window("examples/renderer/debug-text")
machine.wait_for_text("Hello world")

machine.screenshot("screen")
'';
}
)
230 changes: 230 additions & 0 deletions pkgs/by-name/sd/sdl3/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
{
lib,
stdenv,
config,
alsa-lib,
apple-sdk_11,
cmake,
darwinMinVersionHook,
dbus,
fcitx5,
fetchFromGitHub,
ibus,
installShellFiles,
libGL,
libayatana-appindicator,
libdecor,
libdrm,
libjack2,
libpulseaudio,
libusb1,
libxkbcommon,
mesa,
ninja,
nix-update-script,
nixosTests,
pipewire,
sndio,
systemdLibs,
testers,
validatePkgConfig,
wayland,
wayland-scanner,
xorg,
zenity,
alsaSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid,
dbusSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid,
drmSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid,
ibusSupport ? stdenv.hostPlatform.isUnix && !stdenv.hostPlatform.isDarwin,
jackSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually cross-compile to this entire zoo of targets?

Copy link
Contributor

@OPNA2608 OPNA2608 Dec 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't cross-compile in general, though the issues don't seem to be in this derivation at least.

Android:

error: Package ‘glu-9.0.3’ in /home/puna/.cache/nixpkgs-review/pr-326699/nixpkgs/pkgs/by-name/me/mesa_glu/package.nix:56 is marked as broken, refusing to evaluate.

libGLU -> gst-plugins-bad -> gtk4 -> ibus -> sdl3


Regular aarch64-linux:

CMake Error at CMakeLists.txt:4 (find_package):
  Could not find a package configuration file provided by "ECM" (requested
  version 0.0.11) with any of the following names:

xcb-imdkit -> fcitx5 -> sdl3

#364712 will fix extra-cmake-modules being in the wrong *[bB]uildInputs. Then it's "just" stuck on borked Qt cross-compilation at least…

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually cross-compile to this entire zoo of targets?

In theory it could -- but as described above, not currently

This was just adapted from the current SDL2 packaging, though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then please remove it. It's a huge amount of complexity and basically none of this actually needs to be conditional.

Copy link
Member Author

@getchoo getchoo Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a huge amount of complexity

Is it? I don't think specifying "linux but not android" as opposed to just "linux" is much more complicated -- likewise "unix but not darwin". If this was an actually complicated expression for the sake of cross compilation I'd understand, but these are just a logical AND. I'm perfectly fine with maintaining this

It's a huge amount of complexity and basically none of this actually needs to be conditional.

This is completely incorrect. Even if we were to only support tier 1 targets, dbus, drm, ibus, and jack are all exclusive to Linux and would be conditional. Now if you mean they don't need to be arguments/override options....I guess? But I don't see much gain from inlining these into the expression when we can instead give people options on what they want to build SDL with

Further, keeping these options actually helps a lot in solving build/eval (for native or cross) issues if our defaults (currently) fail. Using the issues @OPNA2608 came across above as an example:

Android:

error: Package ‘glu-9.0.3’ in /home/puna/.cache/nixpkgs-review/pr-326699/nixpkgs/pkgs/by-name/me/mesa_glu/package.nix:56 is marked as broken, refusing to evaluate.

libGLU -> gst-plugins-bad -> gtk4 -> ibus -> sdl3

This can be fixed with just .override { ibusSupport = false; }

> pkgsCross.aarch64-android.sdl3.override { ibusSupport = false; }
«derivation /nix/store/5cgngvsw5i9944d7a83sq26ff4cl1a18-sdl3-aarch64-unknown-linux-android-3.1.6.drv»

(note: I didn't actually build this, so it or other packages could still fail, but that's not really my point here)

Regular aarch64-linux:

CMake Error at CMakeLists.txt:4 (find_package):
  Could not find a package configuration file provided by "ECM" (requested
  version 0.0.11) with any of the following names:

xcb-imdkit -> fcitx5 -> sdl3

This can be fixed by disabling ibusSupport as well. Even got it building:

> nix-build --expr 'with import ./. { config = { }; overlays = [ ]; }; pkgsCross.aarch64-multiplatform.sdl3.override { ibusSupport = false; }'
/nix/store/b6jnsb7ijs88n54ly56lf34xmdifn0vs-sdl3-aarch64-unknown-linux-gnu-3.1.6-lib

These options also help in creating smaller, more specialized builds; not everyone needs libudev, dbus, xorg, libdecor, jack, etc. support.

I also disagree with the idea we should be removing cross compilation support for packages because their dependencies are currently broken. That simply makes the problem worse, and pushes more work off to the future if those dependencies were to ever be fixed

libdecorSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid,
openglSupport ? lib.meta.availableOn stdenv.hostPlatform mesa,
pipewireSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid,
pulseaudioSupport ?
config.pulseaudio or stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid,
libudevSupport ? stdenv.hostPlatform.isLinux && !stdenv.hostPlatform.isAndroid,
sndioSupport ? false,
testSupport ? true,
waylandSupport ? stdenv.isLinux && !stdenv.hostPlatform.isAndroid,
x11Support ? !stdenv.hostPlatform.isAndroid && !stdenv.hostPlatform.isWindows,
}:

stdenv.mkDerivation (finalAttrs: {
pname = "sdl3";
version = "3.1.8";

outputs = [
"lib"
"dev"
"out"
OPNA2608 marked this conversation as resolved.
Show resolved Hide resolved
];

src = fetchFromGitHub {
owner = "libsdl-org";
repo = "SDL";
tag = "preview-${finalAttrs.version}";
hash = "sha256-yfnW5y99EegifRavvZWmXPH2NFPKWoe90RmGDGk6PI4=";
};

postPatch =
# Tests timeout on Darwin
lib.optionalString testSupport ''
substituteInPlace test/CMakeLists.txt \
--replace-fail 'set(noninteractive_timeout 10)' 'set(noninteractive_timeout 30)'
''
+ lib.optionalString waylandSupport ''
substituteInPlace src/video/wayland/SDL_waylandmessagebox.c \
--replace-fail '"zenity"' '"${lib.getExe zenity}"'
'';

strictDeps = true;

nativeBuildInputs = [
cmake
ninja
validatePkgConfig
] ++ lib.optional waylandSupport wayland-scanner;

buildInputs =
finalAttrs.dlopenBuildInputs
++ lib.optionals stdenv.hostPlatform.isDarwin [
# error: 'MTLPixelFormatASTC_4x4_LDR' is unavailable: not available on macOS
(darwinMinVersionHook "11.0")

apple-sdk_11
]
++ lib.optionals ibusSupport [
fcitx5
ibus
]
++ lib.optional waylandSupport zenity;

dlopenBuildInputs =
lib.optionals stdenv.hostPlatform.isLinux [
libusb1
]
++ lib.optional (
stdenv.hostPlatform.isUnix && !stdenv.hostPlatform.isDarwin
) libayatana-appindicator
++ lib.optional alsaSupport alsa-lib
++ lib.optional dbusSupport dbus
++ lib.optionals drmSupport [
libdrm
mesa # libgbm
]
++ lib.optional jackSupport libjack2
++ lib.optional libdecorSupport libdecor
++ lib.optional libudevSupport systemdLibs
++ lib.optional openglSupport libGL
++ lib.optional pipewireSupport pipewire
++ lib.optional pulseaudioSupport libpulseaudio
++ lib.optional sndioSupport sndio
++ lib.optionals waylandSupport [
libxkbcommon
wayland
]
++ lib.optionals x11Support [
xorg.libX11
xorg.libXScrnSaver
xorg.libXcursor
xorg.libXext
xorg.libXfixes
xorg.libXi
xorg.libXrandr
];

propagatedBuildInputs = finalAttrs.dlopenPropagatedBuildInputs;

dlopenPropagatedBuildInputs =
lib.optional (openglSupport && !stdenv.hostPlatform.isDarwin) libGL
++ lib.optional x11Support xorg.libX11;

cmakeFlags = [
(lib.cmakeBool "SDL_ALSA" alsaSupport)
(lib.cmakeBool "SDL_DBUS" dbusSupport)
(lib.cmakeBool "SDL_IBUS" ibusSupport)
(lib.cmakeBool "SDL_JACK" jackSupport)
(lib.cmakeBool "SDL_KMSDRM" drmSupport)
(lib.cmakeBool "SDL_LIBUDEV" libudevSupport)
(lib.cmakeBool "SDL_OPENGL" openglSupport)
(lib.cmakeBool "SDL_PIPEWIRE" pipewireSupport)
(lib.cmakeBool "SDL_PULSEAUDIO" pulseaudioSupport)
(lib.cmakeBool "SDL_SNDIO" sndioSupport)
(lib.cmakeBool "SDL_TEST_LIBRARY" testSupport)
(lib.cmakeBool "SDL_WAYLAND" waylandSupport)
(lib.cmakeBool "SDL_WAYLAND_LIBDECOR" libdecorSupport)
(lib.cmakeBool "SDL_X11" x11Support)

(lib.cmakeBool "SDL_TESTS" finalAttrs.finalPackage.doCheck)
];

doCheck = testSupport && stdenv.buildPlatform.canExecute stdenv.hostPlatform;

# See comment below. We actually *do* need these RPATH entries
dontPatchELF = true;

env = {
# Many dependencies are not directly linked to, but dlopen()'d at runtime. Adding them to the RPATH
# helps them be found
NIX_LDFLAGS =
lib.optionalString (stdenv.hostPlatform.extensions.sharedLibrary == ".so")
"-rpath ${
lib.makeLibraryPath (finalAttrs.dlopenBuildInputs ++ finalAttrs.dlopenPropagatedBuildInputs)
}";
};

passthru = {
# Building this in its own derivation to make sure the rpath hack above propagate to users
debug-text-example = stdenv.mkDerivation (finalAttrs': {
pname = "sdl3-debug-text-example";
inherit (finalAttrs) version src;

sourceRoot = "${finalAttrs'.src.name}/examples/renderer/18-debug-text";

nativeBuildInputs = [
installShellFiles
];

buildInputs = [ finalAttrs.finalPackage ];

postBuild = ''
$CC -lSDL3 -o debug-text{,.c}
'';

postInstall = ''
installBin debug-text
'';

meta = {
inherit (finalAttrs.meta) maintainers platforms;
mainProgram = "debug-text";
};
});

tests =
{
pkg-config = testers.hasPkgConfigModules { package = finalAttrs.finalPackage; };
inherit (finalAttrs.passthru) debug-text-example;
}
// lib.optionalAttrs stdenv.hostPlatform.isLinux {
nixosTest = nixosTests.sdl3;
};

updateScript = nix-update-script {
extraArgs = [
"--version-regex"
"'preview-(.*)'"
];
};
};

meta = {
description = "Cross-platform development library (Preview version)";
homepage = "https://libsdl.org";
changelog = "https://github.com/libsdl-org/SDL/releases/tag/${finalAttrs.src.tag}";
license = lib.licenses.zlib;
maintainers = with lib.maintainers; [ getchoo ];
platforms = lib.platforms.unix;
pkgConfigModules = [ "sdl3" ];
};
getchoo marked this conversation as resolved.
Show resolved Hide resolved
})