nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 187 lines 5.1 kB view raw
1{ 2 lib, 3 stdenv, 4 fetchurl, 5 autoPatchelfHook, 6 python-setup-hook, 7 self, 8 # Dependencies 9 bzip2, 10 expat, 11 gdbm, 12 ncurses6, 13 sqlite, 14 tcl-8_5, 15 tk-8_5, 16 tcl-8_6, 17 tk-8_6, 18 zlib, 19 # For the Python package set 20 packageOverrides ? (self: super: { }), 21 sourceVersion, 22 pythonVersion, 23 hash, 24 passthruFun, 25}: 26 27# This version of PyPy is primarily added to speed-up translation of 28# our PyPy source build when developing that expression. 29 30let 31 isPy3k = majorVersion == "3"; 32 passthru = passthruFun rec { 33 inherit 34 self 35 sourceVersion 36 pythonVersion 37 packageOverrides 38 ; 39 implementation = "pypy"; 40 libPrefix = "pypy${pythonVersion}"; 41 executable = "pypy${lib.optionalString isPy3k "3"}"; 42 sitePackages = "lib/${libPrefix}/site-packages"; 43 hasDistutilsCxxPatch = false; 44 45 # Not possible to cross-compile with. 46 pythonOnBuildForBuild = throw "${pname} does not support cross compilation"; 47 pythonOnBuildForHost = self; 48 pythonOnBuildForTarget = throw "${pname} does not support cross compilation"; 49 pythonOnHostForHost = throw "${pname} does not support cross compilation"; 50 pythonOnTargetForTarget = throw "${pname} does not support cross compilation"; 51 52 pythonABITags = [ 53 "none" 54 "pypy${lib.concatStrings (lib.take 2 (lib.splitString "." pythonVersion))}_pp${sourceVersion.major}${sourceVersion.minor}" 55 ]; 56 }; 57 pname = "${passthru.executable}_prebuilt"; 58 version = with sourceVersion; "${major}.${minor}.${patch}"; 59 60 majorVersion = lib.versions.major pythonVersion; 61 62 downloadUrls = { 63 aarch64-linux = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-aarch64.tar.bz2"; 64 x86_64-linux = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-linux64.tar.bz2"; 65 aarch64-darwin = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-macos_arm64.tar.bz2"; 66 x86_64-darwin = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-macos_x86_64.tar.bz2"; 67 }; 68 69in 70with passthru; 71stdenv.mkDerivation { 72 inherit pname version; 73 74 src = fetchurl { 75 url = downloadUrls.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}"); 76 inherit hash; 77 }; 78 79 buildInputs = [ 80 bzip2 81 expat 82 gdbm 83 ncurses6 84 sqlite 85 zlib 86 stdenv.cc.cc.libgcc or null 87 ] 88 ++ lib.optionals stdenv.hostPlatform.isLinux [ 89 tcl-8_5 90 tk-8_5 91 ] 92 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 93 tcl-8_6 94 tk-8_6 95 ]; 96 97 nativeBuildInputs = lib.optionals stdenv.hostPlatform.isLinux [ autoPatchelfHook ]; 98 99 installPhase = '' 100 runHook preInstall 101 102 mkdir -p $out 103 echo "Moving files to $out" 104 mv -t $out bin include lib 105 mv $out/bin/libpypy*-c${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/ 106 ${lib.optionalString stdenv.hostPlatform.isLinux '' 107 rm $out/bin/*.debug 108 ''} 109 110 echo "Removing bytecode" 111 find . -name "__pycache__" -type d -depth -delete 112 113 # Include a sitecustomize.py file 114 cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py 115 116 runHook postInstall 117 ''; 118 119 preFixup = 120 lib.optionalString stdenv.hostPlatform.isLinux '' 121 find $out/{lib,lib_pypy*} -name "*.so" \ 122 -exec patchelf \ 123 --replace-needed libtinfow.so.6 libncursesw.so.6 \ 124 --replace-needed libgdbm.so.4 libgdbm_compat.so.4 {} \; 125 '' 126 + lib.optionalString stdenv.hostPlatform.isDarwin '' 127 install_name_tool \ 128 -change \ 129 @rpath/lib${libPrefix}-c.dylib \ 130 $out/lib/lib${libPrefix}-c.dylib \ 131 $out/bin/${executable} 132 install_name_tool \ 133 -change \ 134 @rpath/lib${libPrefix}-c.dylib \ 135 $out/lib/lib${libPrefix}-c.dylib \ 136 $out/bin/${libPrefix} 137 install_name_tool \ 138 -change \ 139 /opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtcl8.6.dylib \ 140 ${tcl-8_6}/lib/libtcl8.6.dylib \ 141 $out/lib/${libPrefix}/_tkinter/*.so 142 install_name_tool \ 143 -change \ 144 /opt/homebrew${lib.optionalString stdenv.hostPlatform.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtk8.6.dylib \ 145 ${tk-8_6}/lib/libtk8.6.dylib \ 146 $out/lib/${libPrefix}/_tkinter/*.so 147 ''; 148 149 doInstallCheck = true; 150 151 # Check whether importing of (extension) modules functions 152 installCheckPhase = 153 let 154 modules = [ 155 "ssl" 156 "sys" 157 "curses" 158 ] 159 ++ lib.optionals (!isPy3k) [ 160 "Tkinter" 161 ] 162 ++ lib.optionals isPy3k [ 163 "tkinter" 164 ]; 165 imports = lib.concatMapStringsSep "; " (x: "import ${x}") modules; 166 in 167 '' 168 echo "Testing whether we can import modules" 169 $out/bin/${executable} -c '${imports}' 170 ''; 171 172 setupHook = python-setup-hook sitePackages; 173 174 donPatchElf = true; 175 dontStrip = true; 176 177 inherit passthru; 178 179 meta = { 180 homepage = "http://pypy.org/"; 181 description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})"; 182 mainProgram = "pypy"; 183 license = lib.licenses.mit; 184 platforms = lib.attrNames downloadUrls; 185 }; 186 187}