@@ -404,53 +404,6 @@ public final class UserToolchain: Toolchain {
404404 }
405405#endif
406406
407- /// On MacOS toolchain can shadow SDK content. This method is intended
408- /// to locate and include swift-testing library from a toolchain before
409- /// sdk content which to sure that builds that use a custom toolchain
410- /// always get a custom swift-testing library as well.
411- static func deriveMacOSSpecificSwiftTestingFlags(
412- derivedSwiftCompiler: AbsolutePath ,
413- fileSystem: any FileSystem
414- ) -> ( swiftCFlags: [ String ] , linkerFlags: [ String ] ) {
415- // If this is CommandLineTools all we need to add is a frameworks path.
416- if let frameworksPath = try ? AbsolutePath (
417- validating: " ../../Library/Developer/Frameworks " ,
418- relativeTo: resolveSymlinks ( derivedSwiftCompiler) . parentDirectory
419- ) , fileSystem. exists ( frameworksPath. appending ( " Testing.framework " ) ) {
420- return ( swiftCFlags: [
421- " -F " , frameworksPath. pathString
422- ] , linkerFlags: [
423- " -rpath " , frameworksPath. pathString
424- ] )
425- }
426-
427- guard let toolchainLibDir = try ? toolchainLibDir (
428- swiftCompilerPath: derivedSwiftCompiler
429- ) else {
430- return ( swiftCFlags: [ ] , linkerFlags: [ ] )
431- }
432-
433- let testingLibDir = toolchainLibDir. appending (
434- components: [ " swift " , " macosx " , " testing " ]
435- )
436-
437- let testingPluginsDir = toolchainLibDir. appending (
438- components: [ " swift " , " host " , " plugins " , " testing " ]
439- )
440-
441- guard fileSystem. exists ( testingLibDir) , fileSystem. exists ( testingPluginsDir) else {
442- return ( swiftCFlags: [ ] , linkerFlags: [ ] )
443- }
444-
445- return ( swiftCFlags: [
446- " -I " , testingLibDir. pathString,
447- " -L " , testingLibDir. pathString,
448- " -plugin-path " , testingPluginsDir. pathString
449- ] , linkerFlags: [
450- " -rpath " , testingLibDir. pathString
451- ] )
452- }
453-
454407 internal static func deriveSwiftCFlags(
455408 triple: Triple ,
456409 swiftSDK: SwiftSDK ,
@@ -673,14 +626,33 @@ public final class UserToolchain: Toolchain {
673626 var swiftCompilerFlags : [ String ] = [ ]
674627 var extraLinkerFlags : [ String ] = [ ]
675628
676- if triple. isMacOSX {
677- let ( swiftCFlags, linkerFlags) = Self . deriveMacOSSpecificSwiftTestingFlags (
678- derivedSwiftCompiler: swiftCompilers. compile,
679- fileSystem: fileSystem
680- )
629+ let swiftTestingPath : AbsolutePath ? = try Self . deriveSwiftTestingPath (
630+ derivedSwiftCompiler: swiftCompilers. compile,
631+ swiftSDK: self . swiftSDK,
632+ triple: triple,
633+ environment: environment,
634+ fileSystem: fileSystem
635+ )
636+
637+ if triple. isMacOSX, let swiftTestingPath {
638+ // swift-testing in CommandLineTools, needs extra frameworks search path
639+ if swiftTestingPath. extension == " framework " {
640+ swiftCompilerFlags += [ " -F " , swiftTestingPath. pathString]
641+ }
681642
682- swiftCompilerFlags += swiftCFlags
683- extraLinkerFlags += linkerFlags
643+ // Otherwise we must have a custom toolchain, add overrides to find its swift-testing ahead of any in the
644+ // SDK. We expect the library to be in `lib/swift/macosx/testing` and the plugin in
645+ // `lib/swift/host/plugins/testing`
646+ if let pluginsPath = try ? AbsolutePath (
647+ validating: " ../../host/plugins/testing " ,
648+ relativeTo: swiftTestingPath
649+ ) {
650+ swiftCompilerFlags += [
651+ " -I " , swiftTestingPath. pathString,
652+ " -L " , swiftTestingPath. pathString,
653+ " -plugin-path " , pluginsPath. pathString,
654+ ]
655+ }
684656 }
685657
686658 swiftCompilerFlags += try Self . deriveSwiftCFlags (
@@ -774,19 +746,6 @@ public final class UserToolchain: Toolchain {
774746 )
775747 }
776748
777- let swiftTestingPath : AbsolutePath ?
778- if case . custom( _, let useXcrun) = searchStrategy, !useXcrun {
779- swiftTestingPath = nil
780- } else {
781- swiftTestingPath = try Self . deriveSwiftTestingPath (
782- swiftSDK: self . swiftSDK,
783- triple: triple,
784- environment: environment,
785- fileSystem: fileSystem
786- )
787- }
788-
789-
790749 self . configuration = . init(
791750 librarianPath: librarianPath,
792751 swiftCompilerPath: swiftCompilers. manifest,
@@ -1006,58 +965,75 @@ public final class UserToolchain: Toolchain {
1006965 . appending ( " bin " )
1007966 }
1008967 }
1009- return . none
968+ return nil
1010969 }
1011970
971+ /// Find the swift-testing path if it is within a path that will need extra search paths.
1012972 private static func deriveSwiftTestingPath(
973+ derivedSwiftCompiler: AbsolutePath ,
1013974 swiftSDK: SwiftSDK ,
1014975 triple: Triple ,
1015976 environment: Environment ,
1016977 fileSystem: any FileSystem
1017978 ) throws -> AbsolutePath ? {
1018- guard triple. isWindows ( ) else {
1019- return nil
1020- }
979+ if triple. isDarwin ( ) {
980+ // If this is CommandLineTools all we need to add is a frameworks path.
981+ if let frameworksPath = try ? AbsolutePath (
982+ validating: " ../../Library/Developer/Frameworks " ,
983+ relativeTo: resolveSymlinks ( derivedSwiftCompiler) . parentDirectory
984+ ) , fileSystem. exists ( frameworksPath. appending ( " Testing.framework " ) ) {
985+ return frameworksPath
986+ }
1021987
1022- guard let ( platform, info) = getWindowsPlatformInfo (
1023- swiftSDK: swiftSDK,
1024- environment: environment,
1025- fileSystem: fileSystem
1026- ) else {
1027- return nil
1028- }
988+ guard let toolchainLibDir = try ? toolchainLibDir ( swiftCompilerPath: derivedSwiftCompiler) else {
989+ return nil
990+ }
1029991
1030- guard let swiftTestingVersion = info. defaults. swiftTestingVersion else {
1031- return nil
1032- }
992+ let testingLibDir = toolchainLibDir. appending ( components: [ " swift " , " macosx " , " testing " ] )
993+ if fileSystem. exists ( testingLibDir) {
994+ return testingLibDir
995+ }
996+ } else if triple. isWindows ( ) {
997+ guard let ( platform, info) = getWindowsPlatformInfo (
998+ swiftSDK: swiftSDK,
999+ environment: environment,
1000+ fileSystem: fileSystem
1001+ ) else {
1002+ return nil
1003+ }
10331004
1034- let swiftTesting : AbsolutePath =
1035- platform. appending ( " Developer " )
1036- . appending ( " Library " )
1037- . appending ( " Testing- \( swiftTestingVersion) " )
1038-
1039- let binPath : AbsolutePath ? = switch triple. arch {
1040- case . x86_64: // amd64 x86_64 x86_64h
1041- swiftTesting. appending ( " usr " )
1042- . appending ( " bin64 " )
1043- case . x86: // i386 i486 i586 i686 i786 i886 i986
1044- swiftTesting. appending ( " usr " )
1045- . appending ( " bin32 " )
1046- case . arm: // armv7 and many more
1047- swiftTesting. appending ( " usr " )
1048- . appending ( " bin32a " )
1049- case . aarch64: // aarch6 arm64
1050- swiftTesting. appending ( " usr " )
1051- . appending ( " bin64a " )
1052- default :
1053- nil
1054- }
1005+ guard let swiftTestingVersion = info. defaults. swiftTestingVersion else {
1006+ return nil
1007+ }
10551008
1056- guard let path = binPath, fileSystem. exists ( path) else {
1057- return nil
1009+ let swiftTesting : AbsolutePath =
1010+ platform. appending ( " Developer " )
1011+ . appending ( " Library " )
1012+ . appending ( " Testing- \( swiftTestingVersion) " )
1013+
1014+ let binPath : AbsolutePath ? = switch triple. arch {
1015+ case . x86_64: // amd64 x86_64 x86_64h
1016+ swiftTesting. appending ( " usr " )
1017+ . appending ( " bin64 " )
1018+ case . x86: // i386 i486 i586 i686 i786 i886 i986
1019+ swiftTesting. appending ( " usr " )
1020+ . appending ( " bin32 " )
1021+ case . arm: // armv7 and many more
1022+ swiftTesting. appending ( " usr " )
1023+ . appending ( " bin32a " )
1024+ case . aarch64: // aarch6 arm64
1025+ swiftTesting. appending ( " usr " )
1026+ . appending ( " bin64a " )
1027+ default :
1028+ nil
1029+ }
1030+
1031+ if let path = binPath, fileSystem. exists ( path) {
1032+ return path
1033+ }
10581034 }
10591035
1060- return path
1036+ return nil
10611037 }
10621038
10631039 public var sdkRootPath : AbsolutePath ? {
@@ -1084,7 +1060,7 @@ public final class UserToolchain: Toolchain {
10841060 configuration. xctestPath
10851061 }
10861062
1087- public var swiftTestingPathOnWindows : AbsolutePath ? {
1063+ public var swiftTestingPath : AbsolutePath ? {
10881064 configuration. swiftTestingPath
10891065 }
10901066
0 commit comments