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