Apple open sources Swift Build

Apple open sources Swift Build

Apple has made Swift Build open source, this being the engine used by Xcode for building Swift projects, with the aim of unifying build systems across Xcode and the existing open-source Swift Package Manager (Swift PM).

According to Apple software engineer Owen Voorhees, the build engine in Swift PM is “fairly simple” compared to that used by the Mac-only Xcode, and having two different ways to build packages has led to “user confusion when the two implementation’s behavior didn’t match.” 

Swift Build is now on GitHub under the Apache 2.0 license. There are plugins for supporting targets including Android, Apple platforms, Linux, QNX (an embedded operating system) and Windows. Features of the build system include support for project types including libraries, command-line and GUI applications, and optimization to maximize parallelism when building Swift and C code.

The Swift Package Manager continues to use its own build engine by default, but using the flag –build-system swiftbuild enables the new build engine. Voorhees said that Apple intends to collaborate with the community to complete the work of using a unified build execution engine “across all platforms.”

Developers can expect some friction. A developer reported an early issue that “swift-run crashes when using the swiftbuild build system”

Swift is widely used on Apple platforms but not yet for cross-platform. SwiftUI, the GUI framework for Swift, has no cross-platform support unless you count iOS, iPadOS, macOS, tvOS and watchOS. Unfiying the build system will help though, since currently developers use a different build system in Xcode than when working with Swift on other platforms.

Apple’s news has won a mixed reception from developers. The core question is whether Swift can ever succeed cross-platform or whether it is too much tied to Apple. Xcode, the premier IDE for Swift development, is macOS-only, leaving Visual Studio Code as the main choice for those working on Linux or Windows. 

This new development “might not achieve much on its own immediately, but this is the key to build a truly multiplatform ecosystem of libraries, tools and applications in Swift,” said an optimistic commentator; while another believed that “Swift can’t evolve or even exist without Apple and so unless you’re Apple, then Swift is too great of a risk.”

One area where Swift has cross-platform potential is for embedded applications. Apple’s Tim Sneath, director of CoreOS and developer tools / frameworks, assured developers that the company is serious about Swift for embedded work and shared links to resources.

That said, cross-platform Swift remains immature, more than ten years after it was released as open source in December 2015.