1{ stdenv
2, fetchurl
3, python-setup-hook
4, self
5, which
6# Dependencies
7, bzip2
8, zlib
9, openssl
10, expat
11, libffi
12, ncurses
13, tcl
14, tk
15# For the Python package set
16, packageOverrides ? (self: super: {})
17, sourceVersion
18, pythonVersion
19, sha256
20, passthruFun
21}:
22
23# This version of PyPy is primarily added to speed-up translation of
24# our PyPy source build when developing that expression.
25
26with stdenv.lib;
27
28let
29 isPy3k = majorVersion == "3";
30 passthru = passthruFun rec {
31 inherit self sourceVersion pythonVersion packageOverrides;
32 implementation = "pypy";
33 libPrefix = "pypy${pythonVersion}";
34 executable = "pypy${if isPy3k then "3" else ""}";
35 pythonForBuild = self; # Not possible to cross-compile with.
36 sitePackages = "site-packages";
37 };
38 pname = "${passthru.executable}_prebuilt";
39 version = with sourceVersion; "${major}.${minor}.${patch}";
40
41 majorVersion = substring 0 1 pythonVersion;
42
43 setupHook = python-setup-hook sitePackages;
44
45 deps = [
46 bzip2
47 zlib
48 openssl
49 expat
50 libffi
51 ncurses
52 tcl
53 tk
54 ];
55
56in with passthru; stdenv.mkDerivation {
57 inherit pname version;
58
59 src = fetchurl {
60 url= "https://bitbucket.org/pypy/pypy/downloads/pypy${majorVersion}-v${version}-linux64.tar.bz2";
61 inherit sha256;
62 };
63
64 buildInputs = [ which ];
65
66 installPhase = ''
67 mkdir -p $out/lib
68 echo "Moving files to $out"
69 mv -t $out bin include lib-python lib_pypy site-packages
70
71 mv $out/bin/libpypy*-c.so $out/lib/
72
73 rm $out/bin/*.debug
74
75 echo "Patching binaries"
76 interpreter=$(patchelf --print-interpreter $(readlink -f $(which patchelf)))
77 patchelf --set-interpreter $interpreter \
78 --set-rpath $out/lib \
79 $out/bin/pypy*
80
81 pushd $out
82 find {lib,lib_pypy*} -name "*.so" -exec patchelf --replace-needed "libbz2.so.1.0" "libbz2.so.1" {} \;
83 find {lib,lib_pypy*} -name "*.so" -exec patchelf --set-rpath ${stdenv.lib.makeLibraryPath deps} {} \;
84
85 echo "Removing bytecode"
86 find . -name "__pycache__" -type d -depth -exec rm -rf {} \;
87 popd
88 '';
89
90 doInstallCheck = true;
91
92 # Check whether importing of (extension) modules functions
93 installCheckPhase = let
94 modules = [
95 "ssl"
96 "sys"
97 "curses"
98 ] ++ optionals (!isPy3k) [
99 "Tkinter"
100 ] ++ optionals isPy3k [
101 "tkinter"
102 ];
103 imports = concatMapStringsSep "; " (x: "import ${x}") modules;
104 in ''
105 echo "Testing whether we can import modules"
106 $out/bin/${executable} -c '${imports}'
107 '';
108
109 setupHook = python-setup-hook sitePackages;
110
111 donPatchElf = true;
112 dontStrip = true;
113
114 inherit passthru;
115
116 meta = with stdenv.lib; {
117 homepage = http://pypy.org/;
118 description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
119 license = licenses.mit;
120 platforms = [ "x86_64-linux" ];
121 };
122
123}