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

Build stub library from dynapi? #25

Open
icculus opened this issue Mar 26, 2024 · 1 comment
Open

Build stub library from dynapi? #25

icculus opened this issue Mar 26, 2024 · 1 comment

Comments

@icculus
Copy link
Contributor

icculus commented Mar 26, 2024

This might be a completely stupid idea (and maybe I said it before?), but I was thinking:

For projects that just want to make sure they build on GitHub Actions and don't care beyond that, we could maybe do this:

  • Grab a copy of the SDL sources.
  • Build with a file that turns SDL/src/dynapi/SDL_dynapi_procs.h into a complete library in one source file
  • Compile that one source file into a library that has all the right symbols but no actual code, install that and the public headers.
  • Project on GitHub Actions compiles against the headers and links against this stub library.

The benefit is that building SDL from scratch is (presumably) significantly faster and doesn't need any special configuration beyond access to a C compiler, and doesn't need extra tools and dependencies installed. The downside is obviously this won't actually function as a library if the project wants to run tests or whatnot, so this would have to be an option and not the default.

The source code to compile might look as simple as:

#include <SDL3/SDL.h>
#define SDL_DYNAPI_PROC(rettype,fnname,params,args,retn) \
    rettype fnname params { retn 0; }
#include "SDL_dynapi_procs.h"

...is this a terrible idea?

@madebr
Copy link
Collaborator

madebr commented Mar 26, 2024

Not a dumb idea at all. It ties to this issue with the satellite libraries.
I remembered this old Phoronix article about llvm creating interface libraries and tried it on the SDL library.

llvm-ifs --input-format=ELF libSDL3.so.0 --output-ifs libSDL3.txt

generates this file.

I pruned all non-SDL symbols and ran the following command:

llvm-ifs --endianness=little --arch=x86_64 --bitwidth=64 --input-format=IFS libSDL3.pruned.txt --output-elf libSDL3_ifs.so

Compiling and linking a SDL test executable against this interface library results in a working executable:

gcc ../test/testutils.c ../test/testsprite.c -I ../include libSDL3_test.a  -lunwind libSDL3_ifs.so -Wl,-rpath,$PWD

The only issue with the interface library is that:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants