|
| 1 | +diff --git a/Lib/distutils/cygwinccompiler.py b/Lib/distutils/cygwinccompiler.py |
| 2 | +index 66c12dd..2f76fb2 100644 |
| 3 | +--- a/Lib/distutils/cygwinccompiler.py |
| 4 | ++++ b/Lib/distutils/cygwinccompiler.py |
| 5 | +@@ -44,6 +44,8 @@ cygwin in no-cygwin mode). |
| 6 | + # (ld supports -shared) |
| 7 | + # * mingw gcc 3.2/ld 2.13 works |
| 8 | + # (ld supports -shared) |
| 9 | ++# * llvm-mingw with Clang 11 works |
| 10 | ++# (lld supports -shared) |
| 11 | + |
| 12 | + import os |
| 13 | + import sys |
| 14 | +@@ -109,41 +111,46 @@ class CygwinCCompiler(UnixCCompiler): |
| 15 | + "Compiling may fail because of undefined preprocessor macros." |
| 16 | + % details) |
| 17 | + |
| 18 | +- self.gcc_version, self.ld_version, self.dllwrap_version = \ |
| 19 | +- get_versions() |
| 20 | +- self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % |
| 21 | +- (self.gcc_version, |
| 22 | +- self.ld_version, |
| 23 | +- self.dllwrap_version) ) |
| 24 | +- |
| 25 | +- # ld_version >= "2.10.90" and < "2.13" should also be able to use |
| 26 | +- # gcc -mdll instead of dllwrap |
| 27 | +- # Older dllwraps had own version numbers, newer ones use the |
| 28 | +- # same as the rest of binutils ( also ld ) |
| 29 | +- # dllwrap 2.10.90 is buggy |
| 30 | +- if self.ld_version >= "2.10.90": |
| 31 | +- self.linker_dll = "gcc" |
| 32 | +- else: |
| 33 | +- self.linker_dll = "dllwrap" |
| 34 | ++ self.cc = os.environ.get('CC', 'gcc') |
| 35 | ++ self.cxx = os.environ.get('CXX', 'g++') |
| 36 | ++ |
| 37 | ++ if ('gcc' in self.cc): # Start gcc workaround |
| 38 | ++ self.gcc_version, self.ld_version, self.dllwrap_version = \ |
| 39 | ++ get_gcc_versions() |
| 40 | ++ self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % |
| 41 | ++ (self.gcc_version, |
| 42 | ++ self.ld_version, |
| 43 | ++ self.dllwrap_version) ) |
| 44 | ++ |
| 45 | ++ # ld_version >= "2.10.90" and < "2.13" should also be able to use |
| 46 | ++ # gcc -mdll instead of dllwrap |
| 47 | ++ # Older dllwraps had own version numbers, newer ones use the |
| 48 | ++ # same as the rest of binutils ( also ld ) |
| 49 | ++ # dllwrap 2.10.90 is buggy |
| 50 | ++ if self.ld_version >= "2.10.90": |
| 51 | ++ self.linker_dll = self.cc |
| 52 | ++ else: |
| 53 | ++ self.linker_dll = "dllwrap" |
| 54 | + |
| 55 | +- # ld_version >= "2.13" support -shared so use it instead of |
| 56 | +- # -mdll -static |
| 57 | +- if self.ld_version >= "2.13": |
| 58 | ++ # ld_version >= "2.13" support -shared so use it instead of |
| 59 | ++ # -mdll -static |
| 60 | ++ if self.ld_version >= "2.13": |
| 61 | ++ shared_option = "-shared" |
| 62 | ++ else: |
| 63 | ++ shared_option = "-mdll -static" |
| 64 | ++ else: # Assume linker is up to date |
| 65 | ++ self.linker_dll = self.cc |
| 66 | + shared_option = "-shared" |
| 67 | +- else: |
| 68 | +- shared_option = "-mdll -static" |
| 69 | + |
| 70 | +- # Hard-code GCC because that's what this is all about. |
| 71 | +- # XXX optimization, warnings etc. should be customizable. |
| 72 | +- self.set_executables(compiler='gcc -mcygwin -O -Wall', |
| 73 | +- compiler_so='gcc -mcygwin -mdll -O -Wall', |
| 74 | +- compiler_cxx='g++ -mcygwin -O -Wall', |
| 75 | +- linker_exe='gcc -mcygwin', |
| 76 | ++ self.set_executables(compiler='%s -mcygwin -O -Wall' % self.cc, |
| 77 | ++ compiler_so='%s -mcygwin -mdll -O -Wall' % self.cc, |
| 78 | ++ compiler_cxx='%s -mcygwin -O -Wall' % self.cxx, |
| 79 | ++ linker_exe='%s -mcygwin' % self.cc, |
| 80 | + linker_so=('%s -mcygwin %s' % |
| 81 | + (self.linker_dll, shared_option))) |
| 82 | + |
| 83 | + # cygwin and mingw32 need different sets of libraries |
| 84 | +- if self.gcc_version == "2.91.57": |
| 85 | ++ if ('gcc' in self.cc and self.gcc_version == "2.91.57"): |
| 86 | + # cygwin shouldn't need msvcrt, but without the dlls will crash |
| 87 | + # (gcc version 2.91.57) -- perhaps something about initialization |
| 88 | + self.dll_libraries=["msvcrt"] |
| 89 | +@@ -281,26 +288,26 @@ class Mingw32CCompiler(CygwinCCompiler): |
| 90 | + |
| 91 | + # ld_version >= "2.13" support -shared so use it instead of |
| 92 | + # -mdll -static |
| 93 | +- if self.ld_version >= "2.13": |
| 94 | +- shared_option = "-shared" |
| 95 | +- else: |
| 96 | ++ if ('gcc' in self.cc and self.ld_version < "2.13"): |
| 97 | + shared_option = "-mdll -static" |
| 98 | ++ else: |
| 99 | ++ shared_option = "-shared" |
| 100 | + |
| 101 | + # A real mingw32 doesn't need to specify a different entry point, |
| 102 | + # but cygwin 2.91.57 in no-cygwin-mode needs it. |
| 103 | +- if self.gcc_version <= "2.91.57": |
| 104 | ++ if ('gcc' in self.cc and self.gcc_version <= "2.91.57"): |
| 105 | + entry_point = '--entry _DllMain@12' |
| 106 | + else: |
| 107 | + entry_point = '' |
| 108 | + |
| 109 | +- if is_cygwingcc(): |
| 110 | ++ if is_cygwincc(self.cc): |
| 111 | + raise CCompilerError( |
| 112 | + 'Cygwin gcc cannot be used with --compiler=mingw32') |
| 113 | + |
| 114 | +- self.set_executables(compiler='gcc -O2 -Wall', |
| 115 | +- compiler_so='gcc -mdll -O2 -Wall', |
| 116 | +- compiler_cxx='g++ -O2 -Wall', |
| 117 | +- linker_exe='gcc', |
| 118 | ++ self.set_executables(compiler='%s -O2 -Wall' % self.cc, |
| 119 | ++ compiler_so='%s -mdll -O2 -Wall' % self.cc, |
| 120 | ++ compiler_cxx='%s -O2 -Wall' % self.cxx, |
| 121 | ++ linker_exe='%s' % self.cc, |
| 122 | + linker_so='%s %s %s' |
| 123 | + % (self.linker_dll, shared_option, |
| 124 | + entry_point)) |
| 125 | +@@ -351,6 +358,10 @@ def check_config_h(): |
| 126 | + if "GCC" in sys.version: |
| 127 | + return CONFIG_H_OK, "sys.version mentions 'GCC'" |
| 128 | + |
| 129 | ++ # Clang would also work |
| 130 | ++ if "Clang" in sys.version: |
| 131 | ++ return CONFIG_H_OK, "sys.version mentions 'Clang'" |
| 132 | ++ |
| 133 | + # let's see if __GNUC__ is mentioned in python.h |
| 134 | + fn = sysconfig.get_config_h_filename() |
| 135 | + try: |
| 136 | +@@ -389,7 +400,7 @@ def _find_exe_version(cmd): |
| 137 | + # so we need to decode our bytes |
| 138 | + return LooseVersion(result.group(1).decode()) |
| 139 | + |
| 140 | +-def get_versions(): |
| 141 | ++def get_gcc_versions(): |
| 142 | + """ Try to find out the versions of gcc, ld and dllwrap. |
| 143 | + |
| 144 | + If not possible it returns None for it. |
| 145 | +@@ -397,7 +408,7 @@ def get_versions(): |
| 146 | + commands = [gcc+' -dumpversion', ld+' -v', 'dllwrap --version'] |
| 147 | + return tuple([_find_exe_version(cmd) for cmd in commands]) |
| 148 | + |
| 149 | +-def is_cygwingcc(): |
| 150 | +- '''Try to determine if the gcc that would be used is from cygwin.''' |
| 151 | +- out_string = check_output(['gcc', '-dumpmachine']) |
| 152 | ++def is_cygwincc(cc): |
| 153 | ++ '''Try to determine if the compiler that would be used is from cygwin.''' |
| 154 | ++ out_string = check_output([cc, '-dumpmachine']) |
| 155 | + return out_string.strip().endswith(b'cygwin') |
0 commit comments