2021-02-22 21:28:39 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2020-04-24 23:36:52 +00:00
|
|
|
, fetchurl
|
|
|
|
, python-setup-hook
|
|
|
|
, self
|
|
|
|
, which
|
|
|
|
# Dependencies
|
|
|
|
, bzip2
|
2022-01-19 23:45:15 +00:00
|
|
|
, sqlite
|
2020-04-24 23:36:52 +00:00
|
|
|
, zlib
|
2022-01-19 23:45:15 +00:00
|
|
|
, openssl
|
2020-04-24 23:36:52 +00:00
|
|
|
, expat
|
2020-08-20 17:08:02 +00:00
|
|
|
, ncurses6
|
|
|
|
, tcl-8_5
|
|
|
|
, tk-8_5
|
2020-04-24 23:36:52 +00:00
|
|
|
# For the Python package set
|
|
|
|
, packageOverrides ? (self: super: {})
|
|
|
|
, sourceVersion
|
|
|
|
, pythonVersion
|
|
|
|
, sha256
|
|
|
|
, passthruFun
|
|
|
|
}:
|
|
|
|
|
|
|
|
# This version of PyPy is primarily added to speed-up translation of
|
|
|
|
# our PyPy source build when developing that expression.
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
with lib;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
isPy3k = majorVersion == "3";
|
2022-01-19 23:45:15 +00:00
|
|
|
passthru = passthruFun rec {
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit self sourceVersion pythonVersion packageOverrides;
|
|
|
|
implementation = "pypy";
|
|
|
|
libPrefix = "pypy${pythonVersion}";
|
|
|
|
executable = "pypy${if isPy3k then "3" else ""}";
|
2022-01-19 23:45:15 +00:00
|
|
|
sitePackages = "lib/${libPrefix}/site-packages";
|
2020-04-24 23:36:52 +00:00
|
|
|
hasDistutilsCxxPatch = false;
|
2021-02-22 21:28:39 +00:00
|
|
|
|
|
|
|
# Not possible to cross-compile with.
|
|
|
|
pythonOnBuildForBuild = throw "${pname} does not support cross compilation";
|
|
|
|
pythonOnBuildForHost = self;
|
|
|
|
pythonOnBuildForTarget = throw "${pname} does not support cross compilation";
|
|
|
|
pythonOnHostForHost = throw "${pname} does not support cross compilation";
|
|
|
|
pythonOnTargetForTarget = throw "${pname} does not support cross compilation";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
pname = "${passthru.executable}_prebuilt";
|
|
|
|
version = with sourceVersion; "${major}.${minor}.${patch}";
|
|
|
|
|
|
|
|
majorVersion = substring 0 1 pythonVersion;
|
|
|
|
|
|
|
|
deps = [
|
|
|
|
bzip2
|
2022-01-19 23:45:15 +00:00
|
|
|
sqlite
|
2020-04-24 23:36:52 +00:00
|
|
|
zlib
|
2022-01-19 23:45:15 +00:00
|
|
|
openssl
|
2020-04-24 23:36:52 +00:00
|
|
|
expat
|
2020-08-20 17:08:02 +00:00
|
|
|
ncurses6
|
|
|
|
tcl-8_5
|
|
|
|
tk-8_5
|
2020-04-24 23:36:52 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
in with passthru; stdenv.mkDerivation {
|
|
|
|
inherit pname version;
|
|
|
|
|
|
|
|
src = fetchurl {
|
2021-02-13 14:23:35 +00:00
|
|
|
url = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-linux64.tar.bz2";
|
2020-04-24 23:36:52 +00:00
|
|
|
inherit sha256;
|
|
|
|
};
|
|
|
|
|
|
|
|
buildInputs = [ which ];
|
|
|
|
|
|
|
|
installPhase = ''
|
2022-01-19 23:45:15 +00:00
|
|
|
mkdir -p $out
|
2020-04-24 23:36:52 +00:00
|
|
|
echo "Moving files to $out"
|
2022-01-19 23:45:15 +00:00
|
|
|
mv -t $out bin include lib
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
mv $out/bin/libpypy*-c.so $out/lib/
|
|
|
|
|
|
|
|
rm $out/bin/*.debug
|
|
|
|
|
|
|
|
echo "Patching binaries"
|
|
|
|
interpreter=$(patchelf --print-interpreter $(readlink -f $(which patchelf)))
|
|
|
|
patchelf --set-interpreter $interpreter \
|
|
|
|
--set-rpath $out/lib \
|
|
|
|
$out/bin/pypy*
|
|
|
|
|
|
|
|
pushd $out
|
2022-01-19 23:45:15 +00:00
|
|
|
|
|
|
|
find ./lib -name "*.so" -exec patchelf --remove-needed libncursesw.so.6 --replace-needed libtinfow.so.6 libncursesw.so.6 {} \;
|
|
|
|
find ./lib -name "*.so" -exec patchelf --set-rpath ${lib.makeLibraryPath deps}:$out/lib {} \;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
echo "Removing bytecode"
|
|
|
|
find . -name "__pycache__" -type d -depth -exec rm -rf {} \;
|
|
|
|
popd
|
|
|
|
|
|
|
|
# Include a sitecustomize.py file
|
|
|
|
cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
|
|
|
|
|
|
|
|
'';
|
|
|
|
|
|
|
|
doInstallCheck = true;
|
|
|
|
|
|
|
|
# Check whether importing of (extension) modules functions
|
|
|
|
installCheckPhase = let
|
|
|
|
modules = [
|
|
|
|
"ssl"
|
|
|
|
"sys"
|
|
|
|
"curses"
|
|
|
|
] ++ optionals (!isPy3k) [
|
|
|
|
"Tkinter"
|
|
|
|
] ++ optionals isPy3k [
|
|
|
|
"tkinter"
|
|
|
|
];
|
|
|
|
imports = concatMapStringsSep "; " (x: "import ${x}") modules;
|
|
|
|
in ''
|
|
|
|
echo "Testing whether we can import modules"
|
|
|
|
$out/bin/${executable} -c '${imports}'
|
|
|
|
'';
|
|
|
|
|
|
|
|
setupHook = python-setup-hook sitePackages;
|
|
|
|
|
|
|
|
donPatchElf = true;
|
|
|
|
dontStrip = true;
|
|
|
|
|
|
|
|
inherit passthru;
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
homepage = "http://pypy.org/";
|
|
|
|
description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
|
|
|
|
license = licenses.mit;
|
|
|
|
platforms = [ "x86_64-linux" ];
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|