Slide 1

Slide 1 text

Open Source Swift Kenny Tang Swift, a language traditionally used in application programming for Apple devices, has recently been open-sourced, and has gained a lot of attention and momentum, with some people viewing it as a potential competitor to system languages like GO and Rust. Today we’ll look at how far open source Swift has come and what it holds for the future.

Slide 2

Slide 2 text

Open Source Swift 2014 Debut 1.0 1.1 A little bit of history. Work began on Swift in 2010. It made its first public appearance in June 2014.

Slide 3

Slide 3 text

Open Source Swift Swift’s Advance 2014 Debut 1.0 1.1 A little bit of history. Work began on Swift in 2010. It made its first public appearance in June 2014.

Slide 4

Slide 4 text

Open Source Swift Swift’s Advance 2015 1.2 2.0 2.1 In the year that followed - Swift continued its steady march. After a number of revisions and API refinements, it got to a point where it was mature enough to be used in production apps. In June, Apple announced that Swift will be made open source. No-one knew what that meant. Perhaps they were going to put a tar file somewhere and call it a day, the way they treated projects like webkit. People were also skeptical because of how Swift is tightly coupled with Apple’s proprietary platforms. I was one of those people.

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

objc code UIKit Foundation Frameworks Frameworks obj runtime

Slide 7

Slide 7 text

objc code UIKit Foundation Frameworks Frameworks obj runtime To see why, let’s take a look at the role Swift traditionally played in an iOS app. When we add Swift code to an iOS project, Xcode, the IDE, would generate bridging headers for Swift to import and call into cocoa system frameworks like UIKit and Foundation. This interoperability is made possible through LLVM module maps. Now, you can compile Swift code on its own, but it’s not very useful. Swift itself only has a thin core library providing essential features like data structure and type support. For even simple tasks like reading a file, your Swift code has to link against objective-c or system frameworks., most of those proprietary. So it seems like, even if Apple open source Swift, its tight dependence on proprietary frameworks would limit its usability.

Slide 8

Slide 8 text

swift code swift lib objc code UIKit Foundation Frameworks Frameworks obj runtime To see why, let’s take a look at the role Swift traditionally played in an iOS app. When we add Swift code to an iOS project, Xcode, the IDE, would generate bridging headers for Swift to import and call into cocoa system frameworks like UIKit and Foundation. This interoperability is made possible through LLVM module maps. Now, you can compile Swift code on its own, but it’s not very useful. Swift itself only has a thin core library providing essential features like data structure and type support. For even simple tasks like reading a file, your Swift code has to link against objective-c or system frameworks., most of those proprietary. So it seems like, even if Apple open source Swift, its tight dependence on proprietary frameworks would limit its usability.

Slide 9

Slide 9 text

swift code swift lib objc code UIKit Foundation Frameworks Frameworks obj runtime class HelloWorld { func doIt() { print("Yay Hello world!") } } let testObject = HelloWorld() testObject.doIt() > swiftc TestHello.swift && ./TestHello > Yay Hello world! To see why, let’s take a look at the role Swift traditionally played in an iOS app. When we add Swift code to an iOS project, Xcode, the IDE, would generate bridging headers for Swift to import and call into cocoa system frameworks like UIKit and Foundation. This interoperability is made possible through LLVM module maps. Now, you can compile Swift code on its own, but it’s not very useful. Swift itself only has a thin core library providing essential features like data structure and type support. For even simple tasks like reading a file, your Swift code has to link against objective-c or system frameworks., most of those proprietary. So it seems like, even if Apple open source Swift, its tight dependence on proprietary frameworks would limit its usability.

Slide 10

Slide 10 text

swift code swift lib objc code UIKit Foundation Frameworks Frameworks obj runtime To see why, let’s take a look at the role Swift traditionally played in an iOS app. When we add Swift code to an iOS project, Xcode, the IDE, would generate bridging headers for Swift to import and call into cocoa system frameworks like UIKit and Foundation. This interoperability is made possible through LLVM module maps. Now, you can compile Swift code on its own, but it’s not very useful. Swift itself only has a thin core library providing essential features like data structure and type support. For even simple tasks like reading a file, your Swift code has to link against objective-c or system frameworks., most of those proprietary. So it seems like, even if Apple open source Swift, its tight dependence on proprietary frameworks would limit its usability.

Slide 11

Slide 11 text

Open Source Swift 2015 1.2 2.0 2.1

Slide 12

Slide 12 text

Open Source Swift 2.1 In Dec, Apple dropped the 2.2 open source beta of Swift and made their plans clear. Which we’ll look into next. Craig Federighi, their SVP of software, said that their biggest motivation was to make Swift more ubiquitous, and be taught in colleges everywhere.

Slide 13

Slide 13 text

Open Source Swift …to allow Swift be “the language college students learn computer science in”. 2015 DEC 2.2 BETA 2.1 In Dec, Apple dropped the 2.2 open source beta of Swift and made their plans clear. Which we’ll look into next. Craig Federighi, their SVP of software, said that their biggest motivation was to make Swift more ubiquitous, and be taught in colleges everywhere.

Slide 14

Slide 14 text

19 repos To achieve that vision, Apple took this open sourcing thing seriously, and published 19 repos to github, under the Apache 2.0 license. In addition to Swift’s source code, they also released tools that would make Swift much more useful on its own, like a compiler for linux, a package manager that lets you build applications that link with other Swift libraries, and most importantly, re-writes of proprietary frameworks like Foundation in Swift, that provide essential functionalities like IO, networking and threads. Although much of those frameworks are still work-in-progress.

Slide 15

Slide 15 text

19 repos Swift Source Code Linux & OS X compilers Swift Package Manager Foundation Framework Libdispatch.etc. To achieve that vision, Apple took this open sourcing thing seriously, and published 19 repos to github, under the Apache 2.0 license. In addition to Swift’s source code, they also released tools that would make Swift much more useful on its own, like a compiler for linux, a package manager that lets you build applications that link with other Swift libraries, and most importantly, re-writes of proprietary frameworks like Foundation in Swift, that provide essential functionalities like IO, networking and threads. Although much of those frameworks are still work-in-progress.

Slide 16

Slide 16 text

swift code swift lib objc code UIKit Foundation Frameworks Frameworks obj runtime To put it into context what all that meant, let’s go back to this slide.

Slide 17

Slide 17 text

objc code UIKit Foundation Frameworks Frameworks obj runtime swift code swift lib swift package swift package system library + foundation With open source swift, it is possible for swift applications to live on linux platforms like this, with your code bundled with other Swift packages or even calling into system libraries like curl through modulemaps. All ties to objective-c severed.

Slide 18

Slide 18 text

Here’s a short video of getting Swift running in linux. The process is super easy, you can build from source, or grab the pre-compiled binaries. People made pre-built packages on APT.

Slide 19

Slide 19 text

Here’s a short video of getting Swift running in linux. The process is super easy, you can build from source, or grab the pre-compiled binaries. People made pre-built packages on APT.

Slide 20

Slide 20 text

With swift set up in our environment, we can go ahead and build a simple app. What we need is define a Package.swift file and declare our dependencies there, and a main.swift which runs the application. For this example, we’re asking Swift Package Manager to pull in cCURL, and in main.swift we’re importing that into our app, initializing a curl handle, and printing it out.

Slide 21

Slide 21 text

With swift set up in our environment, we can go ahead and build a simple app. What we need is define a Package.swift file and declare our dependencies there, and a main.swift which runs the application. For this example, we’re asking Swift Package Manager to pull in cCURL, and in main.swift we’re importing that into our app, initializing a curl handle, and printing it out.

Slide 22

Slide 22 text

PRs Reviewed by Dev Team Commit Access to Repo Next I want to talk about how the contribution model works. Again it’s surprisingly open, with everyone free to submit PRs. The swift dev team at Apple (7 people) are responsible for reviewing the PRs, and there are clear guidelines, roadmaps and evaluation criteria published in github. Communication and announcements are done through public mailing lists. Contributors with proven track records are given direct commit access to the repos.

Slide 23

Slide 23 text

Community Response In the short 2 months since Dec, the community response has been overwhelming. There are individual contributors are well as companies like IBM sending PRs to fix bugs and complete missing features. One group, PracticalSwift, has submitted about 500 PRs and saw most of them merged. The swift team has also opened up to suggestions on feature or change requests for future versions of Swift. This goes through the same vetting process. And so far, more than 10 proposals have been accepted. The ideas range from small requests like getting rid of C-style for loops and ++ incrementors, to changing the way objective-c bridging headers are translated into swfit.

Slide 24

Slide 24 text

Community Response Long Term Evolution In the short 2 months since Dec, the community response has been overwhelming. There are individual contributors are well as companies like IBM sending PRs to fix bugs and complete missing features. One group, PracticalSwift, has submitted about 500 PRs and saw most of them merged. The swift team has also opened up to suggestions on feature or change requests for future versions of Swift. This goes through the same vetting process. And so far, more than 10 proposals have been accepted. The ideas range from small requests like getting rid of C-style for loops and ++ incrementors, to changing the way objective-c bridging headers are translated into swfit.

Slide 25

Slide 25 text

Community Response Long Term Evolution 40 proposals submitted 8 accepted for Swift 2.2 9 accepted for Swift 3.0 In the short 2 months since Dec, the community response has been overwhelming. There are individual contributors are well as companies like IBM sending PRs to fix bugs and complete missing features. One group, PracticalSwift, has submitted about 500 PRs and saw most of them merged. The swift team has also opened up to suggestions on feature or change requests for future versions of Swift. This goes through the same vetting process. And so far, more than 10 proposals have been accepted. The ideas range from small requests like getting rid of C-style for loops and ++ incrementors, to changing the way objective-c bridging headers are translated into swfit.

Slide 26

Slide 26 text

Finally, here’s a quick list of notable projects from the community, e.g. IBM, who not only released Docker container images with swift pre-installed, but also a web-based swift sandbox, and an experimental app server called Kitura written in Swift, with bindings to redis, crouchDB, mySQL and so on.

Slide 27

Slide 27 text

Finally, here’s a quick list of notable projects from the community, e.g. IBM, who not only released Docker container images with swift pre-installed, but also a web-based swift sandbox, and an experimental app server called Kitura written in Swift, with bindings to redis, crouchDB, mySQL and so on.

Slide 28

Slide 28 text

Finally, here’s a quick list of notable projects from the community, e.g. IBM, who not only released Docker container images with swift pre-installed, but also a web-based swift sandbox, and an experimental app server called Kitura written in Swift, with bindings to redis, crouchDB, mySQL and so on.

Slide 29

Slide 29 text

There’s also no shortage of projects that try to implement a node.js like app server in Swift. Some of the names include PureSwift, Perfect, Vapor and a dozen others. Here’s Vapor serving a JSON response.

Slide 30

Slide 30 text

There’s also no shortage of projects that try to implement a node.js like app server in Swift. Some of the names include PureSwift, Perfect, Vapor and a dozen others. Here’s Vapor serving a JSON response.

Slide 31

Slide 31 text

2.0 2.1 2.2 BETA 3.0 2.2 GM

Slide 32

Slide 32 text

2.2 GM 3.0 2.0 2.1 2.2 BETA 2016 In the current stage, things are still fairly chaotic and unstable. I ran into a lot of issues myself trying to get those demos working. Hopefully we should expect Swift open source to be more stable by the end of the year, when Swift 3.0 comes out. It certainly has a long way to go for it to become a serious contender for systems programming. But the community is starting to form. Until then, do check out the examples and start thinking about the ways you can use or influence Swift.

Slide 33

Slide 33 text

Learn More • https://daringfireball.net/thetalkshow/139/federighi-gruber- transcript • swift pre-built package: dev.iachieved.it/iachievedit/ ubuntu-14-04-package-for-open-source-swift-2-2/ • SPM readme: https://github.com/apple/swift-package-manager • Nearly on-par with C++ for FFT, Mandelbrot, GEMM algos: http:// www.primatelabs.com/blog/2015/02/swift-performance-updated/ • swift evolution mailing lists • http://curtclifton.net/app-developers-on-swift-evolution

Slide 34

Slide 34 text

No content