@@ -292,14 +292,19 @@ def build(args):
292
292
"""Builds SwiftPM using a two-step process: first using CMake, then with itself."""
293
293
parse_build_args (args )
294
294
295
+ # Don't bootstrap if the Swift toolchain already has a pre-built swift-build.
296
+ args .bootstrap = not os .path .exists (os .path .join (os .path .split (args .swiftc_path )[0 ], "swift-build" ))
297
+
295
298
# Build llbuild if its build path is not passed in.
296
299
if not args .llbuild_build_dir :
297
300
build_llbuild (args )
298
301
299
- build_tsc (args )
300
- build_yams (args )
301
- build_swift_argument_parser (args )
302
- build_swift_driver (args )
302
+ if args .bootstrap :
303
+ build_tsc (args )
304
+ build_yams (args )
305
+ build_swift_argument_parser (args )
306
+ build_swift_driver (args )
307
+
303
308
build_swiftpm_with_cmake (args )
304
309
build_swiftpm_with_swiftpm (args ,integrated_swift_driver = False )
305
310
@@ -433,7 +438,7 @@ def install_binary(args, binary, dest_dir):
433
438
# Build functions
434
439
# -----------------------------------------------------------
435
440
436
- def build_with_cmake (args , cmake_args , source_path , build_dir ):
441
+ def build_with_cmake (args , cmake_args , source_path , build_dir , targets = [] ):
437
442
"""Runs CMake if needed, then builds with Ninja."""
438
443
cache_path = os .path .join (build_dir , "CMakeCache.txt" )
439
444
if args .reconfigure or not os .path .isfile (cache_path ) or not args .swiftc_path in open (cache_path ).read ():
@@ -461,6 +466,8 @@ def build_with_cmake(args, cmake_args, source_path, build_dir):
461
466
if args .verbose :
462
467
ninja_cmd .append ("-v" )
463
468
469
+ ninja_cmd += targets
470
+
464
471
call (ninja_cmd , cwd = build_dir , verbose = args .verbose )
465
472
466
473
def build_llbuild (args ):
@@ -558,19 +565,27 @@ def build_swiftpm_with_cmake(args):
558
565
"""Builds SwiftPM using CMake."""
559
566
note ("Building SwiftPM (with CMake)" )
560
567
561
- cmake_flags = [
562
- get_llbuild_cmake_arg (args ),
563
- "-DTSC_DIR=" + os .path .join (args .tsc_build_dir , "cmake/modules" ),
564
- "-DYams_DIR=" + os .path .join (args .yams_build_dir , "cmake/modules" ),
565
- "-DArgumentParser_DIR=" + os .path .join (args .swift_argument_parser_build_dir , "cmake/modules" ),
566
- "-DSwiftDriver_DIR=" + os .path .join (args .swift_driver_build_dir , "cmake/modules" ),
567
- ]
568
+ if args .bootstrap :
569
+ cmake_flags = [
570
+ get_llbuild_cmake_arg (args ),
571
+ "-DTSC_DIR=" + os .path .join (args .tsc_build_dir , "cmake/modules" ),
572
+ "-DYams_DIR=" + os .path .join (args .yams_build_dir , "cmake/modules" ),
573
+ "-DArgumentParser_DIR=" + os .path .join (args .swift_argument_parser_build_dir , "cmake/modules" ),
574
+ "-DSwiftDriver_DIR=" + os .path .join (args .swift_driver_build_dir , "cmake/modules" ),
575
+ "-DBOOTSTRAP:BOOL=ON" ,
576
+ ]
577
+ else :
578
+ cmake_flags = [ "-DBOOTSTRAP:BOOL=OFF" ]
568
579
569
580
if platform .system () == 'Darwin' :
570
581
cmake_flags .append ("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target (args ), g_macos_deployment_target ))
571
582
cmake_flags .append ("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
572
583
573
- build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir )
584
+ targets = []
585
+ if not args .bootstrap :
586
+ targets = ["PD4" , "PD4_2" ]
587
+
588
+ build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir , targets )
574
589
575
590
if args .llbuild_link_framework :
576
591
add_rpath_for_cmake_build (args , args .llbuild_build_dir )
@@ -582,15 +597,22 @@ def build_swiftpm_with_cmake(args):
582
597
583
598
def build_swiftpm_with_swiftpm (args , integrated_swift_driver ):
584
599
"""Builds SwiftPM using the version of SwiftPM built with CMake."""
585
- note ("Building SwiftPM (with swift-build)" )
586
600
587
601
swiftpm_args = [
588
602
"SWIFT_EXEC=" + args .swiftc_path ,
589
603
"SWIFT_DRIVER_SWIFT_EXEC=" + args .swiftc_path ,
590
- "SWIFTPM_PD_LIBS=" + os .path .join (args .bootstrap_dir , "pm" ),
591
- os .path .join (args .bootstrap_dir , "bin/swift-build" ),
592
- "--disable-sandbox" ,
593
604
]
605
+
606
+ if args .bootstrap :
607
+ note ("Building SwiftPM (with a freshly built swift-build)" )
608
+ swiftpm_args .append ("SWIFTPM_PD_LIBS=" + os .path .join (args .bootstrap_dir , "pm" ))
609
+ swiftpm_args .append (os .path .join (args .bootstrap_dir , "bin/swift-build" ))
610
+ else :
611
+ note ("Building SwiftPM (with a prebuilt swift-build)" )
612
+ swiftpm_args .append (os .path .join (os .path .split (args .swiftc_path )[0 ], "swift-build" ))
613
+
614
+ swiftpm_args .append ("--disable-sandbox" )
615
+
594
616
if integrated_swift_driver :
595
617
swiftpm_args .append ("--use-integrated-swift-driver" )
596
618
@@ -660,18 +682,19 @@ def get_swiftpm_env_cmd(args):
660
682
env_cmd .append ("SWIFTCI_USE_LOCAL_DEPS=1" )
661
683
env_cmd .append ("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
662
684
663
- libs_joined = ":" .join ([
664
- os .path .join (args .bootstrap_dir , "lib" ),
665
- os .path .join (args .tsc_build_dir , "lib" ),
666
- os .path .join (args .llbuild_build_dir , "lib" ),
667
- os .path .join (args .yams_build_dir , "lib" ),
668
- os .path .join (args .swift_argument_parser_build_dir , "lib" ),
669
- os .path .join (args .swift_driver_build_dir , "lib" ),
670
- ] + args .target_info ["paths" ]["runtimeLibraryPaths" ])
685
+ if args .bootstrap :
686
+ libs_joined = ":" .join ([
687
+ os .path .join (args .bootstrap_dir , "lib" ),
688
+ os .path .join (args .tsc_build_dir , "lib" ),
689
+ os .path .join (args .llbuild_build_dir , "lib" ),
690
+ os .path .join (args .yams_build_dir , "lib" ),
691
+ os .path .join (args .swift_argument_parser_build_dir , "lib" ),
692
+ os .path .join (args .swift_driver_build_dir , "lib" ),
693
+ ] + args .target_info ["paths" ]["runtimeLibraryPaths" ])
671
694
672
695
if platform .system () == 'Darwin' :
673
696
env_cmd .append ("DYLD_LIBRARY_PATH=%s" % libs_joined )
674
- else :
697
+ elif args . bootstrap :
675
698
env_cmd .append ("LD_LIBRARY_PATH=%s" % libs_joined )
676
699
677
700
return env_cmd
0 commit comments