Skip to content

fix building on CYGWIN#15457

Closed
TrueCat17 wants to merge 9 commits into
libsdl-org:mainfrom
TrueCat17:main
Closed

fix building on CYGWIN#15457
TrueCat17 wants to merge 9 commits into
libsdl-org:mainfrom
TrueCat17:main

Conversation

@TrueCat17

@TrueCat17 TrueCat17 commented Apr 25, 2026

Copy link
Copy Markdown
Contributor
  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources, including code generated by a Large Language Model ("AI").

Existing Issue(s)

Fix for issue #15360

Warning: the building will only work with Software and OpenGL renderers, others (including DirectX) have not been tested
Also I only tested building a static library, not a dynamic one

@slouken

slouken commented Apr 25, 2026

Copy link
Copy Markdown
Collaborator

Building SDL with the cygwin UNIX layer is not officially supported. If you'd like it to be, please add a cygwin build configuration to the github actions and verify that all the automated tests pass.

@slouken slouken added this to the 3.x milestone Apr 25, 2026
@TrueCat17

Copy link
Copy Markdown
Contributor Author

Building SDL with the cygwin UNIX layer is not officially supported

Hm... then what about unofficial support (currently)?
Now the word cygwin appears in SDL many times, so it seems strange to me to talk about complete lack of support
Will accepting this PR make anything worse?
It seems logical to me to first fix the building on the cygwin platform, and THEN add the building to CI

@slouken

slouken commented Apr 25, 2026

Copy link
Copy Markdown
Collaborator

Building SDL with the cygwin UNIX layer is not officially supported

Hm... then what about unofficial support (currently)? Now the word cygwin appears in SDL many times, so it seems strange to me to talk about complete lack of support Will accepting this PR make anything worse? It seems logical to me to first fix the building on the cygwin platform, and THEN add the building to CI

Yes, fixing the building is great, but fixing functionality is even better. I know @madebr had a PR a while back to add cygwin CI, maybe he can contribute it to this PR?

@TrueCat17

Copy link
Copy Markdown
Contributor Author

It seems to me that several months could easily pass before the build in CI is established, so I’ll probably once again suggest accepting PR as is now

@madebr

madebr commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Let me know if I screwed something up.

@slouken

slouken commented Apr 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks @madebr!

CI is failing, FYI

@madebr

madebr commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

CI is failing, FYI

Yup, I assume TrueCat17 is in a better position to fix these errors as he probably has a local development setup.

@TrueCat17

Copy link
Copy Markdown
Contributor Author

I did not include the hidapi build because I did not use this subsystem
I can, of course, spend time fixing build errors, but I'm not sure there's any point in doing so since I don't have the knowledge (and perhaps the hardware, if needed) to check all these extra things
So, I would just add the -DSDL_HIDAPI=0 option when configuring cmake

@madebr

madebr commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Please look into the build failure. It looks very simple.
src/hidapi/windows/hid.c contains a cygwin-specific _wcsdup macro which apparently is not needed anymore today.

@sezero

sezero commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Maybe something like this for _wcsdup?

--- a/src/hidapi/windows/hid.c
+++ b/src/hidapi/windows/hid.c
@@ -48 +48 @@
-#ifdef __CYGWIN__
+#if defined(__CYGWIN__) && !defined(HIDAPI_USING_SDL_RUNTIME)

Don't know what's the thing about SDL_toupper. If only we had the
preprocessed source...

@TrueCat17

Copy link
Copy Markdown
Contributor Author

It seems like everything has been fixed, but everything only works with disabled DirectX, the joystick subsystem (which depends on DirectX) and a few other things
I'll post a commit in a while

I also remind you that just because something has been compiled and even linked, this does not mean at all that it will work
I have neither the desire nor the ability to test very many parts of SDL that are not needed for my tasks

@TrueCat17

TrueCat17 commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

I think I did
Although I am not an expert in creating PR
Before a new push I had to do a git pull, and it could not be done without the --rebase (rebase) or --no-rebase (merge) options - I chose the latter, but not that I was confident in my actions
If I understand correctly, now just need confirmation to pass the tests

@TrueCat17

Copy link
Copy Markdown
Contributor Author

I'm using cygwin for x86 architecture, not x86_64, so everything compiles fine for me
I believe that when outputting HRESULT, it can be cast to int, because in x86 HRESULT = long, despite the fact that long is equal in size to int, and in x86_64 HRESULT = int directly, as a result, in any case, the type will not be cut off, and everything should be in order

@TrueCat17

Copy link
Copy Markdown
Contributor Author

@madebr

I think it will be easier for you to solve the remaining problems related specifically to cygwin-x86_64 yourself, since with my cygwin-x86 I still solve them by viewing build errors in github-actions, but at the same time I also spend a lot of time waiting for confirmation to run tests

Maybe, at least until the build completes successfully, it would be logical to turn off -Werror in order to see all the warnings at once, and not in small parts

@sezero

sezero commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Can you guys look at / test my branch: https://github.com/sezero/SDL/tree/cygwin

Library build succeeds with everything possible enabled. Tests builds fail due to some python error:
https://github.com/sezero/SDL/actions/runs/25175436654/job/73806509782

Details
[316/925] /bin/sh test/CMakeFiles/speaker.png-25e304e.sh e4dd920df8e03716
[317/925] /bin/sh test/CMakeFiles/sword.wav-a1322ac.sh f2c7677d42a02489
[318/925] /bin/sh test/CMakeFiles/testyuv.png-7437162.sh b27bfc14ba496345
[319/925] /bin/sh test/CMakeFiles/trashcan.png-0b042f8.sh d6b3a7bcfcbb7b60
[320/925] /bin/sh test/CMakeFiles/unifont-15.1.05.hex-cb4d4f2.sh b290fe94741fa908
[321/925] /bin/sh test/CMakeFiles/utf8.txt-4930ff6.sh 5b3b8017522b01d0
[322/925] /bin/sh test/CMakeFiles/gamepad_axis.h-5688f34.sh 3e27bfc9ae38bc58
FAILED: [code=2] test/gamepad_axis.h /cygdrive/d/a/SDL/SDL/build/test/gamepad_axis.h 
/bin/sh test/CMakeFiles/gamepad_axis.h-5688f34.sh 3e27bfc9ae38bc58
C:\hostedtoolcache\windows\Python\3.12.10\x64\python3.exe: can't open file 'D:\\cygdrive\\d\\a\\SDL\\SDL\\cmake\\xxd.py': [Errno 2] No such file or directory
[323/925] /bin/sh test/CMakeFiles/gamepad_axis_arrow.h-c163fed.sh 5c8ee46a30c42211
FAILED: [code=2] test/gamepad_axis_arrow.h /cygdrive/d/a/SDL/SDL/build/test/gamepad_axis_arrow.h 
/bin/sh test/CMakeFiles/gamepad_axis_arrow.h-c163fed.sh 5c8ee46a30c42211
C:\hostedtoolcache\windows\Python\3.12.10\x64\python3.exe: can't open file 'D:\\cygdrive\\d\\a\\SDL\\SDL\\cmake\\xxd.py': [Errno 2] No such file or directory
[324/925] /bin/sh test/CMakeFiles/gamepad_back.h-61a31f8.sh bb655b2208125752
FAILED: [code=2] test/gamepad_back.h /cygdrive/d/a/SDL/SDL/build/test/gamepad_back.h 
/bin/sh test/CMakeFiles/gamepad_back.h-61a31f8.sh bb655b2208125752
C:\hostedtoolcache\windows\Python\3.12.10\x64\python3.exe: can't open file 'D:\\cygdrive\\d\\a\\SDL\\SDL\\cmake\\xxd.py': [Errno 2] No such file or directory
[325/925] /bin/sh test/CMakeFiles/gamepad_battery.h-38ab860.sh 9095d1f202e56e74
FAILED: [code=2] test/gamepad_battery.h /cygdrive/d/a/SDL/SDL/build/test/gamepad_battery.h 
/bin/sh test/CMakeFiles/gamepad_battery.h-38ab860.sh 9095d1f202e56e74
C:\hostedtoolcache\windows\Python\3.12.10\x64\python3.exe: can't open file 'D:\\cygdrive\\d\\a\\SDL\\SDL\\cmake\\xxd.py': [Errno 2] No such file or directory

@TrueCat17

Copy link
Copy Markdown
Contributor Author

D:\cygdrive\d\a\SDL\SDL\cmake\xxd.py

This script never runs for me at all (at least I didn’t find one in a text search in the build folder)
Although the tests all seem to be compiled and linked

The path looks very strange
I tried running python3 C:\\cygwin\\c\\q.py - same error
But python3 /cygwin/c/q.py - ok

Somewhere there is a “fixing” (“canonization”?) of the path and it ruins everything
The xxd.py script itself is called in function files2headers in the SDL/test/CMakeLists.txt:266
This function is called 3 times just below
Maybe need to look somewhere from here, but maybe not

By the way, the difference in behavior may also be due to the fact that I use make and not ninja

Comment thread .github/workflows/create-test-plan.py
@sezero

sezero commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Can you guys look at / test my branch: https://github.com/sezero/SDL/tree/cygwin

Apart from the changes in there, there seems to be more work to be done:

The following sources have SDL_PLATFORM_WIN32 special cases:
they must be revised for possible additional SDL_PLATFORM_CYGWIN
handling. ( SDL_PLATFORM_WINDOWS, on the other hand, already
includes SDL_PLATFORM_CYGWIN.) -- Namely:

  • src/SDL_log.c
  • src/core/windows/SDL_windows.h
  • src/main/SDL_runapp.c
  • src/main/windows/SDL_sysmain_runapp.c
  • src/stdlib/SDL_getenv.c (???)
  • src/stdlib/SDL_iconv.c
  • src/test/SDL_test_memory.c (use win32 dbghelp or libunwind ?)

@sezero

sezero commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Can you guys look at / test my branch: https://github.com/sezero/SDL/tree/cygwin
[...]
Tests builds fail due to some python error:

After adding python and perl installs to CI/cygwin, build fully succeeds.

However, install/packaging fails because build seems to generate cygSDL3-0.dll
but cmake-install looks for SDL3.dll -- @madebr: your thing.

@sezero

sezero commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

After applying madebr's lat patch: success.

But: 25 tests fail out of 25 :(
https://github.com/sezero/SDL/actions/runs/25188142275/job/73851095027

@madebr

madebr commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

But: 25 tests fail out of 25 :( https://github.com/sezero/SDL/actions/runs/25188142275/job/73851095027

It looks like the exes cannot find the DLL.
What environment variables need to be set on cygwin to find the dll? PATH as on Windows?

@sezero

sezero commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

It looks like the exes cannot find the DLL. What environment variables need to be set on cygwin to find the dll? PATH as on Windows?

/cc @TrueCat17

@sezero

sezero commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

I've done all ı could for now at https://github.com/sezero/SDL/tree/cygwin
Important notes to further it still stand: #15457 (comment)

@sezero

sezero commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

P.S.: Last (as of this writing) build artifact downloadable from https://github.com/sezero/SDL/actions/runs/25188142275

@TrueCat17

Copy link
Copy Markdown
Contributor Author

To understand what the problem is, we need to look at the specified file:
Output from these tests are in: /cygdrive/d/a/SDL/SDL/build/Testing/Temporary/LastTest.log
But I don't know how to do it

Guess of @madebr is good, but it's better to know for sure rather than guess
For example, the problem may be that “inside” ~SDL3.dll the name specified != the file name, which is why linking occurs normally (since the library name is specified manually), and when launched, the name specified inside that library is taken
So it's better to somehow get that file
(Make it a build artifact? I really don’t understand github-actions, and generally use a static build)

My cygwin, when asked to echo $PATH, also returns /usr/bin (some kind of implicit link to C:/cygwin/bin), which contains cygwin1.dll
I tried running some tests from the cygwin shell on my system and they were fine
The standard cmd on echo %PATH% does not produce the specified path, so it seems to me that cygwin adds this path automatically (in the /etc/profile file)

@sezero

sezero commented May 2, 2026

Copy link
Copy Markdown
Contributor

One minor edit to tests/ cmake'ry for PATH, and tests now run.

Failures, though:

	  2 - testautomation (Failed)
	 15 - testsem (Failed)
	 18 - testyuv (Timeout)
	 23 - testprocess (Failed)
	 24 - testautomation-no-simd (Failed)

https://github.com/sezero/SDL/actions/runs/25257709310/job/74059843233

testsem, testprocess: Some command-line failure???
testautomation, testautomation-no-simd: Couldn't open audio: No default audio device available ??

@TrueCat17

TrueCat17 commented May 2, 2026

Copy link
Copy Markdown
Contributor Author

testautomation, testautomation-no-simd: Couldn't open audio: No default audio device available ??

“No audio device” - a typical situation for a virtual machine

18 - testyuv (Timeout)

As expected, because this is a “manual” test for monitoring the rendering result in different modes, as far as I understand

@stahta01

stahta01 commented May 3, 2026

Copy link
Copy Markdown
Contributor
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4060,7 +4060,7 @@ if(SDL_SHARED)
       SOVERSION "${SDL_SO_VERSION_MAJOR}"
     )
   else()
-    if(WINDOWS OR CYGWIN)
+    if(WINDOWS)
       set_target_properties(SDL3-shared PROPERTIES
         PREFIX ""
       )

Fix for a code error it likely has no effect
I am trying to build on this PR and sezero cygwin branch to get MSys2 Cygwin like environment to build.
It now builds, no idea if it works.

Tim S.

@sezero

sezero commented May 3, 2026

Copy link
Copy Markdown
Contributor
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4060,7 +4060,7 @@ if(SDL_SHARED)
       SOVERSION "${SDL_SO_VERSION_MAJOR}"
     )
   else()
-    if(WINDOWS OR CYGWIN)
+    if(WINDOWS)
       set_target_properties(SDL3-shared PROPERTIES
         PREFIX ""
       )

Fix for a code error it likely has no effect I am trying to build on this PR and sezero cygwin branch to get MSys2 Cygwin like environment to build. It now builds, no idea if it works.

Tim S.

/cc @madebr @TrueCat17

@madebr

madebr commented May 3, 2026

Copy link
Copy Markdown
Contributor

testautomation, testautomation-no-simd: Couldn't open audio: No default audio device available ??

“No audio device” - a typical situation for a virtual machine

CTest runs all tests with dummy audio and video drivers.
So the tests should finish just fine with these dummy drivers.
The tests finish for all other desktop platforms, so there's no reason to make an exception for cygwin.

18 - testyuv (Timeout)

As expected, because this is a “manual” test for monitoring the rendering result in different modes, as far as I understand

No, testyuv is run as testyuv --automated --trackmem which does not require any "manual intervention".

@madebr

madebr commented May 3, 2026

Copy link
Copy Markdown
Contributor
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4060,7 +4060,7 @@ if(SDL_SHARED)
       SOVERSION "${SDL_SO_VERSION_MAJOR}"
     )
   else()
-    if(WINDOWS OR CYGWIN)
+    if(WINDOWS)
       set_target_properties(SDL3-shared PROPERTIES
         PREFIX ""
       )

Fix for a code error it likely has no effect I am trying to build on this PR and sezero cygwin branch to get MSys2 Cygwin like environment to build. It now builds, no idea if it works.
Tim S.

/cc @madebr @TrueCat17

I think naming the dll cygSDL3.dll is fine. No need for it to be libcygSDL3.dll and have a bigger naming difference with "normal SDL3.dll".

@stahta01

stahta01 commented May 3, 2026

Copy link
Copy Markdown
Contributor
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4060,7 +4060,7 @@ if(SDL_SHARED)
       SOVERSION "${SDL_SO_VERSION_MAJOR}"
     )
   else()
-    if(WINDOWS OR CYGWIN)
+    if(WINDOWS)
       set_target_properties(SDL3-shared PROPERTIES
         PREFIX ""
       )

Fix for a code error it likely has no effect I am trying to build on this PR and sezero cygwin branch to get MSys2 Cygwin like environment to build. It now builds, no idea if it works.
Tim S.

/cc @madebr @TrueCat17

I think naming the dll cygSDL3.dll is fine. No need for it to be libcygSDL3.dll and have a bigger naming difference with "normal SDL3.dll".

The does nothing because it never gets there the if branch above is taken because CYGWIN has UNIX true via cmake command.

Tim S.

@stahta01

stahta01 commented May 3, 2026

Copy link
Copy Markdown
Contributor
--- a/src/video/directx/SDL_d3d12.h
+++ b/src/video/directx/SDL_d3d12.h
@@ -37,8 +37,14 @@
 #define WINAPI_PARTITION_GAMES 0
 #endif // WINAPI_PARTITION_GAMES
 
+#if defined(SDL_PLATFORM_WIN32) && (defined(SDL_PLATFORM_CYGWIN) || defined(SDL_PLATFORM_MSYS))
+  #define _WIN32 1
+#endif
 #define COBJMACROS
 #include "d3d12.h"
+#if defined(SDL_PLATFORM_WIN32) && (defined(SDL_PLATFORM_CYGWIN) || defined(SDL_PLATFORM_MSYS))
+  #undef _WIN32
+#endif
 #include <dxgi1_6.h>
 #include <dxgidebug.h>
 
-- 

sezero edited d3d12.h about 200 places to get more items to build. The above patch got the building to work without editing that generated header.

stahta01 added a commit to stahta01/SDL that referenced this pull request May 4, 2026
Some ideas are likely from PR 15457 and sezero cygwin branch
libsdl-org#15457
https://github.com/sezero/SDL/tree/cygwin

Co-authored-by: TrueCat17 <truecat17@gmail.com>
Co-authored-by: Anonymous Maarten <anonymous.maarten@gmail.com>
Co-authored-by: Ozkan Sezer <sezeroz@gmail.com>
@TrueCat17

Copy link
Copy Markdown
Contributor Author

Btw, the if(UNIX) condition on line 1879 is also suspicious because it seems like a duplication to me (with result = always true)

@sezero

sezero commented May 5, 2026

Copy link
Copy Markdown
Contributor

Here is the latest version of my patch, against current main branch: 0001-CYGWIN-support.patch
It can be applied to a branch using git am, its commit log has TODO notes.

Here is the CI job log for it: cygwin-ci-job-log.txt

I deleted my own branch: Won't be messing with cygwin any further.

@stahta01

stahta01 commented May 9, 2026

Copy link
Copy Markdown
Contributor

I got CYGWIN CI tests to pass; but it failed on a later step of verify sdl3.pc.
My Cygwin CI branch

Edit: My branch is highly edited from this PR and doing the changes described below could fix the PR without the later failure.

Edit2: For my MSYS branch it just seems to hide the failure for tests 2,23,24 and maybe others I did not see when I downloaded the log files.

The comment of the commit that fixed it; no idea if it is a good fix or not, I started this work to learn a little on how to do CI.

   ci: Add gdb and perl packages and

    set job.clang_tidy to False
    Also, add "-DSDLTEST_GDB=ON"

I am now going to be removing changes to see what is really needed for CI to pass.

Tim S.

@stahta01 stahta01 mentioned this pull request May 12, 2026
1 task
@sezero

sezero commented May 16, 2026

Copy link
Copy Markdown
Contributor

This is obsolete since #15566 has been merged.

@sezero sezero closed this May 16, 2026
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.

5 participants