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

Swift and Linux - now and the future

Swift and Linux - now and the future

Ian Partridge

July 26, 2016
Tweet

More Decks by Ian Partridge

Other Decks in Programming

Transcript

  1. 1 Swift and Linux Now and the future Ian Partridge

    IBM Runtimes Technologies, IBM Cloud 26th July 2016
  2. 2 Ian Partridge • Senior developer in Swift@IBM • Background

    in runtime systems • Java garbage collection • Runtime performance analysis • Full-stack debugging • Swift@IBM, bringing Swift to the cloud on Linux @ianpartridge @alfa
  3. Agenda • Swift • History • Why Swift? • Swift

    on Linux • Current status • Kitura web framework • Cloud-ready out of the box 3
  4. Timeline Date Event 2010? Works begins inside Apple June 2014

    (WWDC) 1.0-beta September 2014 1.0 June 2015 (WWDC) 2.0-beta September 2015 2.0 December 2015 Swift open-sourced on GitHub June 2016 (WWDC) 3.0-techpreview1 3Q 2016? 3.0 4
  5. Safe • Type safe, but with inference • Definitive initialization

    of local variables • Immutability as a core language feature • No implicit type conversions • Objects cannot be null 7
  6. Expressive • Syntax inspired by C family • Plus modern

    features from scripting languages • Generics • Closures • Tuples • map() + filter() + reduce() 8
  7. Fast • Belongs to the C family of compiled native

    languages • Built on LLVM optimizing compiler • ARC provides memory management without GC pauses • Standard library providing collections using COW 9
  8. IBM Swift Sandbox • Interactive sandbox for exploring Swift •

    Saves your work • Supports multiple versions of Swift • Deploys your Swift code in a Linux Docker container 13 https://swiftlang.ng.bluemix.net/
  9. Swift on Linux – Compiler and debugger 14 • Scripts

    for easily building your own compiler • Or go to swift.org/download
  10. Swift on Linux – Foundation (class libraries) 15 • Work

    in progress • Contributions welcome!
  11. Kitura Web Framework What is it? New, modular, package-based web

    framework written in Swift Why is this cool? Empower a new generation of native mobile developers to write and deploy code into the cloud on Linux. Developer Benefits ? Delivers core technologies needed to stand up enterprise apps on the server Enables developers to create a web application in Swift and deploy these servers on Linux and the cloud. http://github.com/ibm-swift/kitura 17
  12. Isomorphic Swift Code 1 8 Create Swift Module Generate Swift

    Client APIs Kitura Linux Server Project Swagger REST API Deploy Deploy • Same module on client and server • Local or remote API calls • Automatically created Swagger APIs
  13. Developing a Kitura web application on Linux 19 myProject ├──

    Package.swift ├── Sources │ └── main.swift └── Tests $ mkdir myProject 2. Next, initialize this project as a new Swift package 1. First, we create a new project directory $ cd myProject $ swift package init Basic Swift package directory structure:
  14. Developing a Kitura web application on Linux 20 import PackageDescription

    let package = Package( name: "myProject", dependencies: [ .Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 0, minor: 22) ] ) 3. Add Kitura as a dependency for your project (Package.swift):
  15. Developing a Kitura web application on Linux 21 Kitura.addHTTPServer(onPort: 8090,

    with: router) Kitura.run() let router = Router() router.get("/hello") { request, response, next in response.status(.OK).send("<h1>Hello, World!</h1>").end() } 6. Create and start an HTTPServer: 4. Add a router and a path: router.get("/hello.json") { request, response, next in response.status(.OK).send(json: JSON(["Hello": "World!"])).end() } 5. Add a JSON data route
  16. Developing a Kitura web application on Linux 22 import Kitura

    let router = Router() router.get("/hello") { request, response, next in response.status(.OK).send("<h1>Hello, World!</h1>").end() } router.get("/hello.json") { request, response, next in response.status(.OK).send(json: JSON(["Hello": "World!"])).end() } Kitura.addHTTPServer(onPort: 8090, with: router) Kitura.run() 7. Sources/main.swift should now look like this:
  17. Developing a Kitura web application on Linux 23 $ swift

    build -Xcc –fblocks 8. Compile: $ .build/debug/myFirstProject & 9. Run: 10. Open your browser: http://localhost:8090/hello http://localhost:8090/ http://localhost:8090/hello.json
  18. Get started quickly with Kitura • http://github.com/IBM-Swift/Kitura-Sample • `make run`

    • http://github.com/IBM-Swift/Kitura-Starter-Bluemix • `cf push` • http://github.com/IBM-Swift/swift-watson-sdk 24
  19. The future of Swift on Linux • Completing the implementation

    of Foundation and libdispatch • Building a vibrant Swift on Linux community • Server-side packages in the rapidly-growing SPM ecosystem • IDE support • Cloud integration • Exploring the Swift “sweet-spot” • Linux-driven enhancements to Swift itself? 25