@@ -670,6 +670,21 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
670
670
671
671
def call_swiftpm (args , cmd , cwd = None ):
672
672
"""Calls a SwiftPM binary with the necessary environment variables and flags."""
673
+
674
+ args .build_target = get_build_target (args , cross_compile = (True if args .cross_compile_config else False ))
675
+
676
+ args .platform_path = None
677
+ for path in args .target_info ["paths" ]["runtimeLibraryPaths" ]:
678
+ args .platform_path = re .search (r"(lib/swift/([^/]+))$" , path )
679
+ if args .platform_path :
680
+ break
681
+
682
+ if not args .platform_path :
683
+ error (
684
+ "the command `%s -print-target-info` didn't return a valid runtime library path"
685
+ % args .swiftc_path
686
+ )
687
+
673
688
full_cmd = get_swiftpm_env_cmd (args ) + cmd + get_swiftpm_flags (args )
674
689
if cwd is None :
675
690
cwd = args .project_root
@@ -717,6 +732,9 @@ def get_swiftpm_env_cmd(args):
717
732
env_cmd .append ("SWIFTCI_USE_LOCAL_DEPS=1" )
718
733
env_cmd .append ("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
719
734
735
+ if not '-macosx' in args .build_target and args .command == 'install' :
736
+ env_cmd .append ("SWIFTCI_INSTALL_RPATH_OS=%s" % args .platform_path .group (2 ))
737
+
720
738
if args .bootstrap :
721
739
libs_joined = ":" .join ([
722
740
os .path .join (args .bootstrap_dir , "lib" ),
@@ -770,67 +788,34 @@ def get_swiftpm_flags(args):
770
788
# On Darwin platforms, a relative rpath is necessary for experimental
771
789
# toolchains that include libraries not part of the OS (e.g. PythonKit or
772
790
# TensorFlow).
773
- if platform . system () == "Darwin" :
791
+ if '-macosx' in args . build_target :
774
792
# rpaths for compatibility libraries
775
793
for lib_path in get_swift_backdeploy_library_paths (args ):
776
794
build_flags .extend (["-Xlinker" , "-rpath" , "-Xlinker" , lib_path ])
777
795
778
- swift_library_rpath_prefix = "@executable_path/../"
779
- elif platform .system () == 'Linux' or platform .system () == 'OpenBSD' :
780
- # `$ORIGIN` is an ELF construct.
781
- swift_library_rpath_prefix = "$ORIGIN/../"
782
- if platform .system () == 'OpenBSD' :
783
- build_flags .extend (["-Xlinker" , "-z" , "-Xlinker" , "origin" ])
784
-
785
- platform_path = None
786
- for path in args .target_info ["paths" ]["runtimeLibraryPaths" ]:
787
- platform_path = re .search (r"(lib/swift/([^/]+))$" , path )
788
- if platform_path :
789
- build_flags .extend (
790
- [
791
- "-Xlinker" ,
792
- "-rpath" ,
793
- "-Xlinker" ,
794
- swift_library_rpath_prefix + platform_path .group (1 ),
795
- ]
796
- )
797
- if platform .system () == 'Linux' :
798
- build_flags .extend (
799
- [
800
- "-Xlinker" ,
801
- "-rpath" ,
802
- "-Xlinker" ,
803
- swift_library_rpath_prefix + '../' + platform_path .group (2 ),
804
- ]
805
- )
806
- break
807
-
808
- if not platform_path :
809
- error (
810
- "the command `%s -print-target-info` didn't return a valid runtime library path"
811
- % args .swiftc_path
796
+ build_flags .extend (
797
+ [
798
+ "-Xlinker" ,
799
+ "-rpath" ,
800
+ "-Xlinker" ,
801
+ "@executable_path/../" + args .platform_path .group (1 ),
802
+ ]
812
803
)
813
804
814
- # Don't use GNU strerror_r on Android.
815
- if 'ANDROID_DATA' in os .environ or (args .cross_compile_hosts and re .match (
816
- 'android-' , args .cross_compile_hosts )):
817
- build_flags .extend (["-Xswiftc" , "-Xcc" , "-Xswiftc" , "-U_GNU_SOURCE" ])
818
-
819
- if platform .system () == "OpenBSD" :
805
+ if '-openbsd' in args .build_target :
806
+ build_flags .extend (["-Xlinker" , "-z" , "-Xlinker" , "origin" ])
820
807
build_flags .extend (["-Xcc" , "-I/usr/local/include" ])
821
808
build_flags .extend (["-Xlinker" , "-L/usr/local/lib" ])
822
809
823
- # On ELF platforms, remove the host toolchain's stdlib absolute rpath from
824
- # installed executables and shared libraries.
825
- if platform .system () != "Darwin" and args .command == 'install' :
826
- build_flags .extend (["-Xswiftc" , "-no-toolchain-stdlib-rpath" ])
810
+ # Don't use GNU strerror_r on Android.
811
+ if '-android' in args .build_target :
812
+ build_flags .extend (["-Xswiftc" , "-Xcc" , "-Xswiftc" , "-U_GNU_SOURCE" ])
827
813
828
- build_target = get_build_target (args )
829
814
cross_compile_hosts = args .cross_compile_hosts
830
815
if cross_compile_hosts :
831
- if re . search ( '-apple-macosx' , build_target ) and re . match ('macosx-' , cross_compile_hosts ):
816
+ if '-apple-macosx' in args . build_target and cross_compile_hosts . startswith ('macosx-' ):
832
817
build_flags += ["--arch" , "x86_64" , "--arch" , "arm64" ]
833
- elif re . match ('android-' , cross_compile_hosts ):
818
+ elif cross_compile_hosts . startswith ('android-' ):
834
819
build_flags .extend (["--destination" , args .cross_compile_config ])
835
820
else :
836
821
error ("cannot cross-compile for %s" % cross_compile_hosts )
0 commit comments