From 71dd7b5712273cbb9f846f4b8b5bd81e651ba08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=81vels=20Nadto=C4=8Dajevs?= <7645683+bruvzg@users.noreply.github.com> Date: Wed, 25 Jun 2025 06:39:23 +0300 Subject: [PATCH] Fix SDL threading on macOS/Linux. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And fixup pkg-config check for SDL on Linux. Co-authored-by: Rémi Verschelde --- drivers/sdl/SCsub | 5 +- platform/linuxbsd/detect.py | 2 +- thirdparty/sdl/thread/generic/SDL_systhread.c | 57 ------------------- thirdparty/sdl/update-sdl.sh | 8 ++- 4 files changed, 9 insertions(+), 63 deletions(-) delete mode 100644 thirdparty/sdl/thread/generic/SDL_systhread.c diff --git a/drivers/sdl/SCsub b/drivers/sdl/SCsub index b6bd1a5379..d6b65f1cfd 100644 --- a/drivers/sdl/SCsub +++ b/drivers/sdl/SCsub @@ -90,9 +90,6 @@ if env["builtin_sdl"]: "stdlib/SDL_string.c", "stdlib/SDL_strtokr.c", "thread/SDL_thread.c", - "thread/generic/SDL_syscond.c", - "thread/generic/SDL_sysrwlock.c", - "thread/generic/SDL_systhread.c", "timer/SDL_timer.c", ] @@ -182,6 +179,8 @@ if env["builtin_sdl"]: "joystick/windows/SDL_windows_gaming_input.c", "joystick/windows/SDL_windowsjoystick.c", "joystick/windows/SDL_xinputjoystick.c", + "thread/generic/SDL_syscond.c", + "thread/generic/SDL_sysrwlock.c", "thread/windows/SDL_syscond_cv.c", "thread/windows/SDL_sysmutex.c", "thread/windows/SDL_sysrwlock_srw.c", diff --git a/platform/linuxbsd/detect.py b/platform/linuxbsd/detect.py index b649c2f1b2..613d62e96e 100644 --- a/platform/linuxbsd/detect.py +++ b/platform/linuxbsd/detect.py @@ -397,7 +397,7 @@ def configure(env: "SConsEnvironment"): if env["sdl"]: if env["builtin_sdl"]: env.Append(CPPDEFINES=["SDL_ENABLED"]) - elif os.system("pkg-config --exists fontconfig") == 0: # 0 means found + elif os.system("pkg-config --exists sdl3") == 0: # 0 means found env.ParseConfig("pkg-config sdl3 --cflags --libs") env.Append(CPPDEFINES=["SDL_ENABLED"]) else: diff --git a/thirdparty/sdl/thread/generic/SDL_systhread.c b/thirdparty/sdl/thread/generic/SDL_systhread.c deleted file mode 100644 index ecfa4e13ef..0000000000 --- a/thirdparty/sdl/thread/generic/SDL_systhread.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - Simple DirectMedia Layer - Copyright (C) 1997-2025 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ -#include "SDL_internal.h" - -// Thread management routines for SDL - -#include "../SDL_systhread.h" - -bool SDL_SYS_CreateThread(SDL_Thread *thread, - SDL_FunctionPointer pfnBeginThread, - SDL_FunctionPointer pfnEndThread) -{ - return SDL_SetError("Threads are not supported on this platform"); -} - -void SDL_SYS_SetupThread(const char *name) -{ - return; -} - -SDL_ThreadID SDL_GetCurrentThreadID(void) -{ - return 0; -} - -bool SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority) -{ - return true; -} - -void SDL_SYS_WaitThread(SDL_Thread *thread) -{ - return; -} - -void SDL_SYS_DetachThread(SDL_Thread *thread) -{ - return; -} diff --git a/thirdparty/sdl/update-sdl.sh b/thirdparty/sdl/update-sdl.sh index 77ad3b2149..11a9d37f48 100755 --- a/thirdparty/sdl/update-sdl.sh +++ b/thirdparty/sdl/update-sdl.sh @@ -63,8 +63,12 @@ mkdir $target/sensor cp -rv sensor/{*.{c,h},dummy} $target/sensor mkdir $target/thread -cp -rv thread/{*.{c,h},generic,pthread,windows} $target/thread -rm -f $target/thread/generic/SDL_{sysmutex*.{c,h},systls.c} +cp -rv thread/{*.{c,h},pthread,windows} $target/thread +# Despite being 'generic', syssem.c is included in the Unix driver for macOS, +# and syscond/sysrwlock are used by the Windows driver. +# systhread_c.h is included by all these, but we should NOT compile the matching .c file. +mkdir $target/thread/generic +cp -v thread/generic/SDL_{syssem.c,{syscond,sysrwlock}*.{c,h},systhread_c.h} $target/thread/generic mkdir $target/timer cp -rv timer/{*.{c,h},unix,windows} $target/timer