Skip to content

Commit e08059e

Browse files
bpo-42235: [macOS] Use LTO/PGO in build-installer.py with new enough compilers (pythonGH-23079)
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).
1 parent 8c598db commit e08059e

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

Mac/BuildScript/build-installer.py

+10
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,14 @@ def library_recipes():
436436

437437
return result
438438

439+
def compilerCanOptimize():
440+
"""
441+
Return True iff the default Xcode version can use PGO and LTO
442+
"""
443+
# bpo-42235: The version check is pretty conservative, can be
444+
# adjusted after testing
445+
mac_ver = tuple(map(int, platform.mac_ver()[0].split('.')))
446+
return mac_ver >= (10, 15)
439447

440448
# Instructions for building packages inside the .mpkg.
441449
def pkg_recipes():
@@ -1176,6 +1184,7 @@ def buildPython():
11761184
"%s "
11771185
"%s "
11781186
"%s "
1187+
"%s "
11791188
"LDFLAGS='-g -L%s/libraries/usr/local/lib' "
11801189
"CFLAGS='-g -I%s/libraries/usr/local/include' 2>&1"%(
11811190
shellQuote(os.path.join(SRCDIR, 'configure')),
@@ -1188,6 +1197,7 @@ def buildPython():
11881197
shellQuote(WORKDIR)[1:-1],))[internalTk()],
11891198
(' ', "--with-tcltk-libs='-L%s/libraries/usr/local/lib -ltcl8.6 -ltk8.6'"%(
11901199
shellQuote(WORKDIR)[1:-1],))[internalTk()],
1200+
(' ', "--enable-optimizations --with-lto")[compilerCanOptimize()],
11911201
shellQuote(WORKDIR)[1:-1],
11921202
shellQuote(WORKDIR)[1:-1]))
11931203

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
``Mac/BuildScript/build-installer.py`` will now use "--enable-optimizations"
2+
and ``--with-lto`` when building on macOS 10.15 or later.

0 commit comments

Comments
 (0)