pythonInterpreters.pypy39_prebuilt: add darwin support

This commit is contained in:
Weijia Wang 2023-01-08 02:04:15 +01:00
parent 41e9880694
commit fd6ddd9923
2 changed files with 49 additions and 10 deletions

View file

@ -311,7 +311,12 @@ in {
minor = "3"; minor = "3";
patch = "11"; patch = "11";
}; };
sha256 = "sha256-1QYXLKEQcSdBdddOnFgcMWZDLQF5sDZHDjuejSDq5YE="; # linux64 sha256 = {
aarch64-linux = "sha256-CRddxlLtiV2Y6a1j0haBK/PufjmNkAqb+espBrqDArk=";
x86_64-linux = "sha256-1QYXLKEQcSdBdddOnFgcMWZDLQF5sDZHDjuejSDq5YE=";
aarch64-darwin = "sha256-ka11APGjlTHb76CzRaPc/5J/+ZcWVOjS6e98WuMR9X4=";
x86_64-darwin = "sha256-0z9AsgcJmHJYWv1xhzV1ym6mOKJ9gjvGISOMWuglQu0=";
}.${stdenv.system};
pythonVersion = "3.9"; pythonVersion = "3.9";
inherit passthruFun; inherit passthruFun;
}; };

View file

@ -12,6 +12,8 @@
, sqlite , sqlite
, tcl-8_5 , tcl-8_5
, tk-8_5 , tk-8_5
, tcl-8_6
, tk-8_6
, zlib , zlib
# For the Python package set # For the Python package set
, packageOverrides ? (self: super: {}) , packageOverrides ? (self: super: {})
@ -48,11 +50,18 @@ let
majorVersion = lib.versions.major pythonVersion; majorVersion = lib.versions.major pythonVersion;
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";
};
in with passthru; stdenv.mkDerivation { in with passthru; stdenv.mkDerivation {
inherit pname version; inherit pname version;
src = fetchurl { src = fetchurl {
url = "https://downloads.python.org/pypy/pypy${pythonVersion}-v${version}-linux64.tar.bz2"; url = downloadUrls.${stdenv.system} or (throw "Unsupported system: ${stdenv.system}");
inherit sha256; inherit sha256;
}; };
@ -62,12 +71,16 @@ in with passthru; stdenv.mkDerivation {
gdbm gdbm
ncurses6 ncurses6
sqlite sqlite
zlib
] ++ lib.optionals stdenv.isLinux [
tcl-8_5 tcl-8_5
tk-8_5 tk-8_5
zlib ] ++ lib.optionals stdenv.isDarwin [
tcl-8_6
tk-8_6
]; ];
nativeBuildInputs = [ autoPatchelfHook ]; nativeBuildInputs = lib.optionals stdenv.isLinux [ autoPatchelfHook ];
installPhase = '' installPhase = ''
runHook preInstall runHook preInstall
@ -75,10 +88,10 @@ in with passthru; stdenv.mkDerivation {
mkdir -p $out mkdir -p $out
echo "Moving files to $out" echo "Moving files to $out"
mv -t $out bin include lib mv -t $out bin include lib
mv $out/bin/libpypy*-c${stdenv.hostPlatform.extensions.sharedLibrary} $out/lib/
mv $out/bin/libpypy*-c.so $out/lib/ ${lib.optionalString stdenv.isLinux ''
rm $out/bin/*.debug
rm $out/bin/*.debug ''}
echo "Removing bytecode" echo "Removing bytecode"
find . -name "__pycache__" -type d -depth -delete find . -name "__pycache__" -type d -depth -delete
@ -89,11 +102,32 @@ in with passthru; stdenv.mkDerivation {
runHook postInstall runHook postInstall
''; '';
preFixup = '' preFixup = lib.optionalString stdenv.isLinux ''
find $out/{lib,lib_pypy*} -name "*.so" \ find $out/{lib,lib_pypy*} -name "*.so" \
-exec patchelf \ -exec patchelf \
--replace-needed libtinfow.so.6 libncursesw.so.6 \ --replace-needed libtinfow.so.6 libncursesw.so.6 \
--replace-needed libgdbm.so.4 libgdbm_compat.so.4 {} \; --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
''; '';
doInstallCheck = true; doInstallCheck = true;
@ -126,7 +160,7 @@ in with passthru; stdenv.mkDerivation {
homepage = "http://pypy.org/"; homepage = "http://pypy.org/";
description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})"; description = "Fast, compliant alternative implementation of the Python language (${pythonVersion})";
license = licenses.mit; license = licenses.mit;
platforms = [ "x86_64-linux" ]; platforms = lib.mapAttrsToList (arch: _: arch) downloadUrls;
}; };
} }