dvui icon indicating copy to clipboard operation
dvui copied to clipboard

Cannot build SDL examples <- Cannot build SDL from Zig build source

Open iacore opened this issue 1 year ago • 5 comments

When I try to run zig build sdl-ontop or zig build sdl-standalone, I see the following error:

❯ zig build sdl-standalone
sdl-standalone
└─ run sdl-standalone
   └─ compile-sdl-standalone
      └─ install sdl-standalone
         └─ zig build-exe sdl-standalone Debug native
            └─ zig build-lib SDL2 Debug native 1 errors
/home/user/.cache/zig/p/1220bdd8cfd7740aa9f8cce7679824a17b364ff5a34698aa2c1c75ea77e0df15a3b1/include/SDL_opengles.h:33:10: error: 'GLES/gl.h' file not found
#include <GLES/gl.h>
         ^~~~~~~~~~~~
/home/user/.cache/zig/p/1220bdd8cfd7740aa9f8cce7679824a17b364ff5a34698aa2c1c75ea77e0df15a3b1/src/render/opengles/SDL_render_gles.c:27:10: note: in file included from /home/user/.cache/zig/p/1220bdd8cfd7740aa9f8cce7679824a17b364ff5a34698aa2c1c75ea77e0df15a3b1/src/render/opengles/SDL_render_gles.c:27:
#include "SDL_opengles.h"

Here are my headers.

❯ ls /usr/include/G
…include/GL/        …include/GLES2/  …include/GLFW/          
…include/Glacier2/  …include/GLES3/  …include/GraphicsMagick/

I don't have GLES/gl.h.

iacore avatar Sep 19 '24 20:09 iacore

This works: zig build sdl-standalone -fsys=sdl2.

iacore avatar Sep 19 '24 21:09 iacore

This was discussed extensively here https://github.com/david-vanderson/dvui/issues/117

It seems to be an allyourcodebase/sdl issue building on linux

VisenDev avatar Sep 19 '24 23:09 VisenDev

Recently we started compiling SDL on linux by default. Before we always assumed SDL was already installed (same as passing -fsys=sdl2 now).

I haven't looked into this very much. I suspect one of 2 things is happening:

  1. Standard SDL wouldn't compile anyway due to the missing header, or
  2. Standard SDL configure would figure out which of the headers you do have it could use, and tweak some compilation options. If that is the case, then https://github.com/allyourcodebase/SDL needs those smarts added to its build.zig

david-vanderson avatar Sep 19 '24 23:09 david-vanderson

Probably 2. The official build system is CMake. Here it links GLESv2.

I have successfully built https://github.com/libsdl-org/SDL. (The WIP SDL 3.0)

Seems like https://github.com/allyourcodebase/SDL is not accepting issues. Maybe we revert to the behavior of always using the system SDL on Linux for the meantime. I doubt that allyourcodebase/SDL will have all the smarts the official SDL build system has.

allyourcodebase/SDL has derived from SDL 2.

iacore avatar Sep 22 '24 01:09 iacore

The best solution here would be for us to figure out what needed to be added to the https://github.com/allyourcodebase/SDL build.zig and send a PR. In the future we'd like to not depend on any libraries being installed already (of course we must be practical about this).

Let me see if I can reproduce this, because then I can work on a PR. Thanks very much for the link to the CMake part!

david-vanderson avatar Sep 22 '24 18:09 david-vanderson

I pushed a commit to disable SDL trying to build support for opengles1 - @iacore does this fix it for you?

Note that I had to wipe my ~/.cache/zig folder to get zig to recompile SDL.

david-vanderson avatar Nov 18 '24 18:11 david-vanderson

I confirm this fixes the issue. Thanks!

iacore avatar Nov 26 '24 16:11 iacore