lol

Merge pull request #19585 from veprbl/distutils_fix

python: add C++ compiler support for distutils

authored by

Frederik Rietdijk and committed by
GitHub
fea23020 1c523bf1

+324 -11
+9
pkgs/development/interpreters/python/cpython/2.7/default.nix
··· 82 82 ./2.7.3-dylib.patch 83 83 ./2.7.3-getpath-exe-extension.patch 84 84 ./2.7.3-no-libm.patch 85 + ] ++ optionals (!(stdenv.cc.isGNU or false)) [ 86 + 87 + # Patch from http://bugs.python.org/issue1222585 adapted to work with 88 + # `patch -p1' and with a last hunk removed 89 + # Upstream distutils is calling C compiler to compile C++ code, which 90 + # only works for GCC and Apple Clang. This makes distutils to call C++ 91 + # compiler when needed. 92 + ./python-2.7-distutils-C++.patch 93 + 85 94 ]; 86 95 87 96 preConfigure = ''
+260
pkgs/development/interpreters/python/cpython/2.7/python-2.7-distutils-C++.patch
··· 1 + --- a/Lib/distutils/cygwinccompiler.py 2 + +++ b/Lib/distutils/cygwinccompiler.py 3 + @@ -117,8 +117,10 @@ 4 + # dllwrap 2.10.90 is buggy 5 + if self.ld_version >= "2.10.90": 6 + self.linker_dll = "gcc" 7 + + self.linker_dll_cxx = "g++" 8 + else: 9 + self.linker_dll = "dllwrap" 10 + + self.linker_dll_cxx = "dllwrap" 11 + 12 + # ld_version >= "2.13" support -shared so use it instead of 13 + # -mdll -static 14 + @@ -132,9 +134,13 @@ 15 + self.set_executables(compiler='gcc -mcygwin -O -Wall', 16 + compiler_so='gcc -mcygwin -mdll -O -Wall', 17 + compiler_cxx='g++ -mcygwin -O -Wall', 18 + + compiler_so_cxx='g++ -mcygwin -mdll -O -Wall', 19 + linker_exe='gcc -mcygwin', 20 + linker_so=('%s -mcygwin %s' % 21 + - (self.linker_dll, shared_option))) 22 + + (self.linker_dll, shared_option)), 23 + + linker_exe_cxx='g++ -mcygwin', 24 + + linker_so_cxx=('%s -mcygwin %s' % 25 + + (self.linker_dll_cxx, shared_option))) 26 + 27 + # cygwin and mingw32 need different sets of libraries 28 + if self.gcc_version == "2.91.57": 29 + @@ -160,8 +166,12 @@ 30 + raise CompileError, msg 31 + else: # for other files use the C-compiler 32 + try: 33 + - self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 34 + - extra_postargs) 35 + + if self.detect_language(src) == 'c++': 36 + + self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] + 37 + + extra_postargs) 38 + + else: 39 + + self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 40 + + extra_postargs) 41 + except DistutilsExecError, msg: 42 + raise CompileError, msg 43 + 44 + @@ -327,9 +337,14 @@ 45 + self.set_executables(compiler='gcc%s -O -Wall' % no_cygwin, 46 + compiler_so='gcc%s -mdll -O -Wall' % no_cygwin, 47 + compiler_cxx='g++%s -O -Wall' % no_cygwin, 48 + + compiler_so_cxx='g++%s -mdll -O -Wall' % no_cygwin, 49 + linker_exe='gcc%s' % no_cygwin, 50 + linker_so='%s%s %s %s' 51 + % (self.linker_dll, no_cygwin, 52 + + shared_option, entry_point), 53 + + linker_exe_cxx='g++%s' % no_cygwin, 54 + + linker_so_cxx='%s%s %s %s' 55 + + % (self.linker_dll_cxx, no_cygwin, 56 + shared_option, entry_point)) 57 + # Maybe we should also append -mthreads, but then the finished 58 + # dlls need another dll (mingwm10.dll see Mingw32 docs) 59 + --- a/Lib/distutils/emxccompiler.py 60 + +++ b/Lib/distutils/emxccompiler.py 61 + @@ -65,8 +65,12 @@ 62 + # XXX optimization, warnings etc. should be customizable. 63 + self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', 64 + compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', 65 + + compiler_cxx='g++ -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', 66 + + compiler_so_cxx='g++ -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', 67 + linker_exe='gcc -Zomf -Zmt -Zcrtdll', 68 + - linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll') 69 + + linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll', 70 + + linker_exe_cxx='g++ -Zomf -Zmt -Zcrtdll', 71 + + linker_so_cxx='g++ -Zomf -Zmt -Zcrtdll -Zdll') 72 + 73 + # want the gcc library statically linked (so that we don't have 74 + # to distribute a version dependent on the compiler we have) 75 + @@ -83,8 +87,12 @@ 76 + raise CompileError, msg 77 + else: # for other files use the C-compiler 78 + try: 79 + - self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 80 + - extra_postargs) 81 + + if self.detect_language(src) == 'c++': 82 + + self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] + 83 + + extra_postargs) 84 + + else: 85 + + self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 86 + + extra_postargs) 87 + except DistutilsExecError, msg: 88 + raise CompileError, msg 89 + 90 + --- a/Lib/distutils/sysconfig.py 91 + +++ b/Lib/distutils/sysconfig.py 92 + @@ -170,10 +170,12 @@ 93 + _osx_support.customize_compiler(_config_vars) 94 + _config_vars['CUSTOMIZED_OSX_COMPILER'] = 'True' 95 + 96 + - (cc, cxx, opt, cflags, ccshared, ldshared, so_ext, ar, ar_flags) = \ 97 + - get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 98 + - 'CCSHARED', 'LDSHARED', 'SO', 'AR', 99 + - 'ARFLAGS') 100 + + (cc, cxx, ccshared, ldshared, ldcxxshared, so_ext, ar, ar_flags) = \ 101 + + get_config_vars('CC', 'CXX', 'CCSHARED', 'LDSHARED', 'LDCXXSHARED', 102 + + 'SO', 'AR', 'ARFLAGS') 103 + + 104 + + cflags = '' 105 + + cxxflags = '' 106 + 107 + if 'CC' in os.environ: 108 + newcc = os.environ['CC'] 109 + @@ -188,19 +190,27 @@ 110 + cxx = os.environ['CXX'] 111 + if 'LDSHARED' in os.environ: 112 + ldshared = os.environ['LDSHARED'] 113 + + if 'LDCXXSHARED' in os.environ: 114 + + ldcxxshared = os.environ['LDCXXSHARED'] 115 + if 'CPP' in os.environ: 116 + cpp = os.environ['CPP'] 117 + else: 118 + cpp = cc + " -E" # not always 119 + if 'LDFLAGS' in os.environ: 120 + ldshared = ldshared + ' ' + os.environ['LDFLAGS'] 121 + + ldcxxshared = ldcxxshared + ' ' + os.environ['LDFLAGS'] 122 + if 'CFLAGS' in os.environ: 123 + - cflags = opt + ' ' + os.environ['CFLAGS'] 124 + + cflags = os.environ['CFLAGS'] 125 + ldshared = ldshared + ' ' + os.environ['CFLAGS'] 126 + + if 'CXXFLAGS' in os.environ: 127 + + cxxflags = os.environ['CXXFLAGS'] 128 + + ldcxxshared = ldcxxshared + ' ' + os.environ['CXXFLAGS'] 129 + if 'CPPFLAGS' in os.environ: 130 + cpp = cpp + ' ' + os.environ['CPPFLAGS'] 131 + cflags = cflags + ' ' + os.environ['CPPFLAGS'] 132 + + cxxflags = cxxflags + ' ' + os.environ['CPPFLAGS'] 133 + ldshared = ldshared + ' ' + os.environ['CPPFLAGS'] 134 + + ldcxxshared = ldcxxshared + ' ' + os.environ['CPPFLAGS'] 135 + if 'AR' in os.environ: 136 + ar = os.environ['AR'] 137 + if 'ARFLAGS' in os.environ: 138 + @@ -209,13 +219,17 @@ 139 + archiver = ar + ' ' + ar_flags 140 + 141 + cc_cmd = cc + ' ' + cflags 142 + + cxx_cmd = cxx + ' ' + cxxflags 143 + compiler.set_executables( 144 + preprocessor=cpp, 145 + compiler=cc_cmd, 146 + compiler_so=cc_cmd + ' ' + ccshared, 147 + - compiler_cxx=cxx, 148 + + compiler_cxx=cxx_cmd, 149 + + compiler_so_cxx=cxx_cmd + ' ' + ccshared, 150 + linker_so=ldshared, 151 + linker_exe=cc, 152 + + linker_so_cxx=ldcxxshared, 153 + + linker_exe_cxx=cxx, 154 + archiver=archiver) 155 + 156 + compiler.shared_lib_extension = so_ext 157 + --- a/Lib/distutils/unixccompiler.py 158 + +++ b/Lib/distutils/unixccompiler.py 159 + @@ -55,14 +55,17 @@ 160 + # are pretty generic; they will probably have to be set by an outsider 161 + # (eg. using information discovered by the sysconfig about building 162 + # Python extensions). 163 + - executables = {'preprocessor' : None, 164 + - 'compiler' : ["cc"], 165 + - 'compiler_so' : ["cc"], 166 + - 'compiler_cxx' : ["cc"], 167 + - 'linker_so' : ["cc", "-shared"], 168 + - 'linker_exe' : ["cc"], 169 + - 'archiver' : ["ar", "-cr"], 170 + - 'ranlib' : None, 171 + + executables = {'preprocessor' : None, 172 + + 'compiler' : ["cc"], 173 + + 'compiler_so' : ["cc"], 174 + + 'compiler_cxx' : ["c++"], 175 + + 'compiler_so_cxx' : ["c++"], 176 + + 'linker_so' : ["cc", "-shared"], 177 + + 'linker_exe' : ["cc"], 178 + + 'linker_so_cxx' : ["c++", "-shared"], 179 + + 'linker_exe_cxx' : ["c++"], 180 + + 'archiver' : ["ar", "-cr"], 181 + + 'ranlib' : None, 182 + } 183 + 184 + if sys.platform[:6] == "darwin": 185 + @@ -112,12 +115,19 @@ 186 + 187 + def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): 188 + compiler_so = self.compiler_so 189 + + compiler_so_cxx = self.compiler_so_cxx 190 + if sys.platform == 'darwin': 191 + compiler_so = _osx_support.compiler_fixup(compiler_so, 192 + cc_args + extra_postargs) 193 + + compiler_so_cxx = _osx_support.compiler_fixup(compiler_so_cxx, 194 + + cc_args + extra_postargs) 195 + try: 196 + - self.spawn(compiler_so + cc_args + [src, '-o', obj] + 197 + - extra_postargs) 198 + + if self.detect_language(src) == 'c++': 199 + + self.spawn(compiler_so_cxx + cc_args + [src, '-o', obj] + 200 + + extra_postargs) 201 + + else: 202 + + self.spawn(compiler_so + cc_args + [src, '-o', obj] + 203 + + extra_postargs) 204 + except DistutilsExecError, msg: 205 + raise CompileError, msg 206 + 207 + @@ -174,23 +184,16 @@ 208 + ld_args.extend(extra_postargs) 209 + self.mkpath(os.path.dirname(output_filename)) 210 + try: 211 + - if target_desc == CCompiler.EXECUTABLE: 212 + - linker = self.linker_exe[:] 213 + + if target_lang == "c++": 214 + + if target_desc == CCompiler.EXECUTABLE: 215 + + linker = self.linker_exe_cxx[:] 216 + + else: 217 + + linker = self.linker_so_cxx[:] 218 + else: 219 + - linker = self.linker_so[:] 220 + - if target_lang == "c++" and self.compiler_cxx: 221 + - # skip over environment variable settings if /usr/bin/env 222 + - # is used to set up the linker's environment. 223 + - # This is needed on OSX. Note: this assumes that the 224 + - # normal and C++ compiler have the same environment 225 + - # settings. 226 + - i = 0 227 + - if os.path.basename(linker[0]) == "env": 228 + - i = 1 229 + - while '=' in linker[i]: 230 + - i = i + 1 231 + - 232 + - linker[i] = self.compiler_cxx[i] 233 + + if target_desc == CCompiler.EXECUTABLE: 234 + + linker = self.linker_exe[:] 235 + + else: 236 + + linker = self.linker_so[:] 237 + 238 + if sys.platform == 'darwin': 239 + linker = _osx_support.compiler_fixup(linker, ld_args) 240 + --- a/Lib/_osx_support.py 241 + +++ b/Lib/_osx_support.py 242 + @@ -14,13 +14,13 @@ 243 + # configuration variables that may contain universal build flags, 244 + # like "-arch" or "-isdkroot", that may need customization for 245 + # the user environment 246 + -_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'LDFLAGS', 'CPPFLAGS', 'BASECFLAGS', 247 + - 'BLDSHARED', 'LDSHARED', 'CC', 'CXX', 248 + - 'PY_CFLAGS', 'PY_LDFLAGS', 'PY_CPPFLAGS', 249 + - 'PY_CORE_CFLAGS') 250 + +_UNIVERSAL_CONFIG_VARS = ('CFLAGS', 'CXXFLAGS', 'LDFLAGS', 'CPPFLAGS', 251 + + 'BASECFLAGS', 'BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 252 + + 'CC', 'CXX', 'PY_CFLAGS', 'PY_LDFLAGS', 253 + + 'PY_CPPFLAGS', 'PY_CORE_CFLAGS') 254 + 255 + # configuration variables that may contain compiler calls 256 + -_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'CC', 'CXX') 257 + +_COMPILER_CONFIG_VARS = ('BLDSHARED', 'LDSHARED', 'LDCXXSHARED', 'CC', 'CXX') 258 + 259 + # prefix added to original configuration variable names 260 + _INITPRE = '_OSX_SUPPORT_INITIAL_'
+2 -9
pkgs/development/libraries/gdal/default.nix
··· 39 39 (if netcdfSupport then "--with-netcdf=${netcdf}" else "") 40 40 ]; 41 41 42 - # Prevent this: 43 - # 44 - # Checking .pth file support in /nix/store/xkrmb8xnvqxzjwsdmasqmsdh1a5y2y99-gdal-1.11.2/lib/python2.7/site-packages/ 45 - # /nix/store/pbi1lgank10fy0xpjckbdpgacqw34dsz-python-2.7.9/bin/python -E -c pass 46 - # TEST FAILED: /nix/store/xkrmb8xnvqxzjwsdmasqmsdh1a5y2y99-gdal-1.11.2/lib/python2.7/site-packages/ does NOT support .pth files 47 - # error: bad install directory or PYTHONPATH 48 42 preBuild = '' 49 - pythonInstallDir=$out/lib/${pythonPackages.python.libPrefix}/site-packages 50 - mkdir -p $pythonInstallDir 51 - export PYTHONPATH=''${PYTHONPATH:+''${PYTHONPATH}:}$pythonInstallDir 43 + substituteInPlace swig/python/GNUmakefile \ 44 + --replace "ifeq (\$(STD_UNIX_LAYOUT),\"TRUE\")" "ifeq (1,1)" 52 45 ''; 53 46 54 47 postInstall = ''
+15
pkgs/development/python-modules/cython_test.patch
··· 1 + diff --git a/tests/run/numpy_math.pyx b/tests/run/numpy_math.pyx 2 + index eafd23a..4a15522 100644 3 + --- a/tests/run/numpy_math.pyx 4 + +++ b/tests/run/numpy_math.pyx 5 + @@ -37,8 +37,8 @@ def test_fp_classif(): 6 + assert not npmath.isnan(d_zero) 7 + assert not npmath.isnan(f_zero) 8 + 9 + - assert npmath.isinf(npmath.INFINITY) == 1 10 + - assert npmath.isinf(-npmath.INFINITY) == -1 11 + + assert npmath.isinf(npmath.INFINITY) != 0 12 + + assert npmath.isinf(-npmath.INFINITY) != 0 13 + assert npmath.isnan(npmath.NAN) 14 + 15 + assert npmath.signbit(npmath.copysign(1., -1.))
+23
pkgs/development/python-modules/numpy-distutils-C++.patch
··· 1 + diff --git a/numpy/distutils/unixccompiler.py b/numpy/distutils/unixccompiler.py 2 + index a92ccd3..9630e91 100644 3 + --- a/numpy/distutils/unixccompiler.py 4 + +++ b/numpy/distutils/unixccompiler.py 5 + @@ -43,10 +43,15 @@ def UnixCCompiler__compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts 6 + if opt not in llink_s: 7 + self.linker_so = llink_s.split() + opt.split() 8 + 9 + - display = '%s: %s' % (os.path.basename(self.compiler_so[0]), src) 10 + try: 11 + - self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 12 + - extra_postargs, display = display) 13 + + if self.detect_language(src) == 'c++': 14 + + display = '%s: %s' % (os.path.basename(self.compiler_so_cxx[0]), src) 15 + + self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] + 16 + + extra_postargs, display = display) 17 + + else: 18 + + display = '%s: %s' % (os.path.basename(self.compiler_so[0]), src) 19 + + self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + 20 + + extra_postargs, display = display) 21 + except DistutilsExecError: 22 + msg = str(get_exception()) 23 + raise CompileError(msg)
+7 -1
pkgs/development/python-modules/numpy.nix
··· 1 - {lib, python, buildPythonPackage, isPyPy, gfortran, nose, blas}: 1 + {lib, python, buildPythonPackage, isPy27, isPyPy, gfortran, nose, blas}: 2 2 3 3 args: 4 4 ··· 11 11 disabled = isPyPy; 12 12 buildInputs = args.buildInputs or [ gfortran nose ]; 13 13 propagatedBuildInputs = args.propagatedBuildInputs or [ passthru.blas ]; 14 + 15 + patches = lib.optionals isPy27 [ 16 + # See cpython 2.7 patches. 17 + # numpy.distutils is used by cython during it's check phase 18 + ./numpy-distutils-C++.patch 19 + ]; 14 20 15 21 preConfigure = '' 16 22 sed -i 's/-faltivec//' numpy/distutils/system_info.py
+8 -1
pkgs/top-level/python-packages.nix
··· 4172 4172 # For testing 4173 4173 nativeBuildInputs = with self; [ numpy pkgs.ncurses ]; 4174 4174 4175 + # cython's testsuite requires npy_isinf to return sign of the infinity, but 4176 + # a C99 conformant is only required to return a non zero value 4177 + patches = [ ../development/python-modules/cython_test.patch ]; 4178 + 4179 + # cython's testsuite is not working very well with libc++ 4180 + # We are however optimistic about things outside of testsuite still working 4175 4181 checkPhase = '' 4176 4182 export HOME="$NIX_BUILD_TOP" 4177 - ${python.interpreter} runtests.py 4183 + ${python.interpreter} runtests.py \ 4184 + ${if stdenv.cc.isClang or false then ''--exclude="(cpdef_extern_func|libcpp_algo)"'' else ""} 4178 4185 ''; 4179 4186 4180 4187 meta = {