Skip to content

Commit 14c99c8

Browse files
committed
multiprocess cmake build
1 parent b7e9235 commit 14c99c8

File tree

1 file changed

+34
-11
lines changed

1 file changed

+34
-11
lines changed

scripts/gha/build_ios_tvos.py

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import argparse
3939
from collections import defaultdict
4040
import logging
41+
import multiprocessing
4142
import os
4243
import shutil
4344
import subprocess
@@ -434,10 +435,9 @@ def build_xcframeworks(frameworks_path, xcframeworks_path, template_info_plist):
434435
dest_headers_path)
435436

436437

437-
def cmake_configure_and_build(source_path, build_path, toolchain,
438-
archive_output_path, targets,
439-
architecture=None, toolchain_platform=None):
440-
"""CMake configure build project and build libraries.
438+
def cmake_configure(source_path, build_path, toolchain, archive_output_path,
439+
architecture=None, toolchain_platform=None):
440+
"""CMake configure which sets up the build project.
441441
442442
Args:
443443
source_path (str): Source directory containing top level CMakeLists.txt.
@@ -461,8 +461,16 @@ def cmake_configure_and_build(source_path, build_path, toolchain,
461461
cmd.append('-DPLATFORM={0}'.format(toolchain_platform))
462462
utils.run_command(cmd)
463463

464+
465+
def cmake_build(build_path, targets):
466+
"""CMake build which builds all libraries.
467+
468+
Args:
469+
build_path (str): CMake build path (where project is built).
470+
targets (list(str)): CMake build targets. (eg: firebase_auth, etc)
471+
"""
464472
# CMake build for os-platform-architecture
465-
cmd = ['cmake', '--build', build_path, '-j', str(os.cpu_count())]
473+
cmd = ['cmake', '--build', build_path]
466474
cmd.append('--target')
467475
cmd.extend(targets)
468476
utils.run_command(cmd)
@@ -477,6 +485,8 @@ def main():
477485
args.source_dir = os.path.abspath(args.source_dir)
478486

479487
frameworks_path = os.path.join(args.build_dir, 'frameworks')
488+
# List of cmake build process that we will be launched in parallel.
489+
processes = []
480490
for apple_os in args.os:
481491
logging.info("Building for {0}".format(apple_os))
482492
os_config = CONFIG.get(apple_os)
@@ -515,12 +525,25 @@ def main():
515525
# For tvos builds, we pass a special cmake option PLATFORM to toolchain.
516526
toolchain_platform = os_platform_variant_config['toolchain_platform'] \
517527
if apple_os == 'tvos' else None
518-
cmake_configure_and_build(args.source_dir, build_path,
519-
os_platform_variant_config['toolchain'],
520-
archive_output_path, supported_targets,
521-
architecture, toolchain_platform)
522-
# Arrange frameworks
523-
arrange_frameworks(archive_output_path)
528+
# CMake configure was having all sorts of issues when run in parallel.
529+
# It might be the Cocoapods that are downloaded in parallel into a
530+
# single cache directory.
531+
cmake_configure(args.source_dir, build_path,
532+
os_platform_variant_config['toolchain'],
533+
archive_output_path, architecture,
534+
toolchain_platform)
535+
process = multiprocessing.Process(target=cmake_build,
536+
args=(build_path, supported_targets))
537+
processes.append((process, archive_output_path))
538+
539+
# Launch all cmake build processes in parallel.
540+
for process, _ in processes:
541+
process.start()
542+
543+
for process, archive_output_path in processes:
544+
process.wait()
545+
# Reorganize frameworks (renaming, copying over headers etc)
546+
arrange_frameworks(archive_output_path)
524547

525548
# if we built for all architectures build universal framework as well.
526549
build_universal_framework(frameworks_path)

0 commit comments

Comments
 (0)