You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code having no references to FoundationNetworking causes a crash when compiled with swiftc -static-stdlib:
import Foundation
letstr=tryString(data:Data(contentsOf:URL(string:"https://httpbin.org/get")!), encoding:.utf8)!
print(str)
Data(contentsOf:) weakly (indirectly) links FoundationNetworking, which makes the linker exclude that library from static linking as seemingly unused if that's the only reference to networking in your code using Foundation on Linux.
This snippet works perfectly fine when compiled with swiftc -static-stdlib:
import Foundation
import FoundationNetworking
_ =URLSession.shared
letstr=tryString(data:Data(contentsOf:URL(string:"https://httpbin.org/get")!), encoding:.utf8)!
print(str)
Having a direct reference to symbols in FoundationNetworking (such as URLSession) is a recommended workaround as of Swift 5.7 and 5.6, and is likely to work in Swift 5.5 as well.
We're investigating if other solutions can be implemented in a future version of Swift.
This code having no references to
FoundationNetworking
causes a crash when compiled withswiftc -static-stdlib
:Data(contentsOf:)
weakly (indirectly) linksFoundationNetworking
, which makes the linker exclude that library from static linking as seemingly unused if that's the only reference to networking in your code using Foundation on Linux.This snippet works perfectly fine when compiled with
swiftc -static-stdlib
:Having a direct reference to symbols in FoundationNetworking (such as
URLSession
) is a recommended workaround as of Swift 5.7 and 5.6, and is likely to work in Swift 5.5 as well.We're investigating if other solutions can be implemented in a future version of Swift.
Originally posted by @MaxDesiatov in swiftlang/swift#61372 (comment)
The text was updated successfully, but these errors were encountered: