Skip to content

Fix SDL_LEAN_AND_MEAN logic #11400

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

Merged
merged 2 commits into from
Dec 14, 2024
Merged

Fix SDL_LEAN_AND_MEAN logic #11400

merged 2 commits into from
Dec 14, 2024

Conversation

Lzard
Copy link
Contributor

@Lzard Lzard commented Nov 3, 2024

Currently, config flag macros depending on SDL_LEAN_AND_MEAN are always defined, regardless of its value, and only their definedness is checked, not their own values. Those changes fixes this.

See 387774a
Fixes #11344


While looking for other issues similar to this, I noticed:

  • Some config flag macros are conditionally defined, but may still not be true, e.g.:
    #if HAVE_WINAPIFAMILY_H
    #include <winapifamily.h>
    #define WINAPI_FAMILY_WINRT (!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP))
    #else
    #define WINAPI_FAMILY_WINRT 0
    #endif /* HAVE_WINAPIFAMILY_H */
    #if HAVE_WINAPIFAMILY_H && HAVE_WINAPIFAMILY_H
    #define SDL_WINAPI_FAMILY_PHONE (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
    #else
    #define SDL_WINAPI_FAMILY_PHONE 0
    #endif
  • Third-parties sometimes always define the config flag, but either as true or false, e.g. the OpenGL/Vulkan headers, or even compiler flags:
    /* Fix building with older SDKs that don't define these
    See this for more information:
    https://stackoverflow.com/questions/12132933/preprocessor-macro-for-os-x-targets
    */
    #ifndef TARGET_OS_MACCATALYST
    #define TARGET_OS_MACCATALYST 0
    #endif
    #ifndef TARGET_OS_IOS
    #define TARGET_OS_IOS 0
    #endif
    #ifndef TARGET_OS_IPHONE
    #define TARGET_OS_IPHONE 0
    #endif
    #ifndef TARGET_OS_TV
    #define TARGET_OS_TV 0
    #endif
    #ifndef TARGET_OS_SIMULATOR
    #define TARGET_OS_SIMULATOR 0
    #endif
    #ifndef TARGET_OS_VISION
    #define TARGET_OS_VISION 0
    #endif

It might be better to always check that config flag macros are defined and true.

Lzard added 2 commits November 3, 2024 11:27
I am confused by the "You have to manually edit this file" comment. Does it mean that it is expected to manually remove the previous `#define SDL_LEAN_AND_MEAN 0` ?
In any case I put this part of the change in a separate commit so that it can easily be reverted.
@rollerozxa
Copy link
Contributor

rollerozxa commented Dec 14, 2024

Tested PR when building for Linux as well as for Windows (cross-compiling with llvm-mingw), works and fixes the issue.

On main, with an SDL3 static library built with SDL_LEAN_AND_MEAN=1, the optimised blitters, RLE accelerated surfaces and YUV are disabled as they should be (their respective object files resemble stubs 396 bytes in size in the .a file), but the software renderer is not:

/tmp/sdl/build >>> ar tv libSDL3.a | grep '396'                                                                                
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_audiodev.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 imKStoUCS.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_runapp.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_yuv_sw.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_render_ps2.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_render_psp.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_mslibc.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_RLEaccel.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_0.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_1.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_A.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_N.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_auto.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 yuv_rgb_lsx.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 yuv_rgb_sse.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 yuv_rgb_std.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 pch.c.obj

With this PR all beforementioned remain disabled, and the software renderer and associated object files are disabled too.

/tmp/sdl/build >>> ar tv libSDL3.a | grep '396'                                                                                
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_audiodev.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 imKStoUCS.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_runapp.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_yuv_sw.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_render_ps2.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_render_psp.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blendline.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blendpoint.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_drawline.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_drawpoint.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_render_sw.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_rotate.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_triangle.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_mslibc.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_RLEaccel.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_0.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_1.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_A.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_N.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 SDL_blit_auto.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 yuv_rgb_lsx.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 yuv_rgb_sse.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 yuv_rgb_std.c.obj
rw-r--r-- 0/0    396 Jan  1 01:00 1970 pch.c.obj

@slouken slouken merged commit 6cc9ce1 into libsdl-org:main Dec 14, 2024
39 checks passed
@slouken
Copy link
Collaborator

slouken commented Dec 14, 2024

Merged, thanks!

@Lzard Lzard deleted the fix-lean-and-mean branch December 14, 2024 19:14
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

Successfully merging this pull request may close these issues.

Broken preprocessor logic for SDL_LEAN_AND_MEAN (and possibly more?)
3 participants