Skip to content

Commit e786563

Browse files
committed
lang/python39: Fix for macOS 11 and Apple Silicon
(Apple Silicon being their aarch64 platform.) Patches consist of: - Upstream work: python/cpython#22855 - Fix for setup.py to find libbz2.tbd and libz.tbd now that with the shared library cache there's nothing in /usr/lib. See: https://bugs.python.org/issue41116 - Addition of __arch64__ case to fix _decimal module. A very similar fix has since been committed upstream.
1 parent 6dd49a5 commit e786563

24 files changed

Lines changed: 2910 additions & 24 deletions

lang/python39/distinfo

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,41 @@
1-
$NetBSD: distinfo,v 1.1 2020/10/10 20:19:47 adam Exp $
1+
$NetBSD: distinfo,v 1.2 2020/11/12 10:58:20 sjmulder Exp $
22

33
SHA1 (Python-3.9.0.tar.xz) = ff1fc8c37d5d4b09ec3bf0d84f3e5b97745c6704
44
RMD160 (Python-3.9.0.tar.xz) = 822fd1ea11f3ca303a08317f6db61f2a1e03e5ef
55
SHA512 (Python-3.9.0.tar.xz) = b141039c9701a8cb0d15cd11a279153077524af4d0599e7d2c7279d4c18d05fda06b33ef82342d875de996c7117b7dc6eb154dc3669d38a1efa99801aeec6c5e
66
Size (Python-3.9.0.tar.xz) = 18866140 bytes
7+
SHA1 (patch-Lib___osx__support.py) = 4ccccb81381cd7bf4a8bbc3e376d1234cf2266d5
8+
SHA1 (patch-Lib_ctypes_macholib_dyld.py) = d7f3e0c63d6926db253fbe923dd97995478d528c
9+
SHA1 (patch-Lib_ctypes_test_test__macholib.py) = bd887357759975b7a497c4079bc730e9c578ceed
710
SHA1 (patch-Lib_ctypes_util.py) = 032cc99ebad93ddddfd89073c60424a952e3faa3
811
SHA1 (patch-Lib_distutils_command_install.py) = 6fc6f5d918b7581fc62cd0fe55857ee932c3a341
912
SHA1 (patch-Lib_distutils_sysconfig.py) = 6822eafb4dfded86d7f7353831816aeb8119e6cf
13+
SHA1 (patch-Lib_distutils_tests_test__build__ext.py) = 145a0f01b3602c582e033081a35d4d86245575f9
1014
SHA1 (patch-Lib_distutils_unixccompiler.py) = 2e65a8dd5dd3fe25957206c062106fa7a6fc4e69
1115
SHA1 (patch-Lib_lib2to3_pgen2_driver.py) = 5d6dab14197f27363394ff1aeee22a8ced8026d2
1216
SHA1 (patch-Lib_sysconfig.py) = a4f009ed73ebbd9d9c4bf7e12b7981182ed8fd7c
17+
SHA1 (patch-Lib_test_test__bytes.py) = 72559fdcb09f2c0b0c7b62649c249775d359d72e
18+
SHA1 (patch-Lib_test_test__platform.py) = 36311733729ac95159b3177dc0c16e6f4aa2f2b9
19+
SHA1 (patch-Lib_test_test__unicode.py) = 14fe4dd1011dbe262459f735a643774e0d38c99e
20+
SHA1 (patch-Mac_BuildScript_build-installer.py) = 24641c70facfded736ccc2be069d0e2ae63f63fd
21+
SHA1 (patch-Mac_Tools_pythonw.c) = fe128efe942853f0825c1a1fa17842201716dfdf
1322
SHA1 (patch-Makefile.pre.in) = d42f9f5bca1dd663f64122dc95b49111452fe6e8
23+
SHA1 (patch-Modules___ctypes_callbacks.c) = 95750090d396a647fc12f7f7fad8c591ca4dcdec
24+
SHA1 (patch-Modules___ctypes_callproc.c) = 86f27c466a67ebf72d863febece33aa8b1f9f719
25+
SHA1 (patch-Modules___ctypes_ctypes.h) = 641c0af4d550c9140549ce2f2df6239c2c954a06
26+
SHA1 (patch-Modules___ctypes_malloc__closure.c) = 7e8f491ce66acb6d07e8830ee881edbf0aaac538
27+
SHA1 (patch-Modules___decimal_libmpdec_mpdecimal.h) = 8d302abacc5737fe7620d4738fff6c5c3ed387c7
28+
SHA1 (patch-Modules_getpath.c) = d7114d21d7d9c7167fad259b115cb02e4153c531
1429
SHA1 (patch-Modules_makesetup) = a06786eebffadecedba5e3a50a9785fb47613567
1530
SHA1 (patch-Modules_nismodule.c) = 1bafe9b06359586d027a77011b103877590d947d
31+
SHA1 (patch-Modules_posixmodule.c) = c592ef4ebe650f672a15ff9887cbeed2ca73b666
1632
SHA1 (patch-Modules_socketmodule.c) = 02c447f980a08e2185df78d2f13373574f414304
1733
SHA1 (patch-Modules_socketmodule.h) = 61fe96a79d4ccf3e7768eb79dd7e29a50a85328b
34+
SHA1 (patch-Modules_timemodule.c) = 8c8e9e43b6d165c1a7df6142a6bcd430003ed165
35+
SHA1 (patch-Python_bootstrap__hash.c) = cbc2839675182a344591ba672187b166f166499b
36+
SHA1 (patch-Python_pytime.c) = 1bb39b7060c1f337562208dc6611672eaf2f586b
1837
SHA1 (patch-Python_thread__pthread.h) = fb81eaa604b4ed7c1b64c3f4731d58a8aee257be
19-
SHA1 (patch-configure) = fdb9594b1f738c38672bf247dd91da95d9160a3c
20-
SHA1 (patch-pyconfig.h.in) = 4bc6e95441cb5faae94d1d52aeaaa10ae01385b6
21-
SHA1 (patch-setup.py) = 5cd3600318a883a4308b0bb2d51e3feadf9f5ff5
38+
SHA1 (patch-configure) = 371a65a2cb10fe7709d30a16358b48bc2e0a4aa6
39+
SHA1 (patch-configure.ac) = 4ce75ef922e015adf095cb481c829b11c0454efe
40+
SHA1 (patch-pyconfig.h.in) = 7c1c997c089f882fbd334b81c04a03dbaebb2c41
41+
SHA1 (patch-setup.py) = a9e467f8aed7085a982af6a1273b883550d06610
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
$NetBSD: patch-Lib___osx__support.py,v 1.1 2020/11/12 10:58:21 sjmulder Exp $
2+
3+
Support for macOS 11 and Apple Silicon (ARM). Backported from:
4+
https://github.com/python/cpython/pull/22855
5+
6+
--- Lib/_osx_support.py.orig 2020-10-05 15:07:58.000000000 +0000
7+
+++ Lib/_osx_support.py
8+
@@ -110,6 +110,26 @@ def _get_system_version():
9+
10+
return _SYSTEM_VERSION
11+
12+
+_SYSTEM_VERSION_TUPLE = None
13+
+def _get_system_version_tuple():
14+
+ """
15+
+ Return the macOS system version as a tuple
16+
+
17+
+ The return value is safe to use to compare
18+
+ two version numbers.
19+
+ """
20+
+ global _SYSTEM_VERSION_TUPLE
21+
+ if _SYSTEM_VERSION_TUPLE is None:
22+
+ osx_version = _get_system_version()
23+
+ if osx_version:
24+
+ try:
25+
+ _SYSTEM_VERSION_TUPLE = tuple(int(i) for i in osx_version.split('.'))
26+
+ except ValueError:
27+
+ _SYSTEM_VERSION_TUPLE = ()
28+
+
29+
+ return _SYSTEM_VERSION_TUPLE
30+
+
31+
+
32+
def _remove_original_values(_config_vars):
33+
"""Remove original unmodified values for testing"""
34+
# This is needed for higher-level cross-platform tests of get_platform.
35+
@@ -132,14 +152,18 @@ def _supports_universal_builds():
36+
# builds, in particular -isysroot and -arch arguments to the compiler. This
37+
# is in support of allowing 10.4 universal builds to run on 10.3.x systems.
38+
39+
- osx_version = _get_system_version()
40+
- if osx_version:
41+
- try:
42+
- osx_version = tuple(int(i) for i in osx_version.split('.'))
43+
- except ValueError:
44+
- osx_version = ''
45+
+ osx_version = _get_system_version_tuple()
46+
return bool(osx_version >= (10, 4)) if osx_version else False
47+
48+
+def _supports_arm64_builds():
49+
+ """Returns True if arm64 builds are supported on this system"""
50+
+ # There are two sets of systems supporting macOS/arm64 builds:
51+
+ # 1. macOS 11 and later, unconditionally
52+
+ # 2. macOS 10.15 with Xcode 12.2 or later
53+
+ # For now the second category is ignored.
54+
+ osx_version = _get_system_version_tuple()
55+
+ return osx_version >= (11, 0) if osx_version else False
56+
+
57+
58+
def _find_appropriate_compiler(_config_vars):
59+
"""Find appropriate C compiler for extension module builds"""
60+
@@ -331,6 +355,12 @@ def compiler_fixup(compiler_so, cc_args)
61+
except ValueError:
62+
break
63+
64+
+ elif not _supports_arm64_builds():
65+
+ # Look for "-arch arm64" and drop that
66+
+ for idx in range(len(compiler_so)):
67+
+ if compiler_so[idx] == '-arch' and compiler_so[idx+1] == "arm64":
68+
+ del compiler_so[idx:idx+2]
69+
+
70+
if 'ARCHFLAGS' in os.environ and not stripArch:
71+
# User specified different -arch flags in the environ,
72+
# see also distutils.sysconfig
73+
@@ -481,6 +511,8 @@ def get_platform_osx(_config_vars, osnam
74+
75+
if len(archs) == 1:
76+
machine = archs[0]
77+
+ elif archs == ('arm64', 'x86_64'):
78+
+ machine = 'universal2'
79+
elif archs == ('i386', 'ppc'):
80+
machine = 'fat'
81+
elif archs == ('i386', 'x86_64'):
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
$NetBSD: patch-Lib_ctypes_macholib_dyld.py,v 1.1 2020/11/12 10:58:21 sjmulder Exp $
2+
3+
Support for macOS 11 and Apple Silicon (ARM). Backported from:
4+
https://github.com/python/cpython/pull/22855
5+
6+
--- Lib/ctypes/macholib/dyld.py.orig 2020-10-05 15:07:58.000000000 +0000
7+
+++ Lib/ctypes/macholib/dyld.py
8+
@@ -6,6 +6,11 @@ import os
9+
from ctypes.macholib.framework import framework_info
10+
from ctypes.macholib.dylib import dylib_info
11+
from itertools import *
12+
+try:
13+
+ from _ctypes import _dyld_shared_cache_contains_path
14+
+except ImportError:
15+
+ def _dyld_shared_cache_contains_path(*args):
16+
+ raise NotImplementedError
17+
18+
__all__ = [
19+
'dyld_find', 'framework_find',
20+
@@ -122,8 +127,15 @@ def dyld_find(name, executable_path=None
21+
dyld_executable_path_search(name, executable_path),
22+
dyld_default_search(name, env),
23+
), env):
24+
+
25+
if os.path.isfile(path):
26+
return path
27+
+ try:
28+
+ if _dyld_shared_cache_contains_path(path):
29+
+ return path
30+
+ except NotImplementedError:
31+
+ pass
32+
+
33+
raise ValueError("dylib %s could not be found" % (name,))
34+
35+
def framework_find(fn, executable_path=None, env=None):
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
$NetBSD: patch-Lib_ctypes_test_test__macholib.py,v 1.1 2020/11/12 10:58:21 sjmulder Exp $
2+
3+
Support for macOS 11 and Apple Silicon (ARM). Backported from:
4+
https://github.com/python/cpython/pull/22855
5+
6+
--- Lib/ctypes/test/test_macholib.py.orig 2020-10-05 15:07:58.000000000 +0000
7+
+++ Lib/ctypes/test/test_macholib.py
8+
@@ -45,19 +45,22 @@ def find_lib(name):
9+
class MachOTest(unittest.TestCase):
10+
@unittest.skipUnless(sys.platform == "darwin", 'OSX-specific test')
11+
def test_find(self):
12+
-
13+
- self.assertEqual(find_lib('pthread'),
14+
- '/usr/lib/libSystem.B.dylib')
15+
+ # On Mac OS 11, system dylibs are only present in the shared cache,
16+
+ # so symlinks like libpthread.dylib -> libSystem.B.dylib will not
17+
+ # be resolved by dyld_find
18+
+ self.assertIn(find_lib('pthread'),
19+
+ ('/usr/lib/libSystem.B.dylib', '/usr/lib/libpthread.dylib'))
20+
21+
result = find_lib('z')
22+
# Issue #21093: dyld default search path includes $HOME/lib and
23+
# /usr/local/lib before /usr/lib, which caused test failures if
24+
# a local copy of libz exists in one of them. Now ignore the head
25+
# of the path.
26+
- self.assertRegex(result, r".*/lib/libz\..*.*\.dylib")
27+
+ self.assertRegex(result, r".*/lib/libz.*\.dylib")
28+
29+
- self.assertEqual(find_lib('IOKit'),
30+
- '/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit')
31+
+ self.assertIn(find_lib('IOKit'),
32+
+ ('/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit',
33+
+ '/System/Library/Frameworks/IOKit.framework/IOKit'))
34+
35+
if __name__ == "__main__":
36+
unittest.main()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
$NetBSD: patch-Lib_distutils_tests_test__build__ext.py,v 1.1 2020/11/12 10:58:21 sjmulder Exp $
2+
3+
--- Lib/distutils/tests/test_build_ext.py.orig 2020-10-05 15:07:58.000000000 +0000
4+
+++ Lib/distutils/tests/test_build_ext.py
5+
@@ -492,7 +492,7 @@ class BuildExtTestCase(TempdirManager,
6+
# format the target value as defined in the Apple
7+
# Availability Macros. We can't use the macro names since
8+
# at least one value we test with will not exist yet.
9+
- if target[1] < 10:
10+
+ if target[:2] < (10, 10):
11+
# for 10.1 through 10.9.x -> "10n0"
12+
target = '%02d%01d0' % target
13+
else:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$NetBSD: patch-Lib_test_test__bytes.py,v 1.1 2020/11/12 10:58:21 sjmulder Exp $
2+
3+
Support for macOS 11 and Apple Silicon (ARM). Backported from:
4+
https://github.com/python/cpython/pull/22855
5+
6+
--- Lib/test/test_bytes.py.orig 2020-10-05 15:07:58.000000000 +0000
7+
+++ Lib/test/test_bytes.py
8+
@@ -1034,6 +1034,7 @@ class BytesTest(BaseBytesTest, unittest.
9+
c_char_p)
10+
11+
PyBytes_FromFormat = pythonapi.PyBytes_FromFormat
12+
+ PyBytes_FromFormat.argtypes = (c_char_p,)
13+
PyBytes_FromFormat.restype = py_object
14+
15+
# basic tests
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$NetBSD: patch-Lib_test_test__platform.py,v 1.1 2020/11/12 10:58:21 sjmulder Exp $
2+
3+
Support for macOS 11 and Apple Silicon (ARM). Backported from:
4+
https://github.com/python/cpython/pull/22855
5+
6+
--- Lib/test/test_platform.py.orig 2020-10-05 15:07:58.000000000 +0000
7+
+++ Lib/test/test_platform.py
8+
@@ -245,7 +245,7 @@ class PlatformTest(unittest.TestCase):
9+
self.assertEqual(res[1], ('', '', ''))
10+
11+
if sys.byteorder == 'little':
12+
- self.assertIn(res[2], ('i386', 'x86_64'))
13+
+ self.assertIn(res[2], ('i386', 'x86_64', 'arm64'))
14+
else:
15+
self.assertEqual(res[2], 'PowerPC')
16+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
$NetBSD: patch-Lib_test_test__unicode.py,v 1.1 2020/11/12 10:58:21 sjmulder Exp $
2+
3+
Support for macOS 11 and Apple Silicon (ARM). Backported from:
4+
https://github.com/python/cpython/pull/22855
5+
6+
--- Lib/test/test_unicode.py.orig 2020-10-05 15:07:58.000000000 +0000
7+
+++ Lib/test/test_unicode.py
8+
@@ -2523,11 +2523,13 @@ class CAPITest(unittest.TestCase):
9+
def test_from_format(self):
10+
support.import_module('ctypes')
11+
from ctypes import (
12+
+ c_char_p,
13+
pythonapi, py_object, sizeof,
14+
c_int, c_long, c_longlong, c_ssize_t,
15+
c_uint, c_ulong, c_ulonglong, c_size_t, c_void_p)
16+
name = "PyUnicode_FromFormat"
17+
_PyUnicode_FromFormat = getattr(pythonapi, name)
18+
+ _PyUnicode_FromFormat.argtypes = (c_char_p,)
19+
_PyUnicode_FromFormat.restype = py_object
20+
21+
def PyUnicode_FromFormat(format, *args):
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
$NetBSD: patch-Mac_BuildScript_build-installer.py,v 1.1 2020/11/12 10:58:21 sjmulder Exp $
2+
3+
Support for macOS 11 and Apple Silicon (ARM). Backported from:
4+
https://github.com/python/cpython/pull/22855
5+
6+
--- Mac/BuildScript/build-installer.py.orig 2020-10-05 15:07:58.000000000 +0000
7+
+++ Mac/BuildScript/build-installer.py
8+
@@ -116,7 +116,8 @@ WORKDIR = "/tmp/_py"
9+
DEPSRC = os.path.join(WORKDIR, 'third-party')
10+
DEPSRC = os.path.expanduser('~/Universal/other-sources')
11+
12+
-universal_opts_map = { '32-bit': ('i386', 'ppc',),
13+
+universal_opts_map = { 'universal2': ('arm64', 'x86_64'),
14+
+ '32-bit': ('i386', 'ppc',),
15+
'64-bit': ('x86_64', 'ppc64',),
16+
'intel': ('i386', 'x86_64'),
17+
'intel-32': ('i386',),
18+
@@ -124,6 +125,7 @@ universal_opts_map = { '32-bit': ('i386'
19+
'3-way': ('ppc', 'i386', 'x86_64'),
20+
'all': ('i386', 'ppc', 'x86_64', 'ppc64',) }
21+
default_target_map = {
22+
+ 'universal2': '10.9',
23+
'64-bit': '10.5',
24+
'3-way': '10.5',
25+
'intel': '10.5',
26+
@@ -190,6 +192,27 @@ EXPECTED_SHARED_LIBS = {}
27+
def internalTk():
28+
return getDeptargetTuple() >= (10, 6)
29+
30+
+
31+
+def tweak_tcl_build(basedir, archList):
32+
+ with open("Makefile", "r") as fp:
33+
+ contents = fp.readlines()
34+
+
35+
+ # For reasons I don't understand the tcl configure script
36+
+ # decides that some stdlib symbols aren't present, before
37+
+ # deciding that strtod is broken.
38+
+ new_contents = []
39+
+ for line in contents:
40+
+ if line.startswith("COMPAT_OBJS"):
41+
+ # note: the space before strtod.o is intentional,
42+
+ # the detection of a broken strtod results in
43+
+ # "fixstrod.o" on this line.
44+
+ for nm in ("strstr.o", "strtoul.o", " strtod.o"):
45+
+ line = line.replace(nm, "")
46+
+ new_contents.append(line)
47+
+
48+
+ with open("Makefile", "w") as fp:
49+
+ fp.writelines(new_contents)
50+
+
51+
# List of names of third party software built with this installer.
52+
# The names will be inserted into the rtf version of the License.
53+
THIRD_PARTY_LIBS = []
54+
@@ -231,6 +257,7 @@ def library_recipes():
55+
'--libdir=/Library/Frameworks/Python.framework/Versions/%s/lib'%(getVersion(),),
56+
],
57+
useLDFlags=False,
58+
+ buildrecipe=tweak_tcl_build,
59+
install='make TCL_LIBRARY=%(TCL_LIBRARY)s && make install TCL_LIBRARY=%(TCL_LIBRARY)s DESTDIR=%(DESTDIR)s'%{
60+
"DESTDIR": shellQuote(os.path.join(WORKDIR, 'libraries')),
61+
"TCL_LIBRARY": shellQuote('/Library/Frameworks/Python.framework/Versions/%s/lib/tcl8.6'%(getVersion())),
62+
@@ -801,6 +828,7 @@ def build_universal_openssl(basedir, arc
63+
arch_opts = {
64+
"i386": ["darwin-i386-cc"],
65+
"x86_64": ["darwin64-x86_64-cc", "enable-ec_nistp_64_gcc_128"],
66+
+ "arm64": ["darwin64-arm64-cc"],
67+
"ppc": ["darwin-ppc-cc"],
68+
"ppc64": ["darwin64-ppc-cc"],
69+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
$NetBSD: patch-Mac_Tools_pythonw.c,v 1.1 2020/11/12 10:58:21 sjmulder Exp $
2+
3+
Support for macOS 11 and Apple Silicon (ARM). Backported from:
4+
https://github.com/python/cpython/pull/22855
5+
6+
--- Mac/Tools/pythonw.c.orig 2020-10-05 15:07:58.000000000 +0000
7+
+++ Mac/Tools/pythonw.c
8+
@@ -95,9 +95,6 @@ setup_spawnattr(posix_spawnattr_t* spawn
9+
size_t count;
10+
cpu_type_t cpu_types[1];
11+
short flags = 0;
12+
-#ifdef __LP64__
13+
- int ch;
14+
-#endif
15+
16+
if ((errno = posix_spawnattr_init(spawnattr)) != 0) {
17+
err(2, "posix_spawnattr_int");
18+
@@ -119,10 +116,16 @@ setup_spawnattr(posix_spawnattr_t* spawn
19+
20+
#elif defined(__ppc__)
21+
cpu_types[0] = CPU_TYPE_POWERPC;
22+
+
23+
#elif defined(__i386__)
24+
cpu_types[0] = CPU_TYPE_X86;
25+
+
26+
+#elif defined(__arm64__)
27+
+ cpu_types[0] = CPU_TYPE_ARM64;
28+
+
29+
#else
30+
# error "Unknown CPU"
31+
+
32+
#endif
33+
34+
if (posix_spawnattr_setbinpref_np(spawnattr, count,
35+
@@ -220,7 +223,8 @@ main(int argc, char **argv) {
36+
/* We're weak-linking to posix-spawnv to ensure that
37+
* an executable build on 10.5 can work on 10.4.
38+
*/
39+
- if (posix_spawn != NULL) {
40+
+
41+
+ if (&posix_spawn != NULL) {
42+
posix_spawnattr_t spawnattr = NULL;
43+
44+
setup_spawnattr(&spawnattr);

0 commit comments

Comments
 (0)