I would like to start a debate around Swift as a cross-platform language. This is something I have been thinking lately and with the release of Swift for TensorFlow has become clearer to me. Currently Swift is advertised as a cross-platform language but its official support is limited to Ubuntu and Apple platforms. This is great for a large number of developers as it covers Apple devices apps, macOS CLI tools and Linux-based server-side services. But if we want to extend Swift user-base to more fields (machine learning, cross-platform libraries and tools, system programming) following the prophetic Swift Global Domination motto, we need to ensure that Swift becomes a real cross-platform language, and this is not possible without proper Windows support.
I think that Windows support is one, if not the one, feature required by Swift to be understood by outsiders as a cross-platform language. Without it, it is extremely difficult to show Swift as a language that can be used to develop out of the Apple ecosystem (even if that is already possible on Linux). Without it, only Apple platforms developers will ever use it for server-side software. To be clear, an extremely big number of companies are Windows-powered environments and their employees (myself included) can easily set up Python, Ruby, Rust, .NET Core, Go or Node when writing some new code, but not Swift.
I think that after ABI stability is completed in Swift 5, one of the big objectives of the next release should be to complete the cross-platform story with Windows support and finalizing Swift Foundation. What does the Swift community think about the lacking Windows support, its importance and how it should evolve?
I think I agree with with you better Windows support is a must for getting more traction around Swift from what I understand someone like compnerd is working a lot toward(from what I can decipher from Compnerd PR’s) having a better Windows support.
I hope soon someone maybe Apple step up a put an CI for Windows until then you can actually help if you want to https://swift.org/blog/swift-community-hosted-ci/ that will at least help against regression on Windows.
BTW supporting Windows seems to be way more work than supporting Linux…
I think that first class support for Windows is a critical thing, and I doubt anyone in the Swift community would object to it. The problem is that we need to find someone who wants it badly enough and has the resources/know-how to make it happen.
I think the big issue here is that there is a chicken/egg problem: there is low interest between Windows developers about Swift because Swift is not supported on Windows.
Also, Apple has little incentive to move forward in that direction so the push would have to come from the community.
Do we have any idea what’s holding Swift back from supporting Windows? Has the work been scoped at all?
I’d like to add that for people like myself who teach CS in higher education this is one of two closely related issues blocking Swift adoption, the other being the lack of tooling on non-Apple platforms.
I actively promote Swift and would like nothing more than to adopt it as a first programming language for new students, but that will never happen without proper cross-platform support and tools.
@compnerd is the expert on this AFAIK.
I think there are a few other things which continue to affect Swift’s adoption outside of Apple platforms:
- Lack of online and downloadable documentation, similar to swiftdocs.org. That would include whatever’s generated from the header docs as well as long form documentation, available in a variety of formats (Dash docset?), and including the ability to see documentation for released versions as well as
master, and perhaps other branches. Built in API diffing would be great too.
- Lack of a centralized and searchable package database with full SPM (and Xcode!) integration, similar to CocoaPods. Users must be able to find Swift packages and easily integrate them. Going as far as CocoaPods does and offering the ability to fully render documentation, showing testing levels, and other info would also be great.
- More officially supported platforms that are well maintained, as it’s not enough that the language builds on a platform. Swift is still a pain to build on Linux, and even the official Ubuntu support hasn’t expanded above 16.10. I should be able to easily install Swift from any major package manager without having to manually include dependencies. I am glad there’s a semi-official Docker image though.
Without these things, Swift’s adoption outside Apple’s platforms will be limited to those already familiar with Swift wanting to use it on some other platform.
Indeed. But fwiw, if you don’t need to build it,
swiftenv is a really good option.
IMO, Docker is the way to go. Windows, macOS, all Linux distributions (not only Ubuntu).
Docker is ok to test Linux support from macOS or Windows but it doesn’t solve any other problem.
Building Windows tools and libraries with Swift still requires full native Swift support. Extending Swift usage out of the Apple-platform ecosystem still requires full native cross-platform Swift support, easy to install packages like any other popular language has for each platform (
.msi in Windows,
.pkg/Xcode in macOS, and
yum in Linux) and a good package manager.
I strongly agree that improved cross-platform support is requisite to the goal of Swift Global Domination, though I would disagree that Windows support alone is enough to complete it :D.
Is there anybody from an applicable department from Microsoft in this thread or on this forum? Microsoft previously implemented support for Objective-C for the Universal Windows Platform, and it’s kind of surprised me that they haven’t yet jumped on doing the same for Swift. If Microsoft has any interest in Swift running on Windows, I think their participation would be tremendously beneficial. And it would benefit both Microsoft’s interest in Swift and our interest in Windows if as much of that work as is reasonable happened in the main Swift repositories as a first-class supported platform.
(Tangentially, I think Android is up there with Windows as the biggest fish for cross-platform support. And personally, I’ve also strongly felt for a long time that Swift is going to be an awesome language for video game development, but that would ultimately require Swift to be on game consoles, and I recognize that’s getting pretty niche. But I think my broader point is that for Swift to achieve World Domination, I think that long term it’s probably going to need to be about as readily available on any platform as C.)
Indeed. That’s the end-game, right there.
I think that the Windows support is actually within reach. There is a fair amount that is currently working. The bigger items are a couple of ABI issues (Value Witness Tables need to be emitted everywhere, some indirection needs to be adjusted, etc). Getting the test suite passing would certainly help find these types of issues.
Another thing that would be nice would be CI support (if someone is willing to donate the necessary machines). A good chunk of the test suite is passing, but there are failures across the board and not enough people looking at it. New regressions keep coming up. This would also allow regular snapshots which would make it easier for others to get started.
The current build instructions are pretty up to date and should allow most people to get started with swift on Windows. At this point, I think that it is an issue of people willing to work on the issues rather than anything else. Most of the problems are technically resolvable.
libdispatch has been ported to cmake, and has most of the issues for Windows ironed out (a couple of functions need implementing). Foundation has a PR to switch to cmake which would allow us to build the entire thing. Once these two pieces are done, XCTest and SPM could also be integrated giving the Windows port parity with the other targets.
Like @compnerd says, full Windows support really isn’t that far away.
It’s technically possible to build Swift programs for Windows right now if you use static linking (i.e. disable DLLImport within your build of Swift), and I don’t notice any issues in the products even though the tests may still pick some things up. We cross-compile our game and engine (built as a SPM project) from Ubuntu for Windows to native Windows x64. In fact, the Vulkan backend in https://github.com/troughton/SwiftFrameGraph was built and tested exclusively on Windows.
In terms of Foundation and Dispatch, we’re reimplementing just the parts we need from Foundation (https://github.com/troughton/SwiftFrameGraph/tree/master/Sources/WindowsOverlays) and using the old DrPizza libdispatch port (https://github.com/DrPizza/libdispatch) for Dispatch, although we’ll switch over to the official version once that’s ready.
Has anyone thought of Swift as an embedded device language (ie not only raspberry pi, but also stuff running busybox, yocto et al.)? I mean it works server-side, desktop (apps and as scripting) and mobile. Would Swift be a feasible choice for embedded?
Yes. But for the general case, where you need very fine-grained control of memory, you'll need ownership semantics (like Rust's). I think that will be coming up soon-ish after ABI stability, because it's a core part of the World Domination indeed.
With ownership semantics, Swift would be very viable for embedded systems.
Yes, I have been toying with using swift for embedded systems development. At this point I haven't done anything serious with it as I am still playing around with it. I agree that it is a viable and safe language for embedded development.
I'm just chiming in to echo @svanimpe. I also teach computer science at the college level (including Swift in our iOS Dev class) and have written a book related to CS education in Swift (Classic Computer Science Problems in Swift). To see Swift adoption outside of an iOS dev course in higher education, you absolutely need Windows support and tooling. Even if the Linux support were stronger, it would not be enough. Many schools have Windows-only labs that programming instruction takes place in.
A related issue is Swift Playgrounds which are at this point in time closely tied to Xcode and the Playgrounds app for iPad. A lot of Swift education material is being distributed through Playgrounds, but these are ultimately not interactively runnable in an open source platform at this time. On Linux, how do you interactively work with a Swift Playground (beyond running the raw .swift files in the bundle), let alone Windows? Building an open Swift Playground runtime using a cross-platform widget kit might be a good project for the community to keep in mind, if there is not already such an effort.