From 6586bebfec42ed1418469d70dffa5216534bc635 Mon Sep 17 00:00:00 2001 From: stahta01 Date: Fri, 15 May 2026 11:48:24 -0400 Subject: [PATCH] Fix Cygwin building and add CI (#15566) Co-authored-by: TrueCat17 Co-authored-by: Anonymous Maarten Co-authored-by: Ozkan Sezer --- .github/workflows/create-test-plan.py | 23 ++++++++++++++ .github/workflows/generic.yml | 5 +++ CMakeLists.txt | 35 +++++++-------------- cmake/macros.cmake | 2 +- cmake/sdlplatform.cmake | 4 +++ include/SDL3/SDL_opengl.h | 2 +- include/SDL3/SDL_platform_defines.h | 4 +-- include/SDL3/SDL_stdinc.h | 10 +++--- include/SDL3/SDL_thread.h | 4 +-- src/SDL.c | 2 ++ src/audio/wasapi/SDL_wasapi.c | 2 +- src/core/windows/SDL_windows.h | 10 ++++++ src/dialog/windows/SDL_windowsdialog.c | 2 +- src/dynapi/SDL_dynapi.c | 6 ++-- src/gpu/d3d12/SDL_gpu_d3d12.c | 4 +-- src/hidapi/windows/hid.c | 2 +- src/io/SDL_iostream.c | 18 +++++------ src/io/SDL_iostream_c.h | 2 +- src/joystick/windows/SDL_rawinputjoystick.c | 6 ++-- src/time/windows/SDL_systime.c | 2 +- src/video/directx/SDL_d3d12.h | 7 +++++ src/video/windows/SDL_windowsrawinput.c | 2 +- src/video/windows/SDL_windowswindow.c | 28 ++++++++--------- test/CMakeLists.txt | 4 +-- test/childprocess.c | 4 +-- test/testautomation_stdlib.c | 4 ++- 26 files changed, 116 insertions(+), 78 deletions(-) diff --git a/.github/workflows/create-test-plan.py b/.github/workflows/create-test-plan.py index 8d5bdf621d..03883289a3 100755 --- a/.github/workflows/create-test-plan.py +++ b/.github/workflows/create-test-plan.py @@ -43,6 +43,7 @@ class SdlPlatform(Enum): Haiku = "haiku" LoongArch64 = "loongarch64" Msys2 = "msys2" + Cygwin = "cygwin" Linux = "linux" MacOS = "macos" Ios = "ios" @@ -111,6 +112,7 @@ JOB_SPECS = { "msys2-mingw64": JobSpec(name="Windows (msys2, mingw64)", os=JobOs.WindowsLatest, platform=SdlPlatform.Msys2, artifact="SDL-mingw64", msys2_platform=Msys2Platform.Mingw64, ), "msys2-clang64": JobSpec(name="Windows (msys2, clang64)", os=JobOs.WindowsLatest, platform=SdlPlatform.Msys2, artifact="SDL-mingw64-clang", msys2_platform=Msys2Platform.Clang64, ), "msys2-ucrt64": JobSpec(name="Windows (msys2, ucrt64)", os=JobOs.WindowsLatest, platform=SdlPlatform.Msys2, artifact="SDL-mingw64-ucrt", msys2_platform=Msys2Platform.Ucrt64, ), + "cygwin": JobSpec(name="Cygwin", os=JobOs.WindowsLatest, platform=SdlPlatform.Cygwin, artifact="SDL-cygwin", ), "msvc-x64": JobSpec(name="Windows (MSVC, x64)", os=JobOs.WindowsLatest, platform=SdlPlatform.Msvc, artifact="SDL-VC-x64", msvc_arch=MsvcArch.X64, msvc_project="VisualC/SDL.sln", ), "msvc-x86": JobSpec(name="Windows (MSVC, x86)", os=JobOs.WindowsLatest, platform=SdlPlatform.Msvc, artifact="SDL-VC-x86", msvc_arch=MsvcArch.X86, msvc_project="VisualC/SDL.sln", ), "msvc-clang-x64": JobSpec(name="Windows (MSVC, clang-cl x64)", os=JobOs.WindowsLatest, platform=SdlPlatform.Msvc, artifact="SDL-clang-cl-x64", msvc_arch=MsvcArch.X64, clang_cl=True, ), @@ -162,6 +164,7 @@ class StaticLibType(Enum): class SharedLibType(Enum): WIN32 = "SDL3.dll" + CYGDLL = "cygSDL3.dll" SO_0 = "libSDL3.so.0" SO = "libSDL3.so" DYLIB = "libSDL3.0.dylib" @@ -217,6 +220,7 @@ class JobDetails: intel: bool = False msys2_msystem: str = "" msys2_packages: list[str] = dataclasses.field(default_factory=list) + cygwin_packages: list[str] = dataclasses.field(default_factory=list) werror: bool = True microsoft_gameinput_version: str = "" msvc_vcvars_arch: str = "" @@ -254,6 +258,7 @@ class JobDetails: "shell": self.shell, "msys2-msystem": self.msys2_msystem, "msys2-packages": my_shlex_join(self.msys2_packages), + "cygwin-packages": my_shlex_join(self.cygwin_packages), "android-ndk": self.android_ndk, "java": self.java, "intel": self.intel, @@ -773,6 +778,24 @@ def spec_to_job(spec: JobSpec, key: str, trackmem_symbol_names: bool, ctest_args job.microsoft_gameinput_version = WINDOWS_GAMEINPUT_VERSION job.cflags.append("-I$GAMEINPUT_INCLUDE") job.cxxflags.append("-I$GAMEINPUT_INCLUDE") + case SdlPlatform.Cygwin: + job.ccache = False # Missing evict-older-than option + job.clang_tidy = False # error finding files [clang-diagnostic-error] cause might be space in command path + job.test_pkg_config = False # Linefeed issue in test_pkgconfig.sh + job.shell = "bash --noprofile --norc -eo pipefail -o igncr {0}" + job.shared_lib = SharedLibType.CYGDLL + job.static_lib = StaticLibType.A + job.cmake_arguments.append("-DSDLTEST_GDB=ON") + job.cygwin_packages.extend([ + "cmake", + "gcc-core", + "gcc-g++", + "gdb", + "ninja", + "pkg-config", + "perl", + "python", + ]) case SdlPlatform.Riscos: job.ccache = False # FIXME: enable when container gets upgrade # FIXME: Enable SDL_WERROR diff --git a/.github/workflows/generic.yml b/.github/workflows/generic.yml index 8250e50e72..be8180a20e 100644 --- a/.github/workflows/generic.yml +++ b/.github/workflows/generic.yml @@ -28,6 +28,11 @@ jobs: with: msystem: ${{ matrix.platform.msys2-msystem }} install: ${{ matrix.platform.msys2-packages }} + - name: 'Set up Cygwin' + if: ${{ matrix.platform.platform == 'cygwin' }} + uses: cygwin/cygwin-install-action@master + with: + packages: ${{ matrix.platform.cygwin-packages }} - name: 'About this job' run: | echo "key=${{ matrix.platform.key }}" diff --git a/CMakeLists.txt b/CMakeLists.txt index cf87671216..824f82448a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -369,9 +369,9 @@ dep_option(SDL_WAYLAND_LIBDECOR_SHARED "Dynamically load libdecor support" O dep_option(SDL_RPI "Use Raspberry Pi video driver" ON "SDL_VIDEO;UNIX_SYS;SDL_CPU_ARM32 OR SDL_CPU_ARM64" OFF) dep_option(SDL_ROCKCHIP "Use ROCKCHIP Hardware Acceleration video driver" ON "SDL_VIDEO;UNIX_SYS;SDL_CPU_ARM32 OR SDL_CPU_ARM64" OFF) dep_option(SDL_COCOA "Use Cocoa video driver" ON "APPLE" OFF) -dep_option(SDL_DIRECTX "Use DirectX for Windows audio/video" ON "SDL_AUDIO OR SDL_VIDEO;WINDOWS" OFF) -dep_option(SDL_XINPUT "Use Xinput for Windows" ON "WINDOWS" OFF) -dep_option(SDL_WASAPI "Use the Windows WASAPI audio driver" ON "WINDOWS;SDL_AUDIO" OFF) +dep_option(SDL_DIRECTX "Use DirectX for Windows audio/video" ON "SDL_AUDIO OR SDL_VIDEO;WINDOWS OR CYGWIN" OFF) +dep_option(SDL_XINPUT "Use Xinput for Windows" ON "WINDOWS OR CYGWIN" OFF) +dep_option(SDL_WASAPI "Use the Windows WASAPI audio driver" ON "WINDOWS OR CYGWIN;SDL_AUDIO" OFF) dep_option(SDL_RENDER_D3D "Enable the Direct3D 9 render driver" ON "SDL_RENDER;SDL_DIRECTX" OFF) dep_option(SDL_RENDER_D3D11 "Enable the Direct3D 11 render driver" ON "SDL_RENDER;SDL_DIRECTX" OFF) dep_option(SDL_RENDER_D3D12 "Enable the Direct3D 12 render driver" ON "SDL_RENDER;SDL_DIRECTX" OFF) @@ -565,19 +565,6 @@ else() endif() endif() -if(CYGWIN) - # We build SDL on cygwin without the UNIX emulation layer - sdl_include_directories(PUBLIC SYSTEM "/usr/include/mingw") - cmake_push_check_state() - string(APPEND CMAKE_REQUIRED_FLAGS " -mno-cygwin") - check_c_source_compiles("int main(int argc, char **argv) { return 0; }" - HAVE_GCC_NO_CYGWIN) - cmake_pop_check_state() - if(HAVE_GCC_NO_CYGWIN) - sdl_shared_link_options("-mno-cygwin") - endif() -endif() - # General includes sdl_compile_definitions(PRIVATE "USING_GENERATED_CONFIG_H") sdl_include_directories( @@ -1165,7 +1152,7 @@ if(SDL_LIBC) vsnprintf vsscanf wcsnlen wcscmp wcsdup wcslcat wcslcpy wcslen wcsncmp wcsstr wcstol ) - if(WINDOWS) + if(WINDOWS OR CYGWIN) list(APPEND symbols_to_check _copysign _fseeki64 _strrev _ui64toa _uitoa _ultoa _wcsdup ) @@ -1444,7 +1431,7 @@ if(SDL_CAMERA) #endif() endif() -if(UNIX OR APPLE) +if((UNIX OR APPLE) AND NOT CYGWIN) # Relevant for Unix/Darwin only set(DYNAPI_NEEDS_DLOPEN 1) CheckDLOPEN() @@ -1843,7 +1830,7 @@ elseif(EMSCRIPTEN) CheckPTHREAD() CheckLibUnwind() -elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) +elseif(UNIX AND NOT (APPLE OR RISCOS OR HAIKU OR CYGWIN)) set(SDL_DISABLE_DLOPEN_NOTES TRUE) if(SDL_DLOPEN_NOTES) @@ -2234,7 +2221,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) set (HAVE_VSNPRINTF 0) set (USE_POSIX_SPAWN 1) endif() -elseif(WINDOWS) +elseif(WINDOWS OR CYGWIN) enable_language(CXX) check_c_source_compiles(" #include @@ -2268,7 +2255,7 @@ elseif(WINDOWS) if(DEFINED MSVC_VERSION AND NOT ${MSVC_VERSION} LESS 1700) set(USE_WINSDK_DIRECTX TRUE) endif() - if(NOT MINGW AND NOT USE_WINSDK_DIRECTX) + if(NOT (MINGW OR CYGWIN) AND NOT USE_WINSDK_DIRECTX) if("$ENV{DXSDK_DIR}" STREQUAL "") message(FATAL_ERROR "DIRECTX requires the \$DXSDK_DIR environment variable to be set") endif() @@ -2287,7 +2274,7 @@ elseif(WINDOWS) cmake_pop_check_state() if(HAVE_D3D9_H OR HAVE_D3D11_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H) set(HAVE_DIRECTX TRUE) - if(NOT MINGW AND NOT USE_WINSDK_DIRECTX) + if(NOT (MINGW OR CYGWIN) AND NOT USE_WINSDK_DIRECTX) if(CMAKE_SIZEOF_VOID_P EQUAL 8) set(PROCESSOR_ARCH "x64") else() @@ -4104,13 +4091,13 @@ if(SDL_SHARED) RESOURCE "${SDL_FRAMEWORK_RESOURCES}" ) endif() - elseif(UNIX AND NOT ANDROID) + elseif(UNIX AND NOT (ANDROID OR CYGWIN)) set_target_properties(SDL3-shared PROPERTIES VERSION "${SDL_SO_VERSION}" SOVERSION "${SDL_SO_VERSION_MAJOR}" ) else() - if(WINDOWS OR CYGWIN) + if(WINDOWS) set_target_properties(SDL3-shared PROPERTIES PREFIX "" ) diff --git a/cmake/macros.cmake b/cmake/macros.cmake index eb445b233d..afa0a3b597 100644 --- a/cmake/macros.cmake +++ b/cmake/macros.cmake @@ -425,7 +425,7 @@ function(SDL_PrintSummary) message(STATUS "") endif() - if(UNIX AND NOT (ANDROID OR APPLE OR EMSCRIPTEN OR HAIKU OR RISCOS OR DJGPP)) + if(UNIX AND NOT (ANDROID OR APPLE OR EMSCRIPTEN OR HAIKU OR RISCOS OR DJGPP OR CYGWIN)) if(NOT (HAVE_X11 OR HAVE_WAYLAND)) if(NOT SDL_UNIX_CONSOLE_BUILD) message(FATAL_ERROR diff --git a/cmake/sdlplatform.cmake b/cmake/sdlplatform.cmake index 6c60e0a2b3..14455f435e 100644 --- a/cmake/sdlplatform.cmake +++ b/cmake/sdlplatform.cmake @@ -4,6 +4,10 @@ function(SDL_DetectCMakePlatform) set(sdl_cmake_platform Windows) elseif(PSP) set(sdl_cmake_platform psp) + elseif(CYGWIN AND NOT MSYS) + set(sdl_cmake_platform Cygwin) + elseif(MSYS) + set(sdl_cmake_platform Msys) elseif(APPLE) if(CMAKE_SYSTEM_NAME MATCHES ".*(Darwin|MacOS).*") set(sdl_cmake_platform macOS) diff --git a/include/SDL3/SDL_opengl.h b/include/SDL3/SDL_opengl.h index 733f2b51a0..d76764b253 100644 --- a/include/SDL3/SDL_opengl.h +++ b/include/SDL3/SDL_opengl.h @@ -84,7 +84,7 @@ # else # define GLAPIENTRY __stdcall # endif -#elif defined(__CYGWIN__) && defined(USE_OPENGL32) /* use native windows opengl32 */ +#elif defined(__CYGWIN__) /* && defined(USE_OPENGL32) */ /* use native windows opengl32 */ # define GLAPI extern # define GLAPIENTRY __stdcall #elif (defined(__GNUC__) && __GNUC__ >= 4) || (defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)) diff --git a/include/SDL3/SDL_platform_defines.h b/include/SDL3/SDL_platform_defines.h index 23ff34ce10..71dbd53fec 100644 --- a/include/SDL3/SDL_platform_defines.h +++ b/include/SDL3/SDL_platform_defines.h @@ -317,7 +317,7 @@ #define SDL_PLATFORM_CYGWIN 1 #endif -#if (defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN)) && !defined(__NGAGE__) +#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(__NGAGE__) /** * A preprocessor macro that is only defined if compiling for Windows. @@ -417,7 +417,7 @@ #define SDL_PLATFORM_WIN32 1 #endif -#endif /* defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN) */ +#endif /* (defined(_WIN32) || defined(__CYGWIN__)) && !defined(__NGAGE__) */ /* This is to support generic "any GDK" separate from a platform-specific GDK */ diff --git a/include/SDL3/SDL_stdinc.h b/include/SDL3/SDL_stdinc.h index 893f2052f7..3a7920abeb 100644 --- a/include/SDL3/SDL_stdinc.h +++ b/include/SDL3/SDL_stdinc.h @@ -739,7 +739,7 @@ typedef Sint64 SDL_Time; * should define these but this is not true all platforms. * (for example win32) */ #ifndef SDL_PRIs64 -#if defined(SDL_PLATFORM_WINDOWS) +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) #define SDL_PRIs64 "I64d" #elif defined(PRId64) #define SDL_PRIs64 PRId64 @@ -750,7 +750,7 @@ typedef Sint64 SDL_Time; #endif #endif #ifndef SDL_PRIu64 -#if defined(SDL_PLATFORM_WINDOWS) +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) #define SDL_PRIu64 "I64u" #elif defined(PRIu64) #define SDL_PRIu64 PRIu64 @@ -761,7 +761,7 @@ typedef Sint64 SDL_Time; #endif #endif #ifndef SDL_PRIx64 -#if defined(SDL_PLATFORM_WINDOWS) +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) #define SDL_PRIx64 "I64x" #elif defined(PRIx64) #define SDL_PRIx64 PRIx64 @@ -772,7 +772,7 @@ typedef Sint64 SDL_Time; #endif #endif #ifndef SDL_PRIX64 -#if defined(SDL_PLATFORM_WINDOWS) +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) #define SDL_PRIX64 "I64X" #elif defined(PRIX64) #define SDL_PRIX64 PRIX64 @@ -811,7 +811,7 @@ typedef Sint64 SDL_Time; #endif #endif /* Specifically for the `long long` -- SDL-specific. */ -#ifdef SDL_PLATFORM_WINDOWS +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) #ifndef SDL_NOLONGLONG SDL_COMPILE_TIME_ASSERT(longlong_size64, sizeof(long long) == 8); /* using I64 for windows - make sure `long long` is 64 bits. */ #endif diff --git a/include/SDL3/SDL_thread.h b/include/SDL3/SDL_thread.h index 1842c035f7..83d11f90a2 100644 --- a/include/SDL3/SDL_thread.h +++ b/include/SDL3/SDL_thread.h @@ -48,7 +48,7 @@ /* Thread synchronization primitives */ #include -#if defined(SDL_PLATFORM_WINDOWS) +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) #include /* _beginthreadex() and _endthreadex() */ #endif @@ -296,7 +296,7 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadWithProperties(SDL_Prop /* The real implementation, hidden from the wiki, so it can show this as real functions that don't have macro magic. */ #ifndef SDL_WIKI_DOCUMENTATION_SECTION -# if defined(SDL_PLATFORM_WINDOWS) +# if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) # ifndef SDL_BeginThreadFunction # define SDL_BeginThreadFunction _beginthreadex # endif diff --git a/src/SDL.c b/src/SDL.c index 350ca34b34..11b8872928 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -793,6 +793,8 @@ const char *SDL_GetPlatform(void) return "Solaris"; #elif defined(SDL_PLATFORM_WIN32) return "Windows"; +#elif defined(SDL_PLATFORM_CYGWIN) + return "Cygwin"; #elif defined(SDL_PLATFORM_WINGDK) return "WinGDK"; #elif defined(SDL_PLATFORM_XBOXONE) diff --git a/src/audio/wasapi/SDL_wasapi.c b/src/audio/wasapi/SDL_wasapi.c index c01f007ff1..2ef4de82fe 100644 --- a/src/audio/wasapi/SDL_wasapi.c +++ b/src/audio/wasapi/SDL_wasapi.c @@ -773,7 +773,7 @@ static bool mgmtthrtask_PrepDevice(void *userdata) ret = IAudioClient2_SetClientProperties(client2, &audioProps); if (FAILED(ret)) { // This isn't fatal, let's log it instead of failing - SDL_LogWarn(SDL_LOG_CATEGORY_AUDIO, "IAudioClient2_SetClientProperties failed: 0x%lx", ret); + SDL_LogWarn(SDL_LOG_CATEGORY_AUDIO, "IAudioClient2_SetClientProperties failed: 0x%" SDL_PRIxSLONG, ret); } IAudioClient2_Release(client2); } diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h index 5317e30d08..62c1c3a9af 100644 --- a/src/core/windows/SDL_windows.h +++ b/src/core/windows/SDL_windows.h @@ -146,6 +146,16 @@ #define SDL_tcsstr SDL_strstr #endif +#if defined(__LP64__) +#define SDL_PRIdSLONG "d" +#define SDL_PRIuULONG "u" +#define SDL_PRIxSLONG "x" +#else +#define SDL_PRIdSLONG "ld" +#define SDL_PRIuULONG "lu" +#define SDL_PRIxSLONG "lx" +#endif + // Set up for C function definitions, even when using C++ #ifdef __cplusplus extern "C" { diff --git a/src/dialog/windows/SDL_windowsdialog.c b/src/dialog/windows/SDL_windowsdialog.c index 99a49384d6..a9f2c749bd 100644 --- a/src/dialog/windows/SDL_windowsdialog.c +++ b/src/dialog/windows/SDL_windowsdialog.c @@ -1035,7 +1035,7 @@ void windows_ShowFileDialog(void *ptr) const char *opts[1] = { NULL }; callback(userdata, opts, getFilterIndex(dialog.nFilterIndex)); } else { - SDL_SetError("Windows error, CommDlgExtendedError: %ld", pCommDlgExtendedError()); + SDL_SetError("Windows error, CommDlgExtendedError: %" SDL_PRIuULONG, pCommDlgExtendedError()); callback(userdata, NULL, -1); } } diff --git a/src/dynapi/SDL_dynapi.c b/src/dynapi/SDL_dynapi.c index a0135dca42..fcbbbd6d61 100644 --- a/src/dynapi/SDL_dynapi.c +++ b/src/dynapi/SDL_dynapi.c @@ -48,7 +48,7 @@ // These headers have system specific definitions, so aren't included above #include -#if defined(WIN32) || defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN) +#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) #ifndef WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN 1 #endif @@ -451,7 +451,7 @@ Sint32 SDL_DYNAPI_entry(Uint32 apiver, void *table, Uint32 tablesize) // Obviously we can't use SDL_LoadObject() to load SDL. :) // Also obviously, we never close the loaded library, once we accept it. -#if defined(WIN32) || defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN) +#if defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__) static HMODULE sdlapi_lib = NULL; // The handle to the other SDL library, loaded with SDL_DYNAMIC_API_ENVVAR static SDL_INLINE void unload_sdlapi_library(void) @@ -509,7 +509,7 @@ static void dynapi_warn(const char *msg) const char *caption = "SDL Dynamic API Failure!"; (void)caption; // SDL_ShowSimpleMessageBox() is a too heavy for here. -#if (defined(WIN32) || defined(_WIN32) || defined(SDL_PLATFORM_CYGWIN)) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) +#if (defined(WIN32) || defined(_WIN32) || defined(__CYGWIN__)) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) MessageBoxA(NULL, msg, caption, MB_OK | MB_ICONERROR); #elif defined(HAVE_STDIO_H) fprintf(stderr, "\n\n%s\n%s\n\n", caption, msg); diff --git a/src/gpu/d3d12/SDL_gpu_d3d12.c b/src/gpu/d3d12/SDL_gpu_d3d12.c index 3a1d651fdd..2b65006d21 100644 --- a/src/gpu/d3d12/SDL_gpu_d3d12.c +++ b/src/gpu/d3d12/SDL_gpu_d3d12.c @@ -9036,7 +9036,7 @@ static bool D3D12_INTERNAL_GetAdapterByLuid(LUID luid, IDXGIFactory1 *factory, I IDXGIAdapter1 *adapter; res = IDXGIFactory1_EnumAdapters1(factory, adapterIndex, &adapter); if (FAILED(res)) { - SDL_LogError(SDL_LOG_CATEGORY_GPU, "Failed to get an adapter when iterating, i: %d, res: %ld", adapterIndex, res); + SDL_LogError(SDL_LOG_CATEGORY_GPU, "Failed to get an adapter when iterating, i: %d, res: %" SDL_PRIdSLONG, adapterIndex, res); return false; } @@ -9044,7 +9044,7 @@ static bool D3D12_INTERNAL_GetAdapterByLuid(LUID luid, IDXGIFactory1 *factory, I res = IDXGIAdapter1_GetDesc1(adapter, &adapterDesc); if (FAILED(res)) { IDXGIAdapter1_Release(adapter); - SDL_LogError(SDL_LOG_CATEGORY_GPU, "Failed to get description of adapter, i: %d, res %ld", adapterIndex, res); + SDL_LogError(SDL_LOG_CATEGORY_GPU, "Failed to get description of adapter, i: %d, res %" SDL_PRIdSLONG, adapterIndex, res); return false; } if (SDL_memcmp(&adapterDesc.AdapterLuid, &luid, sizeof(luid)) == 0) { diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c index 49a53f9bb3..3d0b4d41d7 100644 --- a/src/hidapi/windows/hid.c +++ b/src/hidapi/windows/hid.c @@ -45,7 +45,7 @@ typedef LONG NTSTATUS; #define _WIN32_WINNT_WIN8 0x0602 #endif -#ifdef __CYGWIN__ +#if defined(__CYGWIN__) && !defined(HIDAPI_USING_SDL_RUNTIME) #include #include #define _wcsdup wcsdup diff --git a/src/io/SDL_iostream.c b/src/io/SDL_iostream.c index 6b19364678..9b5a0978f2 100644 --- a/src/io/SDL_iostream.c +++ b/src/io/SDL_iostream.c @@ -20,7 +20,7 @@ */ #include "SDL_internal.h" -#if defined(SDL_PLATFORM_WINDOWS) +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) #include "../core/windows/SDL_windows.h" #else #include @@ -62,7 +62,7 @@ struct SDL_IOStream #include "../core/android/SDL_android.h" #endif -#if defined(SDL_PLATFORM_WINDOWS) +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) typedef struct IOStreamWindowsData { @@ -478,9 +478,7 @@ SDL_IOStream *SDL_IOFromHandle(HANDLE handle, const char *mode, bool autoclose) return iostr; } -#endif // defined(SDL_PLATFORM_WINDOWS) - -#if !defined(SDL_PLATFORM_WINDOWS) +#else // Functions to read/write file descriptors. Not used for windows. @@ -672,9 +670,9 @@ SDL_IOStream *SDL_IOFromFD(int fd, bool autoclose) return iostr; } -#endif // !defined(SDL_PLATFORM_WINDOWS) +#endif // SDL_PLATFORM_WINDOWS && !SDL_PLATFORM_CYGWIN -#if defined(HAVE_STDIO_H) && !defined(SDL_PLATFORM_WINDOWS) +#if defined(HAVE_STDIO_H) && !(defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN)) // Functions to read/write stdio file pointers. Not used for windows. @@ -871,7 +869,7 @@ SDL_IOStream *SDL_IOFromFP(FILE *fp, bool autoclose) return iostr; } -#endif // !HAVE_STDIO_H && !defined(SDL_PLATFORM_WINDOWS) +#endif // HAVE_STDIO_H && !SDL_PLATFORM_WINDOWS && !SDL_PLATFORM_CYGWIN // Functions to read/write memory pointers @@ -965,7 +963,7 @@ static bool SDLCALL mem_close(void *userdata) // Functions to create SDL_IOStream structures from various data sources // private platforms might define SKIP_STDIO_DIR_TEST in their build configs, too. -#if defined(SDL_PLATFORM_WINDOWS) || defined(SDL_PLATFORM_EMSCRIPTEN) +#if (defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN)) || defined(SDL_PLATFORM_EMSCRIPTEN) #define SKIP_STDIO_DIR_TEST 1 #endif @@ -1101,7 +1099,7 @@ SDL_IOStream *SDL_IOFromFile(const char *file, const char *mode) iostr = SDL_IOFromFP(fp, true); } -#elif defined(SDL_PLATFORM_WINDOWS) +#elif defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) HANDLE handle = windows_file_open(file, mode); if (handle != INVALID_HANDLE_VALUE) { iostr = SDL_IOFromHandle(handle, mode, true); diff --git a/src/io/SDL_iostream_c.h b/src/io/SDL_iostream_c.h index fadb98bcb6..be955e89ad 100644 --- a/src/io/SDL_iostream_c.h +++ b/src/io/SDL_iostream_c.h @@ -23,7 +23,7 @@ #ifndef SDL_iostream_c_h_ #define SDL_iostream_c_h_ -#if defined(SDL_PLATFORM_WINDOWS) +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) SDL_IOStream *SDL_IOFromHandle(HANDLE handle, const char *mode, bool autoclose); #else #if defined(HAVE_STDIO_H) diff --git a/src/joystick/windows/SDL_rawinputjoystick.c b/src/joystick/windows/SDL_rawinputjoystick.c index da557c5e86..8c660c3d23 100644 --- a/src/joystick/windows/SDL_rawinputjoystick.c +++ b/src/joystick/windows/SDL_rawinputjoystick.c @@ -706,12 +706,12 @@ static void RAWINPUT_InitWindowsGamingInput(RAWINPUT_DeviceContext *ctx) hr = __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics_add_GamepadAdded(wgi_state.gamepad_statics, &gamepad_added.iface, &wgi_state.gamepad_added_token); if (!SUCCEEDED(hr)) { - SDL_SetError("add_GamepadAdded() failed: 0x%lx", hr); + SDL_SetError("add_GamepadAdded() failed: 0x%" SDL_PRIxSLONG, hr); } hr = __x_ABI_CWindows_CGaming_CInput_CIGamepadStatics_add_GamepadRemoved(wgi_state.gamepad_statics, &gamepad_removed.iface, &wgi_state.gamepad_removed_token); if (!SUCCEEDED(hr)) { - SDL_SetError("add_GamepadRemoved() failed: 0x%lx", hr); + SDL_SetError("add_GamepadRemoved() failed: 0x%" SDL_PRIxSLONG, hr); } } } @@ -1508,7 +1508,7 @@ static bool RAWINPUT_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_ WindowsGamingInputGamepadState *gamepad_state = ctx->wgi_slot; HRESULT hr = __x_ABI_CWindows_CGaming_CInput_CIGamepad_put_Vibration(gamepad_state->gamepad, ctx->vibration); if (!SUCCEEDED(hr)) { - return SDL_SetError("Setting vibration failed: 0x%lx", hr); + return SDL_SetError("Setting vibration failed: 0x%" SDL_PRIxSLONG, hr); } ctx->triggers_rumbling = (left_rumble > 0 || right_rumble > 0); return true; diff --git a/src/time/windows/SDL_systime.c b/src/time/windows/SDL_systime.c index a35ae7286a..e36ad01841 100644 --- a/src/time/windows/SDL_systime.c +++ b/src/time/windows/SDL_systime.c @@ -151,7 +151,7 @@ bool SDL_TimeToDateTime(SDL_Time ticks, SDL_DateTime *dt, bool localTime) } } - return SDL_SetError("SDL_DateTime conversion failed (%lu)", GetLastError()); + return SDL_SetError("SDL_DateTime conversion failed (%" SDL_PRIuULONG ")", GetLastError()); } #endif // SDL_TIME_WINDOWS diff --git a/src/video/directx/SDL_d3d12.h b/src/video/directx/SDL_d3d12.h index 2dfe672209..1d7a7e8070 100644 --- a/src/video/directx/SDL_d3d12.h +++ b/src/video/directx/SDL_d3d12.h @@ -37,8 +37,15 @@ #define WINAPI_PARTITION_GAMES 0 #endif // WINAPI_PARTITION_GAMES +#ifdef __CYGWIN__ + // generated header d3d12.h wants to see _WIN32 defined in order to believe it's targeting windows + #define _WIN32 1 +#endif #define COBJMACROS #include "d3d12.h" +#ifdef __CYGWIN__ + #undef _WIN32 +#endif #include #include diff --git a/src/video/windows/SDL_windowsrawinput.c b/src/video/windows/SDL_windowsrawinput.c index e9b4aad3d9..497e8007bc 100644 --- a/src/video/windows/SDL_windowsrawinput.c +++ b/src/video/windows/SDL_windowsrawinput.c @@ -78,7 +78,7 @@ static RawInputIterateResult IterateRawInputThread(void) } else if (wait_status == WAIT_INPUT) { return RINP_CONTINUE; } else { - SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Raw input thread exiting, unexpected wait result: %lu", wait_status); + SDL_LogWarn(SDL_LOG_CATEGORY_INPUT, "Raw input thread exiting, unexpected wait result: %" SDL_PRIuULONG, wait_status); return RINP_QUIT; } } diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 506fdc1ae5..bf9c394457 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -1771,16 +1771,16 @@ static STDMETHODIMP SDLDropTarget_DragEnter(SDLDropTarget *target, POINTL pt, DWORD *pdwEffect) { SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In DragEnter at %ld, %ld", pt.x, pt.y); + ". In DragEnter at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG, pt.x, pt.y); *pdwEffect = DROPEFFECT_COPY; POINT pnt = { pt.x, pt.y }; if (ScreenToClient(target->hwnd, &pnt)) { SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In DragEnter at %ld, %ld => window %u at %ld, %ld", pt.x, pt.y, target->window->id, pnt.x, pnt.y); + ". In DragEnter at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG " => window %u at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG, pt.x, pt.y, target->window->id, pnt.x, pnt.y); SDL_SendDropPosition(target->window, pnt.x, pnt.y); } else { SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In DragEnter at %ld, %ld => nil, nil", pt.x, pt.y); + ". In DragEnter at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG " => nil, nil", pt.x, pt.y); } return S_OK; } @@ -1790,16 +1790,16 @@ static STDMETHODIMP SDLDropTarget_DragOver(SDLDropTarget *target, POINTL pt, DWORD *pdwEffect) { SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In DragOver at %ld, %ld", pt.x, pt.y); + ". In DragOver at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG, pt.x, pt.y); *pdwEffect = DROPEFFECT_COPY; POINT pnt = { pt.x, pt.y }; if (ScreenToClient(target->hwnd, &pnt)) { SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In DragOver at %ld, %ld => window %u at %ld, %ld", pt.x, pt.y, target->window->id, pnt.x, pnt.y); + ". In DragOver at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG " => window %u at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG, pt.x, pt.y, target->window->id, pnt.x, pnt.y); SDL_SendDropPosition(target->window, pnt.x, pnt.y); } else { SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In DragOver at %ld, %ld => nil, nil", pt.x, pt.y); + ". In DragOver at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG " => nil, nil", pt.x, pt.y); } return S_OK; } @@ -1820,11 +1820,11 @@ static STDMETHODIMP SDLDropTarget_Drop(SDLDropTarget *target, POINT pnt = { pt.x, pt.y }; if (ScreenToClient(target->hwnd, &pnt)) { SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In Drop at %ld, %ld => window %u at %ld, %ld", pt.x, pt.y, target->window->id, pnt.x, pnt.y); + ". In Drop at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG " => window %u at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG, pt.x, pt.y, target->window->id, pnt.x, pnt.y); SDL_SendDropPosition(target->window, pnt.x, pnt.y); } else { SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In Drop at %ld, %ld => nil, nil", pt.x, pt.y); + ". In Drop at %" SDL_PRIdSLONG ", %" SDL_PRIdSLONG " => nil, nil", pt.x, pt.y); } { @@ -1832,7 +1832,7 @@ static STDMETHODIMP SDLDropTarget_Drop(SDLDropTarget *target, HRESULT hres; hres = pDataObject->lpVtbl->EnumFormatEtc(pDataObject, DATADIR_GET, &pEnumFormatEtc); SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In Drop for EnumFormatEtc, HRESULT is %08lx", hres); + ". In Drop for EnumFormatEtc, HRESULT is %08" SDL_PRIxSLONG, hres); if (hres == S_OK) { FORMATETC fetc; while (pEnumFormatEtc->lpVtbl->Next(pEnumFormatEtc, 1, &fetc, NULL) == S_OK) { @@ -1864,7 +1864,7 @@ static STDMETHODIMP SDLDropTarget_Drop(SDLDropTarget *target, STGMEDIUM med; HRESULT hres = pDataObject->lpVtbl->GetData(pDataObject, &fetc, &med); SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In Drop File for GetData, format %08x '%s', HRESULT is %08lx", + ". In Drop File for GetData, format %08x '%s', HRESULT is %08" SDL_PRIxSLONG, fetc.cfFormat, format_mime, hres); if (SUCCEEDED(hres)) { const size_t bsize = GlobalSize(med.hGlobal); @@ -1912,7 +1912,7 @@ static STDMETHODIMP SDLDropTarget_Drop(SDLDropTarget *target, STGMEDIUM med; HRESULT hres = pDataObject->lpVtbl->GetData(pDataObject, &fetc, &med); SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In Drop Text for GetData, format %08x '%s', HRESULT is %08lx", + ". In Drop Text for GetData, format %08x '%s', HRESULT is %08" SDL_PRIxSLONG, fetc.cfFormat, format_mime, hres); if (SUCCEEDED(hres)) { const size_t bsize = GlobalSize(med.hGlobal); @@ -1958,7 +1958,7 @@ static STDMETHODIMP SDLDropTarget_Drop(SDLDropTarget *target, STGMEDIUM med; HRESULT hres = pDataObject->lpVtbl->GetData(pDataObject, &fetc, &med); SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In Drop Text for GetData, format %08x '%s', HRESULT is %08lx", + ". In Drop Text for GetData, format %08x '%s', HRESULT is %08" SDL_PRIxSLONG, fetc.cfFormat, format_mime, hres); if (SUCCEEDED(hres)) { const size_t bsize = GlobalSize(med.hGlobal); @@ -2012,7 +2012,7 @@ static STDMETHODIMP SDLDropTarget_Drop(SDLDropTarget *target, STGMEDIUM med; HRESULT hres = pDataObject->lpVtbl->GetData(pDataObject, &fetc, &med); SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In Drop Text for GetData, format %08x '%s', HRESULT is %08lx", + ". In Drop Text for GetData, format %08x '%s', HRESULT is %08" SDL_PRIxSLONG, fetc.cfFormat, format_mime, hres); if (SUCCEEDED(hres)) { const size_t bsize = GlobalSize(med.hGlobal); @@ -2058,7 +2058,7 @@ static STDMETHODIMP SDLDropTarget_Drop(SDLDropTarget *target, STGMEDIUM med; HRESULT hres = pDataObject->lpVtbl->GetData(pDataObject, &fetc, &med); SDL_LogTrace(SDL_LOG_CATEGORY_INPUT, - ". In Drop File for GetData, format %08x '%s', HRESULT is %08lx", + ". In Drop File for GetData, format %08x '%s', HRESULT is %08" SDL_PRIxSLONG, fetc.cfFormat, format_mime, hres); if (SUCCEEDED(hres)) { const size_t bsize = GlobalSize(med.hGlobal); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 895f885b13..654ff18874 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -374,7 +374,7 @@ if(MACOS) testnativecocoa.m testnativex11.c ) -elseif(WINDOWS) +elseif(WINDOWS OR CYGWIN) add_sdl_test_executable(testnative BUILD_DEPENDENT NEEDS_RESOURCES TESTUTILS SOURCES testnative.c testnativew32.c) elseif(HAVE_X11 OR HAVE_WAYLAND) add_sdl_test_executable(testnative BUILD_DEPENDENT NEEDS_RESOURCES TESTUTILS SOURCES testnative.c) @@ -671,7 +671,7 @@ function(add_sdl_test TEST TARGET) COMMAND ${command} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) - if(WIN32 AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.27") + if((WIN32 OR CYGWIN) AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.27") set_property(TEST ${TEST} APPEND PROPERTY ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$") endif() if(NOT notrackmem) diff --git a/test/childprocess.c b/test/childprocess.c index 69a7cea2da..ccce2e8622 100644 --- a/test/childprocess.c +++ b/test/childprocess.c @@ -107,7 +107,7 @@ int main(int argc, char *argv[]) { if (print_arguments) { int print_i; -#ifdef SDL_PLATFORM_WINDOWS +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) /* reopen stdout as binary to prevent newline conversion */ _setmode(_fileno(stdout), _O_BINARY); #endif @@ -145,7 +145,7 @@ int main(int argc, char *argv[]) { continue; } -#ifdef SDL_PLATFORM_WINDOWS +#if defined(SDL_PLATFORM_WINDOWS) && !defined(SDL_PLATFORM_CYGWIN) if (strerror_s(error, sizeof(error), errno) != 0) { SDL_strlcpy(error, "Unknown error", sizeof(error)); } diff --git a/test/testautomation_stdlib.c b/test/testautomation_stdlib.c index 4d1c6ea5db..d3f5c54cd8 100644 --- a/test/testautomation_stdlib.c +++ b/test/testautomation_stdlib.c @@ -934,7 +934,9 @@ static int SDLCALL stdlib_sscanf(void *arg) #pragma GCC diagnostic pop #endif -#ifdef _WIN64 +#if defined(SDL_PLATFORM_CYGWIN) +#define SIZE_FORMAT "zu" +#elif defined(_WIN64) #define SIZE_FORMAT "I64u" #elif defined(SDL_PLATFORM_WIN32) #define SIZE_FORMAT "I32u"