setup: drop legacy osx compiler tuning to enable universal builds
authorMatt Harbison <matt_harbison@yahoo.com>
Wed, 04 Jan 2023 13:47:10 -0500
changeset 49958 dd804d83822c
parent 49957 f68b0a5d3211
child 49959 9ea66d166ec7
setup: drop legacy osx compiler tuning to enable universal builds This was triggering deprecation warnings about migrating to `packaging.version` from `distutils` Version classes with `make local`. But rather than migrate that code, let's just get rid of some ~10-12 year old workarounds. As a bonus, the cext libraries that are built are now universal binaries containing x86_64 and arm64 images (at least when built on macOS 11.4 with Xcode 12.5 and the universal version of Python 3.9.13). Several things to note here: - Apple dropped support for 10.15 in Nov 2022, and OS X Lion that is referenced is 10.7 (unsupported since late 2014) - `xcode4` was basically always True because of the `>=` check (10.8 used Xcode 5, and I have Xcode 10.2 on 10.14) - `xcode51` was always False for modern-ish Xcode, because of the exact version string matching - Python 3.8 only supports OS X 10.9+; the Python 3.9.1+ universal installer is macOS 11+ only, and Python 3.10 drops the x86_64 installer to deliver only the universal installer. All of this is to say, the only thing lost by dropping this code on modern Xcode is that `os.environ['ARCHFLAGS'] = ''` is no longer set. But we probably shouldn't be setting that anymore, as shown by the universal libraries now being generated. I was able to `make local` and `python3 run-tests.py --local` with python 3.9.9, Xcode 10.2, and macOS 10.14.6, and didn't incur any more than the usual few test errors, so this should still work on some older versions of macOS.
setup.py
--- a/setup.py	Wed Jan 04 00:20:27 2023 -0500
+++ b/setup.py	Wed Jan 04 13:47:10 2023 -0500
@@ -126,11 +126,7 @@
     DistutilsError,
     DistutilsExecError,
 )
-from distutils.sysconfig import get_python_inc, get_config_var
-from distutils.version import StrictVersion
-
-# Explain to distutils.StrictVersion how our release candidates are versioned
-StrictVersion.version_re = re.compile(r'^(\d+)\.(\d+)(\.(\d+))?-?(rc(\d+))?$')
+from distutils.sysconfig import get_python_inc
 
 
 def write_if_changed(path, content):
@@ -1696,39 +1692,6 @@
     # form W.X.Y.Z, where W,X,Y,Z are numbers in the range 0..65535
     setupversion = setupversion.split(r'+', 1)[0]
 
-if sys.platform == 'darwin' and os.path.exists('/usr/bin/xcodebuild'):
-    version = runcmd(['/usr/bin/xcodebuild', '-version'], {})[1].splitlines()
-    if version:
-        version = version[0].decode('utf-8')
-        xcode4 = version.startswith('Xcode') and StrictVersion(
-            version.split()[1]
-        ) >= StrictVersion('4.0')
-        xcode51 = re.match(r'^Xcode\s+5\.1', version) is not None
-    else:
-        # xcodebuild returns empty on OS X Lion with XCode 4.3 not
-        # installed, but instead with only command-line tools. Assume
-        # that only happens on >= Lion, thus no PPC support.
-        xcode4 = True
-        xcode51 = False
-
-    # XCode 4.0 dropped support for ppc architecture, which is hardcoded in
-    # distutils.sysconfig
-    if xcode4:
-        os.environ['ARCHFLAGS'] = ''
-
-    # XCode 5.1 changes clang such that it now fails to compile if the
-    # -mno-fused-madd flag is passed, but the version of Python shipped with
-    # OS X 10.9 Mavericks includes this flag. This causes problems in all
-    # C extension modules, and a bug has been filed upstream at
-    # http://bugs.python.org/issue21244. We also need to patch this here
-    # so Mercurial can continue to compile in the meantime.
-    if xcode51:
-        cflags = get_config_var('CFLAGS')
-        if cflags and re.search(r'-mno-fused-madd\b', cflags) is not None:
-            os.environ['CFLAGS'] = (
-                os.environ.get('CFLAGS', '') + ' -Qunused-arguments'
-            )
-
 setup(
     name='mercurial',
     version=setupversion,