Skip to content

Commit 65a1fed

Browse files
committed
macos: add --optimized argument to control PGO/LTO
And make non-PGO the default. This matches the behavior of Linux.
1 parent 53fdde9 commit 65a1fed

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

build-macos.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# License, v. 2.0. If a copy of the MPL was not distributed with this
44
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
55

6+
import argparse
67
import datetime
78
import os
89
import pathlib
@@ -22,6 +23,11 @@
2223

2324

2425
def bootstrap():
26+
parser = argparse.ArgumentParser()
27+
parser.add_argument('--optimized', action='store_true')
28+
29+
args = parser.parse_args()
30+
2531
BUILD.mkdir(exist_ok=True)
2632
DIST.mkdir(exist_ok=True)
2733

@@ -33,6 +39,10 @@ def bootstrap():
3339
os.environ['PYBUILD_BOOTSTRAPPED'] = '1'
3440
os.environ['PATH'] = '%s:%s' % (str(VENV / 'bin'), os.environ['PATH'])
3541
os.environ['PYTHONPATH'] = str(ROOT)
42+
43+
if args.optimized:
44+
os.environ['PYBUILD_OPTIMIZED'] = '1'
45+
3646
subprocess.run([str(PYTHON), __file__], check=True)
3747

3848

@@ -45,10 +55,20 @@ def run():
4555
subprocess.run(['make'],
4656
cwd=str(MAKE_DIR), check=True)
4757

48-
source_path = BUILD / 'cpython-macos.tar'
58+
basename = 'cpython-macos'
59+
extra = ''
60+
61+
if 'PYBUILD_OPTIMIZED' in os.environ:
62+
basename += '-pgo'
63+
extra = '-pgo'
64+
65+
basename += '.tar'
66+
67+
source_path = BUILD / basename
4968

50-
compress_python_archive(source_path, DIST, 'cpython-%s-macos-%s' % (
51-
DOWNLOADS['cpython-3.7']['version'], now.strftime('%Y%m%dT%H%M')))
69+
compress_python_archive(source_path, DIST, 'cpython-%s-macos%s-%s' % (
70+
DOWNLOADS['cpython-3.7']['version'], extra,
71+
now.strftime('%Y%m%dT%H%M')))
5272

5373

5474
if __name__ == '__main__':

cpython-macos/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PLATFORM := macos
99

1010
TOOLCHAIN_DEPENDENCIES := $(OUTDIR)/clang-macos.tar
1111

12-
default: $(OUTDIR)/cpython-macos.tar
12+
default: $(OUTDIR)/cpython-macos$(if $(PYBUILD_OPTIMIZED),-pgo,).tar
1313

1414
$(OUTDIR)/clang-macos.tar: $(HERE)/build-clang.sh
1515
$(BUILD) clang
@@ -63,3 +63,6 @@ PYTHON_DEPENDS := \
6363

6464
$(OUTDIR)/cpython-macos.tar: $(PYTHON_DEPENDS)
6565
$(BUILD) cpython
66+
67+
$(OUTDIR)/cpython-macos-pgo.tar: $(PYTHON_DEPENDS)
68+
$(BUILD) --optimized cpython

cpython-macos/build.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def process_setup_line(line):
285285
return bi
286286

287287

288-
def build_cpython():
288+
def build_cpython(optimized=False):
289289
python_archive = download_entry('cpython-3.7', BUILD)
290290
python_version = DOWNLOADS['cpython-3.7']['version']
291291

@@ -343,7 +343,8 @@ def build_cpython():
343343
env['MACOSX_DEPLOYMENT_TARGET'] = MACOSX_DEPLOYMENT_TARGET
344344
env['NUM_CPUS'] = '%s' % multiprocessing.cpu_count()
345345

346-
env['CPYTHON_OPTIMIZED'] = '1'
346+
if optimized:
347+
env['CPYTHON_OPTIMIZED'] = '1'
347348

348349
exec_and_log([SUPPORT / 'build-cpython.sh'], td, env)
349350

@@ -367,7 +368,14 @@ def build_cpython():
367368
with (td / 'out' / 'python' / 'PYTHON.json').open('w') as fh:
368369
json.dump(python_info, fh, sort_keys=True, indent=4)
369370

370-
dest_path = BUILD / 'cpython-macos.tar'
371+
basename = 'cpython-macos'
372+
373+
if optimized:
374+
basename += '-pgo'
375+
376+
basename += '.tar'
377+
378+
dest_path = BUILD / basename
371379

372380
with dest_path.open('wb') as fh:
373381
create_tar_from_directory(fh, td / 'out')
@@ -377,6 +385,7 @@ def main():
377385
BUILD.mkdir(exist_ok=True)
378386

379387
parser = argparse.ArgumentParser()
388+
parser.add_argument('--optimized', action='store_true')
380389
parser.add_argument('action')
381390

382391
args = parser.parse_args()
@@ -396,7 +405,7 @@ def main():
396405
build_clang()
397406

398407
elif action == 'cpython':
399-
build_cpython()
408+
build_cpython(optimized=args.optimized)
400409

401410
else:
402411
print('unknown build action: %s' % action)

0 commit comments

Comments
 (0)