@@ -119,6 +119,10 @@ def add_build_args(parser):
119119 "--release" ,
120120 action = "store_true" ,
121121 help = "enables building SwiftPM in release mode" )
122+ parser .add_argument (
123+ "--skip-cmake-bootstrap" ,
124+ action = "store_true" ,
125+ help = "build with prebuilt package manager in toolchain if it exists" )
122126 parser .add_argument (
123127 "--libswiftpm-install-dir" ,
124128 metavar = 'PATH' ,
@@ -198,6 +202,8 @@ def parse_build_args(args):
198202 args .bootstrap_dir = os .path .join (args .target_dir , "bootstrap" )
199203 args .conf = 'release' if args .release else 'debug'
200204 args .bin_dir = os .path .join (args .target_dir , args .conf )
205+ args .bootstrap = not args .skip_cmake_bootstrap or \
206+ not os .path .exists (os .path .join (os .path .split (args .swiftc_path )[0 ], "swift-build" ))
201207
202208def parse_test_args (args ):
203209 """Parses and cleans arguments necessary for the test action."""
@@ -296,10 +302,12 @@ def build(args):
296302 if not args .llbuild_build_dir :
297303 build_llbuild (args )
298304
299- build_tsc (args )
300- build_yams (args )
301- build_swift_argument_parser (args )
302- build_swift_driver (args )
305+ if args .bootstrap :
306+ build_tsc (args )
307+ build_yams (args )
308+ build_swift_argument_parser (args )
309+ build_swift_driver (args )
310+
303311 build_swiftpm_with_cmake (args )
304312 build_swiftpm_with_swiftpm (args ,integrated_swift_driver = False )
305313
@@ -433,7 +441,7 @@ def install_binary(args, binary, dest_dir):
433441# Build functions
434442# -----------------------------------------------------------
435443
436- def build_with_cmake (args , cmake_args , source_path , build_dir ):
444+ def build_with_cmake (args , cmake_args , source_path , build_dir , targets = [] ):
437445 """Runs CMake if needed, then builds with Ninja."""
438446 cache_path = os .path .join (build_dir , "CMakeCache.txt" )
439447 if args .reconfigure or not os .path .isfile (cache_path ) or not args .swiftc_path in open (cache_path ).read ():
@@ -461,6 +469,8 @@ def build_with_cmake(args, cmake_args, source_path, build_dir):
461469 if args .verbose :
462470 ninja_cmd .append ("-v" )
463471
472+ ninja_cmd += targets
473+
464474 call (ninja_cmd , cwd = build_dir , verbose = args .verbose )
465475
466476def build_llbuild (args ):
@@ -558,19 +568,25 @@ def build_swiftpm_with_cmake(args):
558568 """Builds SwiftPM using CMake."""
559569 note ("Building SwiftPM (with CMake)" )
560570
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- ]
571+ if args .bootstrap :
572+ cmake_flags = [
573+ get_llbuild_cmake_arg (args ),
574+ "-DTSC_DIR=" + os .path .join (args .tsc_build_dir , "cmake/modules" ),
575+ "-DYams_DIR=" + os .path .join (args .yams_build_dir , "cmake/modules" ),
576+ "-DArgumentParser_DIR=" + os .path .join (args .swift_argument_parser_build_dir , "cmake/modules" ),
577+ "-DSwiftDriver_DIR=" + os .path .join (args .swift_driver_build_dir , "cmake/modules" ),
578+ "-DFIND_PM_DEPS:BOOL=YES" ,
579+ ]
580+ else :
581+ cmake_flags = [ "-DFIND_PM_DEPS:BOOL=NO" ]
568582
569583 if platform .system () == 'Darwin' :
570584 cmake_flags .append ("-DCMAKE_C_FLAGS=-target %s%s" % (get_build_target (args ), g_macos_deployment_target ))
571585 cmake_flags .append ("-DCMAKE_OSX_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
572586
573- build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir )
587+ targets = [] if args .bootstrap else ["PD4" , "PD4_2" ]
588+
589+ build_with_cmake (args , cmake_flags , args .project_root , args .bootstrap_dir , targets )
574590
575591 if args .llbuild_link_framework :
576592 add_rpath_for_cmake_build (args , args .llbuild_build_dir )
@@ -582,15 +598,22 @@ def build_swiftpm_with_cmake(args):
582598
583599def build_swiftpm_with_swiftpm (args , integrated_swift_driver ):
584600 """Builds SwiftPM using the version of SwiftPM built with CMake."""
585- note ("Building SwiftPM (with swift-build)" )
586601
587602 swiftpm_args = [
588603 "SWIFT_EXEC=" + args .swiftc_path ,
589604 "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" ,
593605 ]
606+
607+ if args .bootstrap :
608+ note ("Building SwiftPM (with a freshly built swift-build)" )
609+ swiftpm_args .append ("SWIFTPM_PD_LIBS=" + os .path .join (args .bootstrap_dir , "pm" ))
610+ swiftpm_args .append (os .path .join (args .bootstrap_dir , "bin/swift-build" ))
611+ else :
612+ note ("Building SwiftPM (with a prebuilt swift-build)" )
613+ swiftpm_args .append (os .path .join (os .path .split (args .swiftc_path )[0 ], "swift-build" ))
614+
615+ swiftpm_args .append ("--disable-sandbox" )
616+
594617 if integrated_swift_driver :
595618 swiftpm_args .append ("--use-integrated-swift-driver" )
596619
@@ -660,19 +683,20 @@ def get_swiftpm_env_cmd(args):
660683 env_cmd .append ("SWIFTCI_USE_LOCAL_DEPS=1" )
661684 env_cmd .append ("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
662685
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" ])
686+ if args .bootstrap :
687+ libs_joined = ":" .join ([
688+ os .path .join (args .bootstrap_dir , "lib" ),
689+ os .path .join (args .tsc_build_dir , "lib" ),
690+ os .path .join (args .llbuild_build_dir , "lib" ),
691+ os .path .join (args .yams_build_dir , "lib" ),
692+ os .path .join (args .swift_argument_parser_build_dir , "lib" ),
693+ os .path .join (args .swift_driver_build_dir , "lib" ),
694+ ] + args .target_info ["paths" ]["runtimeLibraryPaths" ])
671695
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 )
696+ if platform .system () == 'Darwin' :
697+ env_cmd .append ("DYLD_LIBRARY_PATH=%s" % libs_joined )
698+ else :
699+ env_cmd .append ("LD_LIBRARY_PATH=%s" % libs_joined )
676700
677701 return env_cmd
678702
0 commit comments