2021-02-22 21:28:39 +00:00
|
|
|
{ lib
|
|
|
|
, stdenv
|
2020-04-24 23:36:52 +00:00
|
|
|
, fetchurl
|
2023-01-11 07:51:40 +00:00
|
|
|
, autoPatchelfHook
|
2020-04-24 23:36:52 +00:00
|
|
|
, python-setup-hook
|
|
|
|
, self
|
|
|
|
# Dependencies
|
|
|
|
, bzip2
|
|
|
|
, expat
|
2023-01-11 07:51:40 +00:00
|
|
|
, gdbm
|
2020-08-20 17:08:02 +00:00
|
|
|
, ncurses6
|
2023-01-11 07:51:40 +00:00
|
|
|
, sqlite
|
2020-08-20 17:08:02 +00:00
|
|
|
, tcl-8_5
|
|
|
|
, tk-8_5
|
2023-01-11 07:51:40 +00:00
|
|
|
, tcl-8_6
|
|
|
|
, tk-8_6
|
|
|
|
, zlib
|
2020-04-24 23:36:52 +00:00
|
|
|
# For the Python package set
|
|
|
|
, packageOverrides ? (self: super: {})
|
|
|
|
, sourceVersion
|
|
|
|
, pythonVersion
|
2023-03-04 12:14:45 +00:00
|
|
|
, hash
|
2020-04-24 23:36:52 +00:00
|
|
|
, passthruFun
|
|
|
|
}:
|
|
|
|
|
|
|
|
# This version of PyPy is primarily added to speed-up translation of
|
|
|
|
# our PyPy source build when developing that expression.
|
|
|
|
|
|
|
|
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}";
|
2023-02-16 17:41:37 +00:00
|
|
|
executable = "pypy${lib.optionalString isPy3k "3"}";
|
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}";
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
majorVersion = lib.versions.major pythonVersion;
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
downloadUrls = {
|
|
|
|
aarch64-linux = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-aarch64.tar.bz2";
|
|
|
|
x86_64-linux = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-linux64.tar.bz2";
|
|
|
|
aarch64-darwin = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-macos_arm64.tar.bz2";
|
|
|
|
x86_64-darwin = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-macos_x86_64.tar.bz2";
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
in with passthru; stdenv.mkDerivation {
|
|
|
|
inherit pname version;
|
|
|
|
|
|
|
|
src = fetchurl {
|
2023-01-11 07:51:40 +00:00
|
|
|
url = downloadUrls.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
|
2023-03-04 12:14:45 +00:00
|
|
|
inherit hash;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
buildInputs = [
|
|
|
|
bzip2
|
|
|
|
expat
|
|
|
|
gdbm
|
|
|
|
ncurses6
|
|
|
|
sqlite
|
|
|
|
zlib
|
2023-04-12 12:48:02 +00:00
|
|
|
stdenv.cc.cc.libgcc or null
|
2023-01-11 07:51:40 +00:00
|
|
|
] ++ lib.optionals stdenv.isLinux [
|
|
|
|
tcl-8_5
|
|
|
|
tk-8_5
|
|
|
|
] ++ lib.optionals stdenv.isDarwin [
|
|
|
|
tcl-8_6
|
|
|
|
tk-8_6
|
|
|
|
];
|
|
|
|
|
|
|
|
nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
installPhase = ''
|
2023-01-11 07:51:40 +00:00
|
|
|
runHook preInstall
|
|
|
|
|
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
|
2023-01-11 07:51:40 +00:00
|
|
|
mv $out/bin/libpypy*-c${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/
|
|
|
|
${lib.optionalString stdenv.isLinux ''
|
|
|
|
rm $out/bin/*.debug
|
|
|
|
''}
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
echo "Removing bytecode"
|
2023-01-11 07:51:40 +00:00
|
|
|
find . -name "__pycache__" -type d -depth -delete
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# Include a sitecustomize.py file
|
|
|
|
cp ${../sitecustomize.py} $out/${sitePackages}/sitecustomize.py
|
|
|
|
|
2023-01-11 07:51:40 +00:00
|
|
|
runHook postInstall
|
|
|
|
'';
|
|
|
|
|
|
|
|
preFixup = lib.optionalString stdenv.isLinux ''
|
|
|
|
find $out/{lib,lib_pypy*} -name "*.so" \
|
|
|
|
-exec patchelf \
|
|
|
|
--replace-needed libtinfow.so.6 libncursesw.so.6 \
|
|
|
|
--replace-needed libgdbm.so.4 libgdbm_compat.so.4 {} \;
|
|
|
|
'' + lib.optionalString stdenv.isDarwin ''
|
|
|
|
install_name_tool \
|
|
|
|
-change \
|
|
|
|
@rpath/lib${libPrefix}-c.dylib \
|
|
|
|
$out/lib/lib${libPrefix}-c.dylib \
|
|
|
|
$out/bin/${executable}
|
|
|
|
install_name_tool \
|
|
|
|
-change \
|
|
|
|
@rpath/lib${libPrefix}-c.dylib \
|
|
|
|
$out/lib/lib${libPrefix}-c.dylib \
|
|
|
|
$out/bin/${libPrefix}
|
|
|
|
install_name_tool \
|
|
|
|
-change \
|
|
|
|
/opt/homebrew${lib.optionalString stdenv.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtcl8.6.dylib \
|
|
|
|
${tcl-8_6}/lib/libtcl8.6.dylib \
|
|
|
|
$out/lib/${libPrefix}/_tkinter/*.so
|
|
|
|
install_name_tool \
|
|
|
|
-change \
|
|
|
|
/opt/homebrew${lib.optionalString stdenv.isx86_64 "_x86_64"}/opt/tcl-tk/lib/libtk8.6.dylib \
|
|
|
|
${tk-8_6}/lib/libtk8.6.dylib \
|
|
|
|
$out/lib/${libPrefix}/_tkinter/*.so
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
doInstallCheck = true;
|
|
|
|
|
|
|
|
# Check whether importing of (extension) modules functions
|
|
|
|
installCheckPhase = let
|
|
|
|
modules = [
|
|
|
|
"ssl"
|
|
|
|
"sys"
|
|
|
|
"curses"
|
2023-01-11 07:51:40 +00:00
|
|
|
] ++ lib.optionals (!isPy3k) [
|
2020-04-24 23:36:52 +00:00
|
|
|
"Tkinter"
|
2023-01-11 07:51:40 +00:00
|
|
|
] ++ lib.optionals isPy3k [
|
2020-04-24 23:36:52 +00:00
|
|
|
"tkinter"
|
|
|
|
];
|
2023-01-11 07:51:40 +00:00
|
|
|
imports = lib.concatMapStringsSep "; " (x: "import ${x}") modules;
|
2020-04-24 23:36:52 +00:00
|
|
|
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;
|
2023-01-11 07:51:40 +00:00
|
|
|
platforms = lib.mapAttrsToList (arch: _: arch) downloadUrls;
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|