38
38
import argparse
39
39
from collections import defaultdict
40
40
import logging
41
+ import multiprocessing
41
42
import os
42
43
import shutil
43
44
import subprocess
@@ -434,10 +435,9 @@ def build_xcframeworks(frameworks_path, xcframeworks_path, template_info_plist):
434
435
dest_headers_path )
435
436
436
437
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.
441
441
442
442
Args:
443
443
source_path (str): Source directory containing top level CMakeLists.txt.
@@ -461,8 +461,16 @@ def cmake_configure_and_build(source_path, build_path, toolchain,
461
461
cmd .append ('-DPLATFORM={0}' .format (toolchain_platform ))
462
462
utils .run_command (cmd )
463
463
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
+ """
464
472
# CMake build for os-platform-architecture
465
- cmd = ['cmake' , '--build' , build_path , '-j' , str ( os . cpu_count ()) ]
473
+ cmd = ['cmake' , '--build' , build_path ]
466
474
cmd .append ('--target' )
467
475
cmd .extend (targets )
468
476
utils .run_command (cmd )
@@ -477,6 +485,8 @@ def main():
477
485
args .source_dir = os .path .abspath (args .source_dir )
478
486
479
487
frameworks_path = os .path .join (args .build_dir , 'frameworks' )
488
+ # List of cmake build process that we will be launched in parallel.
489
+ processes = []
480
490
for apple_os in args .os :
481
491
logging .info ("Building for {0}" .format (apple_os ))
482
492
os_config = CONFIG .get (apple_os )
@@ -515,12 +525,25 @@ def main():
515
525
# For tvos builds, we pass a special cmake option PLATFORM to toolchain.
516
526
toolchain_platform = os_platform_variant_config ['toolchain_platform' ] \
517
527
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 )
524
547
525
548
# if we built for all architectures build universal framework as well.
526
549
build_universal_framework (frameworks_path )
0 commit comments