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