Swift's Foundation on Linux is missing URLSession?

Maybe I'm going blind but I notice that when import Foundation on Linux, I don't seem to receive URLSession along with the rest of Foundation.

Wasn't the goal of adding Linux/Windows compatibility to allow some network programming etc., which would require URLSession?

On Linux the Foundation framework had the XML and network components split out due to large dependencies. You can get URLSession by importing FoundationNetworking.

1 Like

For using URLSession you’re suggested to add the following snippet:

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

This not only works on Windows/Linux, but also retains compatibility with the upcoming new Foundation.

2 Likes

Note that all the async goodness is still missing on !Apple. There‘s an issue (among dozens of others) and a pull request for it in GitHub, but don‘t expect any progress.

1 Like

To my knowledge async/await does work on Linux (e.g. "modern" Vapor applications use it), and the according pull request to make it work on Windows (x86_64) for non-trivial cases is only two weeks old.

I'm referring to Foundation(Networking)'s URLSession, which got a number of async/await-enabled calls (like download, upload, etc.) at the time Swift 5.5 was released in September 2021. 17 months later they are still not present on !APPLE and the corresponding issues / pull requests are lingering.

4 Likes