swift-http-types
swift-http-types copied to clipboard
`import HTTPTypesFoundation` pulls in `FoundationNetworking`
Unfortunately, import HTTPTypesFoundation pulls in FoundationNetworking unconditionally which has issues on Linux.
We carry link-time checks to make sure that we're not accidentally using URLSession in places where it's important not to. Unfortunately, modules that import HTTPTypesFoundation now also pull in FoundationNetworking.
Would it be possible to remove the import FoundationNetworking and move that to a separate module like HTTPTypesFoundationNetworking?
Does this require a major version bump due to source breakages?
Yeah, unfortunately it does due to the leaky nature of Swift imports. In this case it a "cheap" major, and we can encourage users to depend on a cross-major range.
Yeah, unfortunately it does due to the leaky nature of Swift imports. In this case it a "cheap" major, and we can encourage users to depend on a cross-major range.
Yes, thank you! A "cheap major" is perfect here. We've done this before and asking users to do "1.0.0" ..< "3.0.0" is usually not a problem. Especially because it can be done at any point in time and doesn't break stuff either way.
I checked and URLRequest and URLResponse are both in FoundationNetworking. HTTPTypesFoundation would have no API at all if it doesn't import FoundationNetworking.
Why do these packages import HTTPTypesFoundation?
I checked and URLRequest and URLResponse are both in FoundationNetworking.
HTTPTypesFoundationwould have no API at all if it doesn't import FoundationNetworking.Why do these packages
import HTTPTypesFoundation?
Just for the extension HTTPRequest { public var url: URL? } :)
Oh I see
URL is part of FoundationEssentials, so that could be the only requirement there.
Alternatively, can we move extension HTTPRequest { public var url: URL? } to the main HTTPTypes package? Can we assume that FoundationEssentials exists everywhere?
Alternatively, can we move
extension HTTPRequest { public var url: URL? }to the main HTTPTypes package? Can we assume thatFoundationEssentialsexists everywhere?
I don't think NIOExtras has FoundationEssentials, @Lukasa?
update: I checked, NIOExtras nor anything it depends on currently imports Foundation*.
Correct, currently we don't use FoundationEssentials in NIO-world. I'm not sure how long that state of affairs will last though: the existence of FoundationEssentials relieves many of the constraints of depending on Foundation.
FoundationEssentials is present on all non-Darwin platforms as part of the Swift toolchain. On Darwin it's still just Foundation.
What's the difference between import Foundation and import FoundationEssentials on non-Darwin? Does import FoundationEssentials work on Swift 5.7 or is it more recent?
import FoundationEssentials is available in Swift 6.0 or later. See here for more information on how these are all layered.
Would you recommend that we do something like:
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
Yes that's the recommend pattern to check if it exists and import only that. IMO that's the way we should do it here and move the extension for URL to the main module of this package behind the conditional import.
Are people all OK with moving URL to the main package? I can make a new PR to do that