at 17.09-beta 6.3 kB view raw
1{ stdenv, fetchurl, zlib ? null, zlibSupport ? true, bzip2, pkgconfig, libffi 2, sqlite, openssl, ncurses, python, expat, tcl, tk, tix, xlibsWrapper, libX11 3, makeWrapper, callPackage, self, gdbm, db 4, python-setup-hook 5# For the Python package set 6, pkgs, packageOverrides ? (self: super: {}) 7}: 8 9assert zlibSupport -> zlib != null; 10 11let 12 majorVersion = "5.8"; 13 minorVersion = "0"; 14 minorVersionSuffix = ""; 15 pythonVersion = "2.7"; 16 version = "${majorVersion}.${minorVersion}${minorVersionSuffix}"; 17 libPrefix = "pypy${majorVersion}"; 18 sitePackages = "site-packages"; 19 20 pythonForPypy = python.withPackages (ppkgs: [ ppkgs.pycparser ]); 21 22in stdenv.mkDerivation rec { 23 name = "pypy-${version}"; 24 inherit majorVersion version pythonVersion; 25 26 src = fetchurl { 27 url = "https://bitbucket.org/pypy/pypy/get/release-pypy${pythonVersion}-v${version}.tar.bz2"; 28 sha256 = "0dibf1bx4icrbi8zsqk7cfwgwsd3hfx6biz59k8j5rys3fx9z418"; 29 }; 30 31 patches = [ 32 # https://bitbucket.org/pypy/pypy/issues/2604/lib-python-27-test-test_ospy 33 ./2604-skip-urandom-fd-test.patch 34 ]; 35 36 postPatch = '' 37 substituteInPlace "lib-python/2.7/lib-tk/Tix.py" --replace "os.environ.get('TIX_LIBRARY')" "os.environ.get('TIX_LIBRARY') or '${tix}/lib'" 38 ''; 39 40 buildInputs = [ bzip2 openssl pkgconfig pythonForPypy libffi ncurses expat sqlite tk tcl xlibsWrapper libX11 makeWrapper gdbm db ] 41 ++ stdenv.lib.optional (stdenv ? cc && stdenv.cc.libc != null) stdenv.cc.libc 42 ++ stdenv.lib.optional zlibSupport zlib; 43 44 hardeningDisable = stdenv.lib.optional stdenv.isi686 "pic"; 45 46 C_INCLUDE_PATH = stdenv.lib.makeSearchPathOutput "dev" "include" buildInputs; 47 LIBRARY_PATH = stdenv.lib.makeLibraryPath buildInputs; 48 LD_LIBRARY_PATH = stdenv.lib.makeLibraryPath (stdenv.lib.filter (x : x.outPath != stdenv.cc.libc.outPath or "") buildInputs); 49 50 preConfigure = '' 51 # hint pypy to find nix ncurses 52 substituteInPlace pypy/module/_minimal_curses/fficurses.py \ 53 --replace "/usr/include/ncurses/curses.h" "${ncurses.dev}/include/curses.h" \ 54 --replace "ncurses/curses.h" "${ncurses.dev}/include/curses.h" \ 55 --replace "ncurses/term.h" "${ncurses.dev}/include/term.h" \ 56 --replace "libraries=['curses']" "libraries=['ncurses']" 57 58 # tkinter hints 59 substituteInPlace lib_pypy/_tkinter/tklib_build.py \ 60 --replace "'/usr/include/tcl'" "'${tk}/include', '${tcl}/include'" \ 61 --replace "linklibs = ['tcl' + _ver, 'tk' + _ver]" "linklibs=['${tcl.libPrefix}', '${tk.libPrefix}']" \ 62 --replace "libdirs = []" "libdirs = ['${tk}/lib', '${tcl}/lib']" 63 64 sed -i "s@libraries=\['sqlite3'\]\$@libraries=['sqlite3'], include_dirs=['${sqlite.dev}/include'], library_dirs=['${sqlite.out}/lib']@" lib_pypy/_sqlite3_build.py 65 ''; 66 67 buildPhase = '' 68 ${pythonForPypy.interpreter} rpython/bin/rpython --make-jobs="$NIX_BUILD_CORES" -Ojit --batch pypy/goal/targetpypystandalone.py --withmod-_minimal_curses --withmod-unicodedata --withmod-thread --withmod-bz2 --withmod-_multiprocessing 69 ''; 70 71 setupHook = python-setup-hook sitePackages; 72 73 postBuild = '' 74 cd ./lib_pypy 75 ../pypy-c ./_audioop_build.py 76 ../pypy-c ./_curses_build.py 77 ../pypy-c ./_pwdgrp_build.py 78 ../pypy-c ./_sqlite3_build.py 79 ../pypy-c ./_syslog_build.py 80 ../pypy-c ./_tkinter/tklib_build.py 81 cd .. 82 ''; 83 84 doCheck = true; 85 checkPhase = '' 86 export TERMINFO="${ncurses.out}/share/terminfo/"; 87 export TERM="xterm"; 88 export HOME="$TMPDIR"; 89 # disable shutils because it assumes gid 0 exists 90 # disable socket because it has two actual network tests that fail 91 # disable test_urllib2net, test_urllib2_localnet, and test_urllibnet because they require networking (example.com) 92 # disable test_ssl because no shared cipher' not found in '[Errno 1] error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure 93 # disable test_zipfile64 because it causes ENOSPACE 94 ./pypy-c ./pypy/test_all.py --pypy=./pypy-c -k 'not ( test_ssl or test_urllib2net or test_urllibnet or test_urllib2_localnet or test_socket or test_shutil or test_zipfile64 )' lib-python 95 ''; 96 97 installPhase = '' 98 mkdir -p $out/{bin,include,lib,pypy-c} 99 100 cp -R {include,lib_pypy,lib-python,pypy-c} $out/pypy-c 101 cp libpypy-c.so $out/lib/ 102 ln -s $out/pypy-c/pypy-c $out/bin/pypy 103 chmod +x $out/bin/pypy 104 105 # other packages expect to find stuff according to libPrefix 106 ln -s $out/pypy-c/include $out/include/${libPrefix} 107 ln -s $out/pypy-c/lib-python/${pythonVersion} $out/lib/${libPrefix} 108 109 # We must wrap the original, not the symlink. 110 # PyPy uses argv[0] to find its standard library, and while it knows 111 # how to follow symlinks, it doesn't know about wrappers. So, it 112 # will think the wrapper is the original. As long as the wrapper has 113 # the same path as the original, this is OK. 114 wrapProgram "$out/pypy-c/pypy-c" \ 115 --set LD_LIBRARY_PATH "${LD_LIBRARY_PATH}:$out/lib" \ 116 --set LIBRARY_PATH "${LIBRARY_PATH}:$out/lib" 117 118 # verify cffi modules 119 $out/bin/pypy -c "import Tkinter;import sqlite3;import curses" 120 121 # Python on Nix is not manylinux1 compatible. https://github.com/NixOS/nixpkgs/issues/18484 122 echo "manylinux1_compatible=False" >> $out/lib/${libPrefix}/_manylinux.py 123 ''; 124 125 passthru = let 126 pythonPackages = callPackage ../../../../../top-level/python-packages.nix {python=self; overrides=packageOverrides;}; 127 in rec { 128 inherit zlibSupport libPrefix sitePackages; 129 executable = "pypy"; 130 isPypy = true; 131 buildEnv = callPackage ../../wrapper.nix { python = self; }; 132 interpreter = "${self}/bin/${executable}"; 133 withPackages = import ../../with-packages.nix { inherit buildEnv pythonPackages;}; 134 pkgs = pythonPackages; 135 }; 136 137 enableParallelBuilding = true; # almost no parallelization without STM 138 139 meta = with stdenv.lib; { 140 homepage = http://pypy.org/; 141 description = "Fast, compliant alternative implementation of the Python language (2.7.13)"; 142 license = licenses.mit; 143 platforms = platforms.linux; 144 maintainers = with maintainers; [ domenkozar ]; 145 }; 146}