NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.41k stars 13.63k forks source link

libSDL2 does not ship SDL2 `.a` files when built #146759

Closed peperunas closed 2 years ago

peperunas commented 2 years ago

Describe the bug

It seems that libSDL2 does not ship .a files. Particularly, I am having issues with projects that look for libSDL2main.a.

The issue persists even when SDL2 is used with withStatic = true.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Build SDL2 and look in $out/lib

Additional context

This issue has been presented in multiple occasions, e.g. #98242 and #24984

Notify maintainers

@cpages

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

$ nix-shell -p nix-info --run "nix-info -m"                                                                                                                          130 ↵
 - system: `"x86_64-linux"`
 - host os: `Linux 5.10.78, NixOS, 21.05.20211115.46251a7 (Okapi)`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.4pre20211006_53e4794`
 - channels(root): `"nixos-21.05.2549.a1007637cea, home-manager-21.05, nixos-unstable-21.11pre304920.dd98b100651"`
 - channels(giulio): `""`
 - nixpkgs: `/nix/store/ql6s3pl8gfv6v1n3ffsww0yspbji5lx3-source`
r-burns commented 2 years ago

Interesting - I think this is because the SDL2 builder tries to delete extraneous static libraries:

https://github.com/NixOS/nixpkgs/blob/595dde5dbe42f2ca60cb2e5e7454fa3076e86610/pkgs/development/libraries/SDL2/default.nix#L98

But libSDL2main.a is "special" because it doesn't have a corresponding .so, so I think we should always keep that one.

peperunas commented 2 years ago

Yes, as of now I am using this:

  SDL2 = pkgs.SDL2.overrideAttrs (old: {
    postInstall = ''
      moveToOutput lib/libSDL2main.a "$dev"
      if [ "$dontDisableStatic" -eq "1" ]; then
        rm $out/lib/*.la
      else
        rm $out/lib/*.a
      fi
      moveToOutput bin/sdl2-config "$dev"
      cp $dev/lib/libSDL2main.a $out/lib/
    '';
  });
romatthe commented 2 years ago

I encountered this issue as well when trying to package this Blake Stone source port, which explicitly tries to find libSDL2main.a. Took me a while to figure out what was going on. @peperunas' fix does help, for now at least.

SuperSandro2000 commented 2 years ago

https://github.com/NixOS/nixpkgs/pull/149601#issuecomment-1214247198