From 22061578c5e17c58d4f18716ddc17d8916ebb3b1 Mon Sep 17 00:00:00 2001 From: Masayuki Yamamoto Date: Sat, 28 Oct 2017 00:18:40 +0900 Subject: [PATCH 1/4] bpo-4032: Cygwin: Add .dll.a to UnixCCompiler for searching libraries Allow the UnixCCompiler.find_library_file to correctly find DLL import libs (.dll.a). --- Lib/distutils/ccompiler.py | 7 ++++--- Lib/distutils/unixccompiler.py | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Lib/distutils/ccompiler.py b/Lib/distutils/ccompiler.py index 1a411ed1113224..16bc0771509e63 100644 --- a/Lib/distutils/ccompiler.py +++ b/Lib/distutils/ccompiler.py @@ -875,9 +875,10 @@ def executable_filename(self, basename, strip_dir=0, output_dir=''): def library_filename(self, libname, lib_type='static', # or 'shared' strip_dir=0, output_dir=''): assert output_dir is not None - if lib_type not in ("static", "shared", "dylib", "xcode_stub"): - raise ValueError( - "'lib_type' must be \"static\", \"shared\", \"dylib\", or \"xcode_stub\"") + if lib_type not in ("static", "shared", "dylib", "xcode_stub", + "implib"): + raise ValueError("'lib_type' must be \"static\", \"shared\", " + "\"dylib\", \"xcode_stub\", or \"implib\"") fmt = getattr(self, lib_type + "_lib_format") ext = getattr(self, lib_type + "_lib_extension") diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py index d10a78da311405..b015eeb609a725 100644 --- a/Lib/distutils/unixccompiler.py +++ b/Lib/distutils/unixccompiler.py @@ -77,8 +77,9 @@ class UnixCCompiler(CCompiler): shared_lib_extension = ".so" dylib_lib_extension = ".dylib" xcode_stub_lib_extension = ".tbd" + implib_lib_extension = ".dll.a" static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s" - xcode_stub_lib_format = dylib_lib_format + implib_lib_format = xcode_stub_lib_format = dylib_lib_format if sys.platform == "cygwin": exe_extension = ".exe" @@ -266,6 +267,7 @@ def find_library_file(self, dirs, lib, debug=0): shared_f = self.library_filename(lib, lib_type='shared') dylib_f = self.library_filename(lib, lib_type='dylib') xcode_stub_f = self.library_filename(lib, lib_type='xcode_stub') + implib_f = self.library_filename(lib, lib_type='implib') static_f = self.library_filename(lib, lib_type='static') if sys.platform == 'darwin': @@ -301,6 +303,7 @@ def find_library_file(self, dirs, lib, debug=0): dylib = os.path.join(dir, dylib_f) static = os.path.join(dir, static_f) xcode_stub = os.path.join(dir, xcode_stub_f) + implib = os.path.join(dir, implib_f) if sys.platform == 'darwin' and ( dir.startswith('/System/') or ( @@ -310,6 +313,7 @@ def find_library_file(self, dirs, lib, debug=0): dylib = os.path.join(sysroot, dir[1:], dylib_f) static = os.path.join(sysroot, dir[1:], static_f) xcode_stub = os.path.join(sysroot, dir[1:], xcode_stub_f) + implib = os.path.join(sysroot, dir[1:], implib_f) # We're second-guessing the linker here, with not much hard # data to go on: GCC seems to prefer the shared library, so I'm @@ -319,6 +323,8 @@ def find_library_file(self, dirs, lib, debug=0): return dylib elif os.path.exists(xcode_stub): return xcode_stub + elif os.path.exists(implib): + return implib elif os.path.exists(shared): return shared elif os.path.exists(static): From b104fc696694832c9b238776a6532dfa67eaf93c Mon Sep 17 00:00:00 2001 From: Masayuki Yamamoto Date: Sat, 28 Oct 2017 00:57:08 +0900 Subject: [PATCH 2/4] bpo-4032: remove blank lines --- Lib/distutils/unixccompiler.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/Lib/distutils/unixccompiler.py b/Lib/distutils/unixccompiler.py index b015eeb609a725..024287c82f76b9 100644 --- a/Lib/distutils/unixccompiler.py +++ b/Lib/distutils/unixccompiler.py @@ -296,8 +296,6 @@ def find_library_file(self, dirs, lib, debug=0): else: sysroot = m.group(1) - - for dir in dirs: shared = os.path.join(dir, shared_f) dylib = os.path.join(dir, dylib_f) From d3618740515c3bfed8b5336675699dd332323894 Mon Sep 17 00:00:00 2001 From: Masayuki Yamamoto Date: Sat, 28 Oct 2017 01:08:01 +0900 Subject: [PATCH 3/4] bpo-4032: add a news file --- .../NEWS.d/next/Library/2017-10-28-01-07-44.bpo-4032.RvZFlS.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2017-10-28-01-07-44.bpo-4032.RvZFlS.rst diff --git a/Misc/NEWS.d/next/Library/2017-10-28-01-07-44.bpo-4032.RvZFlS.rst b/Misc/NEWS.d/next/Library/2017-10-28-01-07-44.bpo-4032.RvZFlS.rst new file mode 100644 index 00000000000000..81fe8ad9393134 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-10-28-01-07-44.bpo-4032.RvZFlS.rst @@ -0,0 +1,2 @@ +Add .dll.a to UnixCCompiler to allow the UnixCCompiler.find_library_file to +correctly find DLL import libs on Cygwin. Patch by Masayuki Yamamoto. From 07f3c0dbb748e3add71b6e3569abe34fed388aa3 Mon Sep 17 00:00:00 2001 From: "Erik M. Bray" Date: Wed, 12 Jun 2019 14:16:12 +0200 Subject: [PATCH 4/4] bpo-28459: Fix _pyio on Cygwin where the msvcrt module is not built. Instead use ctypes to access the setmode function provided by Cygwin. --- Lib/_pyio.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Lib/_pyio.py b/Lib/_pyio.py index 0b6493bc8dc926..c145934fac4a88 100644 --- a/Lib/_pyio.py +++ b/Lib/_pyio.py @@ -10,8 +10,13 @@ import sys # Import _thread instead of threading to reduce startup cost from _thread import allocate_lock as Lock -if sys.platform in {'win32', 'cygwin'}: +if sys.platform == 'win32': from msvcrt import setmode as _setmode +elif sys.platform == 'cygwin': + import ctypes + _cygwin1 = ctypes.CDLL('cygwin1.dll') + def _setmode(fd, mode): + return _cygwin1._setmode(ctypes.c_int(fd), ctypes.c_int(mode)) else: _setmode = None