summary refs log tree commit diff
path: root/pkgs/development/interpreters/python
diff options
context:
space:
mode:
authorWeijia Wang <9713184+wegank@users.noreply.github.com>2023-01-01 16:05:48 +0100
committerWeijia Wang <9713184+wegank@users.noreply.github.com>2023-01-01 16:05:48 +0100
commita440e955e049da9458837c43c8bd08202ef16229 (patch)
treee9fd8cc2e0dfb958c75335c61397e6ad2b0bc78c /pkgs/development/interpreters/python
parent1ca08d4c638a89f2c82bec993f9ca4893faf3241 (diff)
downloadnixpkgs-a440e955e049da9458837c43c8bd08202ef16229.tar
nixpkgs-a440e955e049da9458837c43c8bd08202ef16229.tar.gz
nixpkgs-a440e955e049da9458837c43c8bd08202ef16229.tar.bz2
nixpkgs-a440e955e049da9458837c43c8bd08202ef16229.tar.lz
nixpkgs-a440e955e049da9458837c43c8bd08202ef16229.tar.xz
nixpkgs-a440e955e049da9458837c43c8bd08202ef16229.tar.zst
nixpkgs-a440e955e049da9458837c43c8bd08202ef16229.zip
python3: allow enabling framework on darwin
Diffstat (limited to 'pkgs/development/interpreters/python')
-rw-r--r--pkgs/development/interpreters/python/cpython/default.nix22
1 files changed, 18 insertions, 4 deletions
diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix
index 8d55ea6c39c..0e62723ca51 100644
--- a/pkgs/development/interpreters/python/cpython/default.nix
+++ b/pkgs/development/interpreters/python/cpython/default.nix
@@ -17,6 +17,7 @@
 , libxcrypt
 , self
 , configd
+, darwin
 , autoreconfHook
 , autoconf-archive
 , pkg-config
@@ -41,6 +42,7 @@
 , stripBytecode ? true
 , includeSiteCustomize ? true
 , static ? stdenv.hostPlatform.isStatic
+, enableFramework ? false
 , enableOptimizations ? false
 # enableNoSemanticInterposition is a subset of the enableOptimizations flag that doesn't harm reproducibility.
 # clang starts supporting `-fno-sematic-interposition` with version 10
@@ -65,6 +67,8 @@ assert x11Support -> tcl != null
 
 assert bluezSupport -> bluez != null;
 
+assert enableFramework -> stdenv.isDarwin;
+
 assert lib.assertMsg (reproducibleBuild -> stripBytecode)
   "Deterministic builds require stripping bytecode.";
 
@@ -84,6 +88,8 @@ let
   buildPackages = pkgsBuildHost;
   inherit (passthru) pythonForBuild;
 
+  inherit (darwin.apple_sdk.frameworks) Cocoa;
+
   tzdataSupport = tzdata != null && passthru.pythonAtLeast "3.9";
 
   passthru = let
@@ -125,6 +131,8 @@ let
     ++ optionals x11Support [ tcl tk libX11 xorgproto ]
     ++ optionals (bluezSupport && stdenv.isLinux) [ bluez ]
     ++ optionals stdenv.isDarwin [ configd ])
+
+    ++ optionals enableFramework [ Cocoa ]
     ++ optionals tzdataSupport [ tzdata ];  # `zoneinfo` module
 
   hasDistutilsCxxPatch = !(stdenv.cc.isGNU or false);
@@ -307,8 +315,10 @@ in with passthru; stdenv.mkDerivation {
     "--without-ensurepip"
     "--with-system-expat"
     "--with-system-ffi"
-  ] ++ optionals (!static) [
+  ] ++ optionals (!static && !enableFramework) [
     "--enable-shared"
+  ] ++ optionals enableFramework [
+    "--enable-framework=${placeholder "out"}/Library/Frameworks"
   ] ++ optionals enableOptimizations [
     "--enable-optimizations"
   ] ++ optionals enableLTO [
@@ -387,7 +397,11 @@ in with passthru; stdenv.mkDerivation {
     ] ++ optionals tzdataSupport [
       tzdata
     ]);
-  in ''
+  in lib.optionalString enableFramework ''
+    for dir in include lib share; do
+      ln -s $out/Library/Frameworks/Python.framework/Versions/Current/$dir $out/$dir
+    done
+  '' + ''
     # needed for some packages, especially packages that backport functionality
     # to 2.x from 3.x
     for item in $out/lib/${libPrefix}/test/*; do
@@ -484,7 +498,7 @@ in with passthru; stdenv.mkDerivation {
   # Enforce that we don't have references to the OpenSSL -dev package, which we
   # explicitly specify in our configure flags above.
   disallowedReferences =
-    lib.optionals (openssl' != null && !static) [ openssl'.dev ]
+    lib.optionals (openssl' != null && !static && !enableFramework) [ openssl'.dev ]
     ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
     # Ensure we don't have references to build-time packages.
     # These typically end up in shebangs.
@@ -518,7 +532,7 @@ in with passthru; stdenv.mkDerivation {
       high level dynamic data types.
     '';
     license = licenses.psfl;
-    platforms = with platforms; linux ++ darwin;
+    platforms = platforms.linux ++ platforms.darwin;
     maintainers = with maintainers; [ fridh ];
   };
 }