]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42235: [macOS] Use LTO/PGO in build-installer.py with new enough compilers (GH...
authorRonald Oussoren <ronaldoussoren@mac.com>
Mon, 3 May 2021 03:43:52 +0000 (05:43 +0200)
committerGitHub <noreply@github.com>
Mon, 3 May 2021 03:43:52 +0000 (23:43 -0400)
With recent enough compilers we can build binaries with
LTO/PGO on macOS. This patch enables this when building on
macOS 10.15 or later (Xcode 11 or later).

Mac/BuildScript/build-installer.py
Misc/NEWS.d/next/macOS/2020-11-01-17-37-16.bpo-42235.A97_BN.rst [new file with mode: 0644]

index 540b5a0d1b8f93df61d28042bcdb84ec546538b8..ff62096ec6cd4276a0ae18a7e50d277a061b074a 100755 (executable)
@@ -436,6 +436,14 @@ def library_recipes():
 
     return result
 
+def compilerCanOptimize():
+    """
+    Return True iff the default Xcode version can use PGO and LTO
+    """
+    # bpo-42235: The version check is pretty conservative, can be
+    # adjusted after testing
+    mac_ver = tuple(map(int, platform.mac_ver()[0].split('.')))
+    return mac_ver >= (10, 15)
 
 # Instructions for building packages inside the .mpkg.
 def pkg_recipes():
@@ -1176,6 +1184,7 @@ def buildPython():
                "%s "
                "%s "
                "%s "
+               "%s "
                "LDFLAGS='-g -L%s/libraries/usr/local/lib' "
                "CFLAGS='-g -I%s/libraries/usr/local/include' 2>&1"%(
         shellQuote(os.path.join(SRCDIR, 'configure')),
@@ -1188,6 +1197,7 @@ def buildPython():
                             shellQuote(WORKDIR)[1:-1],))[internalTk()],
         (' ', "--with-tcltk-libs='-L%s/libraries/usr/local/lib -ltcl8.6 -ltk8.6'"%(
                             shellQuote(WORKDIR)[1:-1],))[internalTk()],
+        (' ', "--enable-optimizations --with-lto")[compilerCanOptimize()],
         shellQuote(WORKDIR)[1:-1],
         shellQuote(WORKDIR)[1:-1]))
 
diff --git a/Misc/NEWS.d/next/macOS/2020-11-01-17-37-16.bpo-42235.A97_BN.rst b/Misc/NEWS.d/next/macOS/2020-11-01-17-37-16.bpo-42235.A97_BN.rst
new file mode 100644 (file)
index 0000000..eef4fcd
--- /dev/null
@@ -0,0 +1,2 @@
+``Mac/BuildScript/build-installer.py`` will now use "--enable-optimizations"
+and ``--with-lto`` when building on macOS 10.15 or later.