Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Open Source Swift

Open Source Swift

Lightning talk at Flipconf 3.0, March 2016

Kenny Tang

March 15, 2016
Tweet

More Decks by Kenny Tang

Other Decks in Technology

Transcript

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. 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.
  14. 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.
  15. 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.
  16. 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.
  17. 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.
  18. 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.
  19. 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.
  20. 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.
  21. 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.
  22. 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.
  23. 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.
  24. 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.
  25. 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.
  26. 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.
  27. 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.
  28. 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.
  29. 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