The Swift team stated in the official blog that they have been working with developers on swift.org to port Swift to Windows for more than a year. Now, developers can use Swift to build their own projects in Windows.
Porting Swift to Windows this time is not simply a compiler, but to ensure that the complete Swift ecosystem is available in Windows, including compilers, standard libraries, and core libraries. Saleem Abdulrasool, an engineer of the Swift Core Team, shared the technical details of the porting process at the LLVM Developers Conference in 2019.
The Swift team showed a calculator written entirely in Swift on the official blog:
The calculator was built using the following projects:
- Swift toolchain on Windows
- Visual Studio 2019 and CMake,
- Ninja, and Windows SDK
Although the application was built using CMake, the Swift Package Manager support on Windows will soon be implemented, and the application can be built using swift-build instead of CMake or Ninja. In addition, developers can use LLDB to debug their built applications in Windows:
The blog also stated that Readdle, a manufacturer of efficiency tools, is trying to use Swift to write cross-platform applications. Many existing Swift libraries can be directly ported to Windows to support its applications. Saleem Abdulrasool said that he had worked with Alexander, an engineering director at Readdle, to study how to use Swift to write cross-platform applications. Alexander told him:
“We started experimenting with Swift on Windows more than a year ago. At that time, we had already released the Android version of Spark, so we were very interested in using Spark to share the core code with iOS/macOS and expanding to another platform. Although some features are not yet available, Swift on Windows can fully meet our needs.
All business logic of Spark is located in a separate core module, we call it Core, which also allows us to use any UI framework on the target platform: AppKit for macOS, UIKit for iOS, and UIToolkit for Android. Therefore, we must port Spark Core to Windows. Another challenge is how to implement the user interface. After many discussions, we finally decided to use Electron as the front-end part of the Windows version of Spark.
This means that we need to be able to build Spark Core on Windows, and Spark Core also needs to be a loadable plugin for Node.js. What I want to say is that if you are considering extending your existing application code base to platforms other than macOS/iOS, you can definitely do it with Swift right away. If you want to maintain a small Swift library, you can easily add Windows support!”
Developers can refer to the official tutorial to build Swift projects in Windows.
Since the release of Swift, there have been developers hoping to build iOS/macOS applications in Windows, but Apple has been inactive for many years. In contrast, Microsoft has already ported .NET to iOS and macOS, and .NET is also available on almost all platforms, with complete API support. And now, Apple finally ported Swift to Windows. It seems that both sides want to win this “war”. Microsoft seems to be in the upper hand, while Apple has just taken a small step.