@@ -410,23 +410,24 @@ public final class UserToolchain: Toolchain {
410410 static func deriveMacOSSpecificSwiftTestingFlags(
411411 derivedSwiftCompiler: AbsolutePath ,
412412 fileSystem: any FileSystem
413- ) -> [ String ] {
413+ ) -> ( swiftCFlags : [ String ] , linkerFlags : [ String ] ) {
414414 // If this is CommandLineTools all we need to add is a frameworks path.
415415 if let frameworksPath = try ? AbsolutePath (
416416 validating: " ../../Library/Developer/Frameworks " ,
417417 relativeTo: resolveSymlinks ( derivedSwiftCompiler) . parentDirectory
418418 ) , fileSystem. exists ( frameworksPath. appending ( " Testing.framework " ) ) {
419- return [
419+ return ( swiftCFlags : [
420420 " -F " , frameworksPath. pathString,
421+ ] , linkerFlags: [
421422 " -Xlinker " , " -rpath " ,
422- " -Xlinker " , frameworksPath. pathString
423- ]
423+ " -Xlinker " , frameworksPath. pathString,
424+ ] )
424425 }
425426
426427 guard let toolchainLibDir = try ? toolchainLibDir (
427428 swiftCompilerPath: derivedSwiftCompiler
428429 ) else {
429- return [ ]
430+ return ( swiftCFlags : [ ] , linkerFlags : [ ] )
430431 }
431432
432433 let testingLibDir = toolchainLibDir. appending (
@@ -438,15 +439,16 @@ public final class UserToolchain: Toolchain {
438439 )
439440
440441 guard fileSystem. exists ( testingLibDir) , fileSystem. exists ( testingPluginsDir) else {
441- return [ ]
442+ return ( swiftCFlags : [ ] , linkerFlags : [ ] )
442443 }
443444
444- return [
445+ return ( swiftCFlags : [
445446 " -I " , testingLibDir. pathString,
446447 " -L " , testingLibDir. pathString,
447448 " -plugin-path " , testingPluginsDir. pathString,
449+ ] , linkerFlags: [
448450 " -Xlinker " , " -rpath " , " -Xlinker " , testingLibDir. pathString,
449- ]
451+ ] )
450452 }
451453
452454 internal static func deriveSwiftCFlags(
@@ -669,11 +671,15 @@ public final class UserToolchain: Toolchain {
669671 self . targetTriple = triple
670672
671673 var swiftCompilerFlags : [ String ] = [ ]
674+ var extraLinkerFlags : [ String ] = [ ]
675+
672676 #if os(macOS)
673- swiftCompilerFlags + = Self . deriveMacOSSpecificSwiftTestingFlags (
677+ let ( swiftCFlags , linkerFlags ) = Self . deriveMacOSSpecificSwiftTestingFlags (
674678 derivedSwiftCompiler: swiftCompilers. compile,
675679 fileSystem: fileSystem
676680 )
681+ swiftCompilerFlags += swiftCFlags
682+ extraLinkerFlags += linkerFlags
677683 #endif
678684
679685 swiftCompilerFlags += try Self . deriveSwiftCFlags (
@@ -683,11 +689,13 @@ public final class UserToolchain: Toolchain {
683689 fileSystem: fileSystem
684690 )
685691
692+ extraLinkerFlags += swiftSDK. toolset. knownTools [ . linker] ? . extraCLIOptions ?? [ ]
693+
686694 self . extraFlags = BuildFlags (
687695 cCompilerFlags: swiftSDK. toolset. knownTools [ . cCompiler] ? . extraCLIOptions ?? [ ] ,
688696 cxxCompilerFlags: swiftSDK. toolset. knownTools [ . cxxCompiler] ? . extraCLIOptions ?? [ ] ,
689697 swiftCompilerFlags: swiftCompilerFlags,
690- linkerFlags: swiftSDK . toolset . knownTools [ . linker ] ? . extraCLIOptions ?? [ ] ,
698+ linkerFlags: extraLinkerFlags ,
691699 xcbuildFlags: swiftSDK. toolset. knownTools [ . xcbuild] ? . extraCLIOptions ?? [ ] )
692700
693701 self . includeSearchPaths = swiftSDK. pathsConfiguration. includeSearchPaths ?? [ ]
0 commit comments