@@ -292,14 +292,19 @@ def build(args):
292292 """Builds SwiftPM using a two-step process: first using CMake, then with itself."""
293293 parse_build_args (args )
294294
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+
295298 # Build llbuild if its build path is not passed in.
296299 if not args .llbuild_build_dir :
297300 build_llbuild (args )
298301
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+
303308 build_swiftpm_with_cmake (args )
304309 build_swiftpm_with_swiftpm (args ,integrated_swift_driver = False )
305310
@@ -433,7 +438,7 @@ def install_binary(args, binary, dest_dir):
433438# Build functions
434439# -----------------------------------------------------------
435440
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 = [] ):
437442 """Runs CMake if needed, then builds with Ninja."""
438443 cache_path = os .path .join (build_dir , "CMakeCache.txt" )
439444 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):
461466 if args .verbose :
462467 ninja_cmd .append ("-v" )
463468
469+ ninja_cmd += targets
470+
464471 call (ninja_cmd , cwd = build_dir , verbose = args .verbose )
465472
466473def build_llbuild (args ):
@@ -558,19 +565,27 @@ def build_swiftpm_with_cmake(args):
558565 """Builds SwiftPM using CMake."""
559566 note ("Building SwiftPM (with CMake)" )
560567
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" ]
568579
569580 if platform .system () == 'Darwin' :
570581 cmake_flags .append ("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target (args ), g_macos_deployment_target ))
571582 cmake_flags .append ("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
572583
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 )
574589
575590 if args .llbuild_link_framework :
576591 add_rpath_for_cmake_build (args , args .llbuild_build_dir )
@@ -582,15 +597,22 @@ def build_swiftpm_with_cmake(args):
582597
583598def build_swiftpm_with_swiftpm (args , integrated_swift_driver ):
584599 """Builds SwiftPM using the version of SwiftPM built with CMake."""
585- note ("Building SwiftPM (with swift-build)" )
586600
587601 swiftpm_args = [
588602 "SWIFT_EXEC=" + args .swiftc_path ,
589603 "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" ,
593604 ]
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+
594616 if integrated_swift_driver :
595617 swiftpm_args .append ("--use-integrated-swift-driver" )
596618
@@ -660,19 +682,20 @@ def get_swiftpm_env_cmd(args):
660682 env_cmd .append ("SWIFTCI_USE_LOCAL_DEPS=1" )
661683 env_cmd .append ("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
662684
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" ])
671694
672- if platform .system () == 'Darwin' :
673- env_cmd .append ("DYLD_LIBRARY_PATH=%s" % libs_joined )
674- else :
675- env_cmd .append ("LD_LIBRARY_PATH=%s" % libs_joined )
695+ if platform .system () == 'Darwin' :
696+ env_cmd .append ("DYLD_LIBRARY_PATH=%s" % libs_joined )
697+ else :
698+ env_cmd .append ("LD_LIBRARY_PATH=%s" % libs_joined )
676699
677700 return env_cmd
678701
0 commit comments