@@ -684,6 +684,21 @@ def build_swiftpm_with_swiftpm(args, integrated_swift_driver):
684
684
685
685
def call_swiftpm (args , cmd , cwd = None ):
686
686
"""Calls a SwiftPM binary with the necessary environment variables and flags."""
687
+
688
+ args .build_target = get_build_target (args , cross_compile = (True if args .cross_compile_config else False ))
689
+
690
+ args .platform_path = None
691
+ for path in args .target_info ["paths" ]["runtimeLibraryPaths" ]:
692
+ args .platform_path = re .search (r"(lib/swift/([^/]+))$" , path )
693
+ if args .platform_path :
694
+ break
695
+
696
+ if not args .platform_path :
697
+ error (
698
+ "the command `%s -print-target-info` didn't return a valid runtime library path"
699
+ % args .swiftc_path
700
+ )
701
+
687
702
full_cmd = get_swiftpm_env_cmd (args ) + cmd + get_swiftpm_flags (args )
688
703
if cwd is None :
689
704
cwd = args .project_root
@@ -731,6 +746,9 @@ def get_swiftpm_env_cmd(args):
731
746
env_cmd .append ("SWIFTCI_USE_LOCAL_DEPS=1" )
732
747
env_cmd .append ("SWIFTPM_MACOS_DEPLOYMENT_TARGET=%s" % g_macos_deployment_target )
733
748
749
+ if not '-macosx' in args .build_target and args .command == 'install' :
750
+ env_cmd .append ("SWIFTCI_INSTALL_RPATH_OS=%s" % args .platform_path .group (2 ))
751
+
734
752
if args .bootstrap :
735
753
libs_joined = ":" .join ([
736
754
os .path .join (args .bootstrap_dir , "lib" ),
@@ -787,67 +805,34 @@ def get_swiftpm_flags(args):
787
805
# On Darwin platforms, a relative rpath is necessary for experimental
788
806
# toolchains that include libraries not part of the OS (e.g. PythonKit or
789
807
# TensorFlow).
790
- if platform . system () == "Darwin" :
808
+ if '-macosx' in args . build_target :
791
809
# rpaths for compatibility libraries
792
810
for lib_path in get_swift_backdeploy_library_paths (args ):
793
811
build_flags .extend (["-Xlinker" , "-rpath" , "-Xlinker" , lib_path ])
794
812
795
- swift_library_rpath_prefix = "@executable_path/../"
796
- elif platform .system () == 'Linux' or platform .system () == 'OpenBSD' :
797
- # `$ORIGIN` is an ELF construct.
798
- swift_library_rpath_prefix = "$ORIGIN/../"
799
- if platform .system () == 'OpenBSD' :
800
- build_flags .extend (["-Xlinker" , "-z" , "-Xlinker" , "origin" ])
801
-
802
- platform_path = None
803
- for path in args .target_info ["paths" ]["runtimeLibraryPaths" ]:
804
- platform_path = re .search (r"(lib/swift/([^/]+))$" , path )
805
- if platform_path :
806
- build_flags .extend (
807
- [
808
- "-Xlinker" ,
809
- "-rpath" ,
810
- "-Xlinker" ,
811
- swift_library_rpath_prefix + platform_path .group (1 ),
812
- ]
813
- )
814
- if platform .system () == 'Linux' :
815
- build_flags .extend (
816
- [
817
- "-Xlinker" ,
818
- "-rpath" ,
819
- "-Xlinker" ,
820
- swift_library_rpath_prefix + '../' + platform_path .group (2 ),
821
- ]
822
- )
823
- break
824
-
825
- if not platform_path :
826
- error (
827
- "the command `%s -print-target-info` didn't return a valid runtime library path"
828
- % args .swiftc_path
813
+ build_flags .extend (
814
+ [
815
+ "-Xlinker" ,
816
+ "-rpath" ,
817
+ "-Xlinker" ,
818
+ "@executable_path/../" + args .platform_path .group (1 ),
819
+ ]
829
820
)
830
821
831
- # Don't use GNU strerror_r on Android.
832
- if 'ANDROID_DATA' in os .environ or (args .cross_compile_hosts and re .match (
833
- 'android-' , args .cross_compile_hosts )):
834
- build_flags .extend (["-Xswiftc" , "-Xcc" , "-Xswiftc" , "-U_GNU_SOURCE" ])
835
-
836
- if platform .system () == "OpenBSD" :
822
+ if '-openbsd' in args .build_target :
823
+ build_flags .extend (["-Xlinker" , "-z" , "-Xlinker" , "origin" ])
837
824
build_flags .extend (["-Xcc" , "-I/usr/local/include" ])
838
825
build_flags .extend (["-Xlinker" , "-L/usr/local/lib" ])
839
826
840
- # On ELF platforms, remove the host toolchain's stdlib absolute rpath from
841
- # installed executables and shared libraries.
842
- if platform .system () != "Darwin" and args .command == 'install' :
843
- build_flags .extend (["-Xswiftc" , "-no-toolchain-stdlib-rpath" ])
827
+ # Don't use GNU strerror_r on Android.
828
+ if '-android' in args .build_target :
829
+ build_flags .extend (["-Xswiftc" , "-Xcc" , "-Xswiftc" , "-U_GNU_SOURCE" ])
844
830
845
- build_target = get_build_target (args )
846
831
cross_compile_hosts = args .cross_compile_hosts
847
832
if cross_compile_hosts :
848
- if re . search ( '-apple-macosx' , build_target ) and re . match ('macosx-' , cross_compile_hosts ):
833
+ if '-apple-macosx' in args . build_target and cross_compile_hosts . startswith ('macosx-' ):
849
834
build_flags += ["--arch" , "x86_64" , "--arch" , "arm64" ]
850
- elif re . match ('android-' , cross_compile_hosts ):
835
+ elif cross_compile_hosts . startswith ('android-' ):
851
836
build_flags .extend (["--destination" , args .cross_compile_config ])
852
837
else :
853
838
error ("cannot cross-compile for %s" % cross_compile_hosts )
0 commit comments