@@ -2961,8 +2961,10 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
29612961 // NOTE: With Swift in the OS, static libs aren't being supplied by the toolchains
29622962 // so users of this flag will need to provide their own.
29632963 if scope. evaluate ( BuiltinMacros . SWIFT_FORCE_STATIC_LINK_STDLIB, lookup: lookup) {
2964+ print ( " staticallyLinkSwiftStdlib: true " )
29642965 return true
29652966 }
2967+ print ( " staticallyLinkSwiftStdlib: false " )
29662968 return false
29672969 }
29682970
@@ -3001,19 +3003,24 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
30013003 if swiftLibraryPath. isEmpty {
30023004 // Look next to the compiler and in the toolchains for one.
30033005 if shouldStaticLinkStdlib {
3006+ print ( " Finding static lib search paths " )
30043007 swiftLibraryPath = findSearchPathForLibrary ( executablePath: swiftc, possibleNames: [
30053008 " swift_static/ \( platformName) /lib \( swiftStdlibName) .a " ,
30063009 " swift_static/lib \( swiftStdlibName) .a " ,
30073010 " lib \( swiftStdlibName) .a " ,
30083011 ] , toolchains: producer. toolchains) ?? Path ( " " )
30093012 } else {
3013+ print ( " Finding dynamiclib search paths " )
30103014 swiftLibraryPath = findSearchPathForLibrary ( executablePath: swiftc, possibleNames: [
30113015 " swift/ \( platformName) /lib \( swiftStdlibName) . \( dynamicLibraryExtension) " ,
30123016 " swift/lib \( swiftStdlibName) . \( dynamicLibraryExtension) " ,
30133017 " lib \( swiftStdlibName) . \( dynamicLibraryExtension) " ,
30143018 ] , toolchains: producer. toolchains) ?? Path ( " " )
30153019 }
3020+ } else {
3021+ print ( " swiftLibraryPath is not empty. " )
30163022 }
3023+ print ( " ********** swiftLibraryPath are: \( swiftLibraryPath) " )
30173024
30183025 let isMacCatalystUnzippered = producer. sdkVariant? . isMacCatalyst == true && !scope. evaluate ( BuiltinMacros . IS_ZIPPERED, lookup: lookup)
30193026
@@ -3023,12 +3030,12 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
30233030 // TAPI requires absolute paths.
30243031 let sdkroot = scope. evaluate ( BuiltinMacros . SDKROOT, lookup: lookup)
30253032 if !sdkroot. isEmpty {
3026- sdkPathArgument = [ " -L " + sdkroot. join ( " usr/lib/swift " ) . str]
3033+ sdkPathArgument = [ " -L " + sdkroot. join ( " usr/lib/swift_static " ) . str]
30273034 unzipperedSDKPathArgument = [ " -L " + sdkroot. join ( " System/iOSSupport/usr/lib/swift " ) . str]
30283035 }
30293036 } else {
30303037 // ld prefers SDK relative paths.
3031- sdkPathArgument = [ " -L/usr/lib/swift " ]
3038+ sdkPathArgument = [ " -L/usr/lib/swift_static " ]
30323039 unzipperedSDKPathArgument = [ " -L/System/iOSSupport/usr/lib/swift " ]
30333040 }
30343041
@@ -3039,6 +3046,7 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
30393046 }
30403047
30413048 args += [ sdkPathArgument]
3049+ print ( " **** SDK Parth arguments: \( sdkPathArgument) " )
30423050 }
30433051
30443052 // Add the -L to the standard library path. This is used primarily for the OSS toolchain now as each of the libs have been moved into the Swift SDK.
@@ -3061,9 +3069,20 @@ public final class SwiftCompilerSpec : CompilerSpec, SpecIdentifierType, SwiftDi
30613069
30623070 if !forTAPI {
30633071 if shouldStaticLinkStdlib {
3064- args += [ [ " -Xlinker " , " -force_load_swift_libs " ] ]
3065- // The Swift runtime requires libc++ & Foundation.
3066- args += [ [ " -lc++ " , " -framework " , " Foundation " ] ]
3072+ // Platform-specific static linking flags
3073+ // args += [["-Xlinker", "$(LD_FORCE_STATIC_LINK_STDLIB)"]]
3074+ if producer. isApplePlatform {
3075+ // Darwin/Apple platforms use force_load_swift_libs and Framework linking
3076+ args += [ [ " -Xlinker " , " -force_load_swift_libs " ] ]
3077+ args += [ [ " -lc++ " , " -framework " , " Foundation " ] ]
3078+ } else {
3079+ // Non-Apple platforms (Linux, etc.) use static library linking
3080+ // args += [["-lc++", "-framework", "Foundation"]]
3081+ // args += [["-lc++"]]
3082+ args += [ [ " -static-stdlib " ] ]
3083+ // args += [["-Xlinker", "-no-pie"]]
3084+ // Note: Foundation is not available as a framework on non-Apple platforms
3085+ }
30673086 }
30683087
30693088 // Add the AST, if debugging.
0 commit comments