git.iko.soy/typeable/nixpkgs
on master help sign in
SDL, SDL2: don't link statically to any of the inputs
commitf114118842e19ced171fd634d6ff70a92746f2cb authorJan Malakhovski <oxij@oxij.org> dateMon 5 Mar 2018, 20:12 (9 years ago) parent6166027
2 files changed+39−21
pkgs/development/libraries/SDL/default.nix+9−8 pkgs/development/libraries/SDL2/default.nix+30−13
pkgs/development/libraries/SDL/default.nix+9−8
@@ -17,17 +17,10 @@ assert openglSupport -> (stdenv.isDarwin || x11Support && libGL != null && libGL
1717
1818let
1919
20− # XXX: By default, SDL wants to dlopen() PulseAudio, in which case
21− # we must arrange to add it to its RPATH; however, `patchelf' seems
22− # to fail at doing this, hence `--disable-pulseaudio-shared'.
2320 configureFlagsFun = attrs: [
2421 "--disable-oss"
2522 "--disable-video-x11-xme"
26− "--disable-x11-shared"
27− "--disable-alsa-shared"
2823 "--enable-rpath"
29− "--disable-pulseaudio-shared"
30− "--disable-osmesa-shared"
3124 ] ++ optional (!x11Support) "--without-x"
3225 ++ optional alsaSupport "--with-alsa-prefix=${attrs.alsaLib.out}/lib";
3326
@@ -47,7 +40,6 @@ stdenv.mkDerivation rec {
4740
4841 nativeBuildInputs = [ pkgconfig ];
4942
50− # Since `libpulse*.la' contain `-lgdbm', PulseAudio must be propagated.
5143 propagatedBuildInputs = [ ]
5244 ++ optionals x11Support [ libXext libICE libXrandr ]
5345 ++ optional stdenv.isLinux libcap
@@ -114,6 +106,15 @@ stdenv.mkDerivation rec {
114106 moveToOutput share/aclocal "$dev"
115107 '';
116108
109+ # See the same place in the expression for SDL2
110+ postFixup = ''
111+ for lib in $out/lib/*.so* ; do
112+ if [[ -L "$lib" ]]; then
113+ patchelf --set-rpath "$(patchelf --print-rpath $lib):${lib.makeLibraryPath propagatedBuildInputs}" "$lib"
114+ fi
115+ done
116+ '';
117+
117118 setupHook = ./setup-hook.sh;
118119
119120 passthru = { inherit openglSupport; };
pkgs/development/libraries/SDL2/default.nix+30−13
@@ -21,14 +21,10 @@ assert openglSupport -> (stdenv.isDarwin || x11Support && libGL != null);
2121
2222let
2323
24− # XXX: By default, SDL wants to dlopen() PulseAudio, in which case
25− # we must arrange to add it to its RPATH; however, `patchelf' seems
26− # to fail at doing this, hence `--disable-pulseaudio-shared'.
2724 configureFlagsFun = attrs: [
28− "--disable-oss" "--disable-x11-shared" "--disable-wayland-shared"
29− "--disable-pulseaudio-shared" "--disable-alsa-shared"
30− ] ++ optional alsaSupport "--with-alsa-prefix=${attrs.alsaLib.out}/lib"
31− ++ optional (!x11Support) "--without-x";
25+ "--disable-oss"
26+ ] ++ optional (!x11Support) "--without-x"
27+ ++ optional alsaSupport "--with-alsa-prefix=${attrs.alsaLib.out}/lib";
3228
3329in
3430
@@ -48,18 +44,17 @@ stdenv.mkDerivation rec {
4844
4945 nativeBuildInputs = [ pkgconfig ];
5046
51− # Since `libpulse*.la' contain `-lgdbm', PulseAudio must be propagated.
5247 propagatedBuildInputs = [ libiconv ]
48+ ++ optional dbusSupport dbus
49+ ++ optional udevSupport udev
5350 ++ optionals x11Support [ libICE libXi libXScrnSaver libXcursor libXinerama libXext libXrandr libXxf86vm ]
5451 ++ optionals waylandSupport [ wayland wayland-protocols libxkbcommon ]
52+ ++ optional alsaSupport alsaLib
5553 ++ optional pulseaudioSupport libpulseaudio;
5654
5755 buildInputs = [ audiofile ]
58− ++ optional openglSupport libGL
59− ++ optional alsaSupport alsaLib
60− ++ optional dbusSupport dbus
61− ++ optional udevSupport udev
62− ++ optional ibusSupport ibus
56+ ++ optional openglSupport libGL
57+ ++ optional ibusSupport ibus
6358 ++ optionals stdenv.isDarwin [ AudioUnit Cocoa CoreAudio CoreServices ForceFeedback OpenGL ];
6459
6560 # https://bugzilla.libsdl.org/show_bug.cgi?id=1431
@@ -81,6 +76,28 @@ stdenv.mkDerivation rec {
8176 moveToOutput bin/sdl2-config "$dev"
8277 '';
8378
79+ # SDL is weird in that instead of just dynamically linking with
80+ # libraries when you `--enable-*` (or when `configure` finds) them
81+ # it `dlopen`s them at runtime. In principle, this means it can
82+ # ignore any missing optional dependencies like alsa, pulseaudio,
83+ # some x11 libs, wayland, etc if they are missing on the system
84+ # and/or work with wide array of versions of said libraries. In
85+ # nixpkgs, however, we don't need any of that. Moreover, since we
86+ # don't have a global ld-cache we have to stuff all the propagated
87+ # libraries into rpath by hand or else some applications that use
88+ # SDL API that requires said libraries will fail to start.
89+ #
90+ # You can grep SDL sources with `grep -rE 'SDL_(NAME|.*_SYM)'` to
91+ # confirm that they actually use most of the `propagatedBuildInputs`
92+ # from above in this way. This is pretty weird.
93+ postFixup = ''
94+ for lib in $out/lib/*.so* ; do
95+ if [[ -L "$lib" ]]; then
96+ patchelf --set-rpath "$(patchelf --print-rpath $lib):${lib.makeLibraryPath propagatedBuildInputs}" "$lib"
97+ fi
98+ done
99+ '';
100+
84101 setupHook = ./setup-hook.sh;
85102
86103 passthru = { inherit openglSupport; };