Repository navigation
Closed
8 / 118 of 11 issues completedLabels
Description
Cygwin is a free and open-source Unix-like environment and command-line interface for Microsoft Windows. There is an on-going effort to support Cygwin in Python. I create this meta-issue to track other Cygwin sub-issues.
To install Cygwin on Windows and build CPython in Cygwin, you can use these commands:
- Download https://cygwin.com/setup-x86_64.exe
- Run setup-x86_64.exe : select
gcc-core,make,libffi-devel,libssl-develandzlib-develpackages (I also installedvim, my favorite text editor 😁). - Start Cygwin shell (icon on the desktop).
- Type:
git config --global core.autocrlf input-- I had issues with newlines in the./configurescript without that. - Run
git clone https://github.com/python/cpython/ --depth=1 - Type:
cd cpython - Type:
./configure --with-pydebug --cache-file=../configure.cache --without-mimalloc - Type:
make -j8
mimalloc is disabled because it fails at startup on Cygwin with:
$ PYTHONMALLOC=mimalloc ./python.exe -c pass
mimalloc: warning: cannot decommit OS memory (error: 22 (0x16), address: 0x20000430000, size: 0x1bd0000 bytes)
mimalloc: assertion failed: at "Objects/mimalloc/os.c":444, mi_os_decommit_ex
assertion: "err == 0"
Aborted
Linked PRs
- gh-149879: Fix test_pwd on Cygwin #149880
- gh-149879: Fix sys.orig_argv[0] on Cygwin: add ".exe" suffix #149885
- gh-149879: Set thread name max length on Cygwin #149890
- gh-149879: Fix test_signal on Cygwin #149896
- gh-149879: Fix test_tarfile on Cygwin #149897
- gh-149879: Don't import msvcrt in _pyio on Cygwin #149899
- gh-149879: Fix test_resource on Cygwin #149903
- gh-149879: Fix test_os on Cygwin #149910
- gh-149879: Fix test_socket on Cygwin #149913
- gh-149879: Fix multiprocessing tests on Cygwin #149999
- gh-149879: Fix multiprocessing tests on Cygwin #150031
- gh-149879: Fix test_tempfile on Cygwin #150081
- gh-149879: Fix test_c_stack_unwind on Cygwin #150084
- gh-149879: Fix test__locale on Cygwin #150248
- gh-149879: Fix test_c_locale_coercion on Cygwin #150250
- gh-149879: Fix test_capi on Cygwin #150252
- gh-149879: Fix test_termios and test_ioctl on Cygwin #150412
- gh-149879: Fix test_concurrent_futures on Cygwin #150415
- gh-149879: Fix test_asyncio on Cygwin #150416
- gh-149879: Fix test_httpservers on Cygwin #150417
- gh-149879: Skip test_venv on Cygwin #150418
- gh-149879: Fix test_ssl on Cygwin #150419
- gh-149879: Fix test_venv on Cygwin #150426
- gh-149879: Fix test_ftplib on Cygwin #150431
- gh-149879: Fix test_math on Cygwin #150432
- gh-149879: Fix test_strptime on Cygwin #150438
- gh-149879: Fix multiprocessing resource tracker tests on Cygwin #150440
- gh-149879: Fix test_embed on Cygwin #150441
- gh-149879: Fix test_venv on Cygwin #150483
- gh-149879: Fix test_grp on Cygwin #150495
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Activity
vstinner commentedon May 15, 2026
Right now, around 60 tests are failing. It's too early to consider adding a buildbot.
gh-149879: Fix sys.orig_argv[0] on Cygwin: add ".exe" suffix (#149885)
gh-149879: Fix test_pwd on Cygwin (#149880)
zware commentedon May 15, 2026
As long as the tests can finish cleanly even if failing, I think an 'unstable' worker could be added any time.
gh-149879: Set thread name max length on Cygwin (#149890)
gh-149879: Fix test_signal on Cygwin (#149896)
gh-149879: Fix test_tarfile on Cygwin (#149897)
gh-149879: Don't import msvcrt in _pyio on Cygwin (#149899)
vstinner commentedon May 15, 2026
With the latest batch of fixes: 47 tests failed on 505.
pythongh-149879: Fix test_resource on Cygwin
vstinner commentedon May 15, 2026
cc @carlo-bramini
gh-149879: Fix test_resource on Cygwin (#149903)
gh-149879: Fix test_os on Cygwin (#149910)
pythongh-149879: Fix test_socket on Cygwin
gh-149879: Fix test_socket on Cygwin (#149913)
carlo-bramini commentedon May 17, 2026
In the first post, what about adding also
libexpat-develpackage and adding--with-system-expatoption to configure script?StanFromIreland commentedon May 17, 2026
We already bundle latest expat? In general those options are for distributors, not for development.
embray commentedon May 18, 2026
@vstinner Nice to see you working on this. I was trying quite a number of years ago to get various Cygwin patches to cpython upstream, and was maintaining a Cygwin builtbot for a while. As is typical the job that was funding that work ran out and I gradually drifted away from it before the effort was complete.
Nevertheless, happy to provide any assistance to this if the need arises.
https://github.com/embray/PyCygwin might also be of use; not sure. It's written using Cython so probably not directly, but has some useful tools for handling path conversions (esp for #90907)
vstinner commentedon May 18, 2026
Recent Cygwin changes:
libpythonDLL was renamed tocygpythonDLL (ex:cygpython3.16d.dll)importlib._bootstrap_external.EXTENSION_SUFFIXES:'.cpython-316d.dll'was added to['.cpython-316d.dll', '.dll']sys.orig_argv[0]was modified to include.exesuffix. For example,/python.exe -c 'import sys; print(repr(sys.orig_argv[0]))'displays'./python.exe'._PYTHREAD_NAME_MAXLENmacro to16(bytes): needed to fix_thread.set_name().test_os.test_os:timerfd_gettime_ns()behaves differently on Cygwin, I had to adapt the test. It's maybe a bug in Cygwin?socket: I disabledSCM_RIGHTS,sendmsg(),recvmsg(), andsethostname()(it doesn't report failures) features. It seems like ancdata are not supported in Cygwin.Cygwin status:
msvcrtextension is not built: Cygwin doesn't provide<conio.h>nor<sys/locking.h>header files._winapiextension is not built.gh-149879: Fix multiprocessing tests on Cygwin (#150031)
vstinner commentedon May 18, 2026
I think that we have to put some limits in Cygwin support: we cannot support the full Windows API (in C code).
So it's a good thing that
MS_WINDOWSmacro is false in C code, and thatsys.platform == 'win32'is false in Python. Cygwin uses the "other" code path (Unix-like).Supporting
forkserverstart method inmultiprocessingrequires the_winapiextension and_multiprocessing.closesocketfunction.Supporting
_multiprocessing.closesocketfunction in Cygwin seems to be complicated:#include <winsock2.h>introduces a conflict on theselect()function already defined differently by<sys/select.h>. The<sys/select.h>header is included by<sys/types.h>which is included by<Python.h>.For
multiprocessing, IMO it's acceptable to only support "start" and "fork" start methods.Using the Windows code path in
subprocessrequiresmsvcrtand_winapi. But buildingmsvcrtextension fails on Cygwin because of missing<conio.h>nor<sys/locking.h>header files. Sosubprocessis implemented withfork+execusing_posixsubprocessextension. It just works on Cygwin!carlo-bramini commentedon May 19, 2026
If I can say my opinion, some fixed positions must be taken about the support for Cygwin.
When running an application on Cygwin, the operating system is not Windows.
The operating system IS Cygwin.
It is also true that Cygwin can use Windows APIs.
It supports some customized headers that can be included and used together with POSIX functions, but they must be used with some care.
For example, Cygwin can get advantages by using built-in audio frameworks like Winmm/DirectSound/Wasapi, instead of using thirdy party libraries.
However, as general rule, an user should forget that the heart behind Cygwin is Windows.
Instead, he must think like using a true UNIX platform.
embray commentedon May 19, 2026
I agree. I remember trying to fix that some years ago and throwing my hands up. It's not that it's impossible, strictly speaking. I got some patches into Cygwin back then to better support some socket edge cases though I don't recall the details. But someone would have to be very specifically motivated -- I think as a first pass it's OK to mark it as not supported.
vstinner commentedon May 19, 2026
The Cygwin python39 package has many interesting patches: https://cygwin.com/cgit/cygwin-packages/python39/tree/
(Patches on distutils and setup.py are outdated, since both have been removed.)
There is an interesting
3.6.12-socketmodule.patch:Sadly, even if I apply this patch, sending file descriptors still fail: ancdata is always empty on Cygwin. I don't know if
ancdatais supposed to be supported or not on Cygwin. I disabled sendmsg()/recvmsg() in thesocketmodule on Cygwin.I wrote this test programs to test send_fds() / recv_fds().
client.py:
server.py:
On Cygwin, the server gets an empty list of file descriptors (
fds), andancdatais empty inrecv_fds().vstinner commentedon May 19, 2026
Rust has a
Socket::set_no_peercredmethod forsetsockopt(s->sock_fd, SOL_SOCKET, SO_PEERCRED, 0, 0):gh-149879: Fix test_tempfile on Cygwin (#150081)
gh-149879: Fix test_c_locale_coercion on Cygwin (#150250)
pythongh-149879: Fix test_c_locale_coercion on Cygwin (python#150250)
pythongh-149879: Fix test_c_locale_coercion on Cygwin (python#150250)
pythongh-149879: Fix test__locale on Cygwin
gh-149879: Fix test__locale on Cygwin (#150248)
gh-149879: Fix test_c_stack_unwind on Cygwin (#150084)
gh-149879: Fix test_capi on Cygwin (#150252)
vstinner commentedon May 25, 2026
Update: 29 tests fail.
gh-149879: Fix test_termios and test_ioctl on Cygwin (#150412)
gh-149879: Fix test_httpservers on Cygwin (#150417)
gh-149879: Fix test_ssl on Cygwin (#150419)
gh-149879: Fix test_asyncio on Cygwin (#150416)
vstinner commentedon May 25, 2026
To fix
test_asyncioon Cygwin, I disabled tests on UNIX sockets and I modified the subprocess implementation to use a socket for stdin: see commit be715d7.gh-149879: Fix test_concurrent_futures on Cygwin (#150415)
gh-149879: Fix test_ftplib on Cygwin (#150431)
pythongh-149879: Fix test_strptime on Cygwin
pythongh-149879: Fix multiprocessing resource tracker tests on Cygwin
gh-149879: Fix multiprocessing resource tracker tests on Cygwin (#150440
gh-149879: Fix test_strptime on Cygwin (#150438)
gh-149879: Fix test_math and test_statistics on Cygwin (#150432)
gh-149879: Fix test_venv on Cygwin (#150483)
gh-149879: Fix test_embed on Cygwin (#150441)
vstinner commentedon May 26, 2026
Update: 8 tests are failing.
The remaining failures are the most complex ones to fix. I'm not sure if it's worth it to fix the last issues.
test_grp also fails, but I have a pending fix: PR gh-150495.
There are also some race conditions.
The following test logs warnings:
And there is a Cygwin bug:
*** fatal error in forked process - failed to create new win32 semaphore, currentvalue 4294967295, Win32 error 87.vstinner commentedon May 26, 2026
Recent changes:
vstinner commentedon May 26, 2026
I created Enhance Cygwin support topic on discusss.python.org to discuss what should be the next steps for the Cygwin support.
gh-149879: Fix test_grp on Cygwin (#150495)
carlo-bramini commentedon May 28, 2026
About:
On Cygwin, some of the test on the mathematical functions fail.
You can see this error on screen:
followed by a number of lines describing the failed tests.
Actually, the cause of all these errors is inside the implementation of the
fma()math function.This is an "hystorical" bug of Cygwin because NEWLIB provides a very minimalist implementation of this function and, for this reason, it doesn't guarantee the precision and it doesn't even provides a software replacement for this task:
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=newlib/libm/common/s_fma.c
I have seen that there is a macro called
UNRELIABLE_FMAinsideModules\mathmodule.c.I tried to activate this macro with a quick hack and the number of failures decreased from 33 to 20.
As you can see, it is still failing elsewhere, the above macro fixed some but not all the issues.
This happens because the
fma()is used also for implementing other math functions provided by LIBM.Affected functions are:
fma()pow()log()log2()So, there is not much that is it could be done here, on the source code of Python.
However, besides the obvious solution of fixing that function inside LIBM, a possible way for fixing this malfunction is using a function from another C library.
At the end, Cygwin still runs on top of Windows.
And Windows has its own DLL libraries for providing C functions, including the math ones.
The
fma()is not provided by MSVCRT, but it could be get from UCRT, as well as all other affected math functions.The UCRT is available on all versions of Windows supported by Cygwin and it can be made available even on Windows XP by installing the Microsoft Visual C++ Redistributable.
So, I did a quick patch for testing and I imported those library functions from UCRT.
As result, all mathematical tests have been executed successfully.
See here my change:
As you can see, it is just a draft and there are surely better ways for optimizing it, perhaps by loading the pointer to functions only once and falling back to the ones provided by LIBM if they are not found for any reason, or by adding an additional
crt_errno()if an error condition needs to be detected (which is not needed at the time of writing).After running the test, this is the result on screen:
However... in my personal opinion, it would be better to fix LIBM, which would make the problem solved at the roots and it would be nice to have a direct support to FMA3 and FMA4 and a software implementation as fallback.
In that case, it must be also accepted the fact that older versions of Cygwin won't be able to execute the testsuite successfully, but this is quite obvious.
I'm providing this report as a reference for the
Enhance Cygwin supporttopic.EDIT: in my opinion,
hypot()function is fine.The tests were failing because the function to fail was
sqrt()since it is a subset of thepow()function.vstinner commentedon May 28, 2026
Hum. IMO this math patch is a little too big. Also calling GetModuleHandleA() and GetProcAddress() at each function call is inefficient. I suggest you reporting the issue to newlib bug tracker instead.
vstinner commentedon May 28, 2026
@carlo-bramini: So I'm now curious. How are you using Python in Cygwin? Do you use Python to build other packages? Or for something else? You may share your experience at https://discuss.python.org/t/enhance-cygwin-support/107537.
vstinner commentedon Jun 18, 2026
I'm done with Cygwin enhancements. I summarized recent changes on https://discuss.python.org/t/enhance-cygwin-support/107537. I close the issue. For further work, you can open new issues.