@@ -27,10 +27,11 @@ from helpers import note, error, symlink_force, mkdir_p, call, call_output
27
27
28
28
g_macos_deployment_target = '10.15'
29
29
30
+ g_shared_lib_prefix = "lib"
30
31
if platform .system () == 'Darwin' :
31
- g_shared_lib_ext = ".dylib"
32
+ g_shared_lib_suffix = ".dylib"
32
33
else :
33
- g_shared_lib_ext = ".so"
34
+ g_shared_lib_suffix = ".so"
34
35
35
36
def main ():
36
37
parser = argparse .ArgumentParser (description = """
@@ -366,7 +367,7 @@ def install(args):
366
367
"PackageGraph" , "SPMBuildCore" , "Build" ,
367
368
"Xcodeproj" , "Workspace"
368
369
]
369
- install_libswiftpm_dylib (args , "SwiftPM" , args .libswiftpm_install_dir , libswiftpm_modules )
370
+ install_dylib (args , "SwiftPM" , args .libswiftpm_install_dir , libswiftpm_modules )
370
371
371
372
# Install libSwiftPMDataModel if an install directory was provided.
372
373
if args .libswiftpmdatamodel_install_dir :
@@ -377,82 +378,59 @@ def install(args):
377
378
"PackageGraph" , "SPMBuildCore" ,
378
379
"Xcodeproj" , "Workspace"
379
380
]
380
- install_libswiftpm_dylib (args , "SwiftPMDataModel" , args .libswiftpmdatamodel_install_dir , libswiftpmdatamodel_modules )
381
+ install_dylib (args , "SwiftPMDataModel" , args .libswiftpmdatamodel_install_dir , libswiftpmdatamodel_modules )
381
382
383
+ # Installs the SwiftPM tools and runtime support libraries.
382
384
def install_swiftpm (prefix , args ):
383
385
# Install swiftpm binaries.
384
386
for binary in ["swift-build" , "swift-test" , "swift-run" , "swift-package" , "swift-package-collection" ]:
385
387
dest = os .path .join (prefix , "bin" )
386
388
install_binary (args , binary , dest )
387
389
390
+ # On Darwin, also install the swiftpm-xctest-helper tool.
388
391
if platform .system () == 'Darwin' :
389
392
dest = os .path .join (prefix , "libexec" , "swift" , "pm" )
390
393
install_binary (args , "swiftpm-xctest-helper" , dest )
391
394
392
- # Install PackageDescription runtime libraries .
393
- runtime_lib_dest = os .path .join (prefix , "lib" , "swift" , "pm" )
394
- runtime_lib_src = os . path . join (args . bootstrap_dir , "pm" )
395
+ # Install the PackageDescription library and associated modules .
396
+ dest = os .path .join (prefix , "lib" , "swift" , "pm" , "ManifestAPI " )
397
+ install_dylib (args , "PackageDescription" , dest , [ "PackageDescription" ] )
395
398
396
- files_to_install = ["libPackageDescription" + g_shared_lib_ext ]
397
- if platform .system () == 'Darwin' :
398
- files_to_install .append ("PackageDescription.swiftinterface" )
399
- else :
400
- files_to_install .append ("PackageDescription.swiftmodule" )
401
- files_to_install .append ("PackageDescription.swiftdoc" )
402
-
403
- for file in files_to_install :
404
- src = os .path .join (runtime_lib_src , "ManifestAPI" , file )
405
- dest = os .path .join (runtime_lib_dest , "ManifestAPI" , file )
406
- mkdir_p (os .path .dirname (dest ))
407
-
408
- note ("Installing %s to %s" % (src , dest ))
409
-
410
- file_util .copy_file (src , dest , update = 1 )
411
-
412
- files_to_install = ["libPackagePlugin" + g_shared_lib_ext ]
413
- if platform .system () == 'Darwin' :
414
- files_to_install .append ("PackagePlugin.swiftinterface" )
415
- else :
416
- files_to_install .append ("PackagePlugin.swiftmodule" )
417
- files_to_install .append ("PackagePlugin.swiftdoc" )
418
-
419
- for file in files_to_install :
420
- src = os .path .join (runtime_lib_src , "PluginAPI" , file )
421
- dest = os .path .join (runtime_lib_dest , "PluginAPI" , file )
422
- mkdir_p (os .path .dirname (dest ))
423
-
424
- note ("Installing %s to %s" % (src , dest ))
425
-
426
- file_util .copy_file (src , dest , update = 1 )
399
+ # Install the PackagePlugin library and associated modules.
400
+ dest = os .path .join (prefix , "lib" , "swift" , "pm" , "PluginAPI" )
401
+ install_dylib (args , "PackagePlugin" , dest , ["PackagePlugin" ])
427
402
428
403
429
- def install_libswiftpm_dylib (args , library_name , install_dir , module_names ):
430
- # FIXME: Don't hardcode the prefix and suffix.
431
- install_binary (args , "lib" + library_name + ".dylib" , install_dir )
404
+ # Helper function that installs a dynamic library and a set of modules to a particular directory.
405
+ def install_dylib (args , library_name , install_dir , module_names ):
406
+ # Install the dynamic library itself.
407
+ install_binary (args , g_shared_lib_prefix + library_name + g_shared_lib_suffix , install_dir )
432
408
433
- # Install the swiftmodule and swiftdoc files.
409
+ # Install the swiftmodule/swiftinterface and swiftdoc files for all the modules .
434
410
for module in module_names :
435
- install_binary (args , module + ".swiftmodule" , install_dir )
436
- if not args .cross_compile_hosts : # When compiling for multiple arches, swiftdoc is part of the swiftmodule directory
411
+ # If we're cross-compiling, we expect the .swiftmodule to be a directory that contains everything.
412
+ if args .cross_compile_hosts :
413
+ install_binary (args , module + ".swiftmodule" , install_dir )
414
+ else :
415
+ # Otherwise we have either a .swiftinterface or a .swiftmodule, plus a .swiftdoc.
416
+ if os .path .exists (os .path .join (args .bin_dir , module + ".swiftinterface" )):
417
+ install_binary (args , module + ".swiftinterface" , install_dir )
418
+ else :
419
+ install_binary (args , module + ".swiftmodule" , install_dir )
437
420
install_binary (args , module + ".swiftdoc" , install_dir )
438
421
439
- # Install the C headers.
440
- tscclibc_include_dir = os .path .join (args .tsc_source_dir , "Sources/TSCclibc/include" )
441
- tscclibc_include_dir_dest = os .path .join (install_dir , "TSCclibc" )
442
- dir_util .copy_tree (tscclibc_include_dir , tscclibc_include_dir_dest )
443
-
444
422
423
+ # Helper function that installs a single built artifact to a particular directory. The source may be either a file or a directory.
445
424
def install_binary (args , binary , dest_dir ):
446
425
src = os .path .join (args .bin_dir , binary )
447
426
dest = os .path .join (dest_dir , binary )
448
427
449
428
note ("Installing %s to %s" % (src , dest ))
450
-
451
429
mkdir_p (os .path .dirname (dest ))
452
- if os .path .isdir (src ) and args . cross_compile_hosts : # Handle swiftmodule directories if compiling for multiple arches.
453
- dir_util .copy_tree (src , dest )
430
+ if os .path .isdir (src ):
431
+ dir_util .copy_tree (src , dest , update = 1 , verbose = 1 )
454
432
else :
455
- file_util .copy_file (src , dest , update = 1 )
433
+ file_util .copy_file (src , dest , update = 1 , verbose = 1 )
456
434
457
435
# -----------------------------------------------------------
458
436
# Build functions
@@ -647,6 +625,7 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
647
625
if integrated_swift_driver :
648
626
swiftpm_args .append ("--use-integrated-swift-driver" )
649
627
628
+ # Build SwiftPM, including libSwiftPM, all the command line tools, and the current variant of PackageDescription.
650
629
call_swiftpm (args , swiftpm_args )
651
630
652
631
# Setup symlinks that'll allow using swiftpm from the build directory.
@@ -772,7 +751,7 @@ def get_swiftpm_flags(args):
772
751
swift_library_rpath_prefix = "$ORIGIN/../"
773
752
platform_path = None
774
753
for path in args .target_info ["paths" ]["runtimeLibraryPaths" ]:
775
- platform_path = re .search (r"(lib/swift/[^/]+)$" , path )
754
+ platform_path = re .search (r"(lib/swift/( [^/]+) )$" , path )
776
755
if platform_path :
777
756
build_flags .extend (
778
757
[
@@ -782,6 +761,15 @@ def get_swiftpm_flags(args):
782
761
swift_library_rpath_prefix + platform_path .group (1 ),
783
762
]
784
763
)
764
+ if platform .system () == 'Linux' :
765
+ build_flags .extend (
766
+ [
767
+ "-Xlinker" ,
768
+ "-rpath" ,
769
+ "-Xlinker" ,
770
+ swift_library_rpath_prefix + '../' + platform_path .group (2 ),
771
+ ]
772
+ )
785
773
break
786
774
787
775
if not platform_path :
0 commit comments