Upload
carl-brown
View
279
Download
0
Embed Size (px)
Citation preview
June 1, 2016
Open-Source Swift: Up and RunningSwift<Austin>() -> [Meetup][0]
Slides will be postedNo need to try to write everything down.I’ll post a link to the Meetup.com comments for this meeting.
Please, STOP me at your convenienceSwift is newIt is changing very quicklyWe’re all learning this togetherPlease share your experience with us
Assumptions
✤ You want to be able to Compile/Run/Test/Learn “Pure” Swift
✤ That is: Swift without the closed-source Objective-C runtime (more on that later)
✤ You don’t want to have to build Swift and LLDB from scratch
✤ At least not at this meeting
✤ You aren’t running the Exact, Precise versions of Ubuntu (15.10 or 14.04) Apple Supports on the machine in front of you
✤ (If you are, then the first part of the meeting won’t be necessary for you, please hang on for a while.)
Prerequisites
✤ You need a specific version of Ubuntu (15.10 or 14.04)
✤ You need specific libraries installed
✤ You need specific executables installed
✤ And those might change at any (or every) snapshot
✤ … OR, of course, you can CHEAT (and probably should)
Containers all the way down…
✤ We’re going to talk through a couple of options:
✤ Docker
✤ Vagrant
✤ I’m sure there are others
Swift Roulette: Step Right Up & Pick a Version
✤ Usually several versions to pick from on swift.org/download
✤ The current release version is there (but that’s OLD)
✤ Historically, we’ve gotten a new SNAPSHOT every couple of weeks or so
✤ But, we just got Swift 3.0 Preview 1, (YESTERDAY!!) so I don’t know how that might affect the SNAPSHOT schedule
Swift Roulette: Step Right Up & Pick a Version
✤ Tonight, I’m going to use the 3.0 preview 1
✤ And I’m going to do it via Docker/Vagrant
Docker
✤ Seems to be coming the de-facto standard (from what I can see)
✤ Has issues with development (especially debugging - more later)
✤ Easy to use for deployment
✤ (You can use "carlbrown/docker-swift:latest", as a base
✤ at least until the rest of the ecosystem catches up with the latest drop)
Installing DockerMac or Windows
https://www.docker.com/products/docker-toolbox
Docker commands
docker run -it -v `pwd`:/Project swiftaustin-docker-swift ls /Project
docker build -t "swiftaustin-docker-swift" .
Vagrant
✤ Free VM software
✤ Build from spec file
✤ I tend to use this for development/debugging, and then move to Docker for deployment
Installing VagrantMac or Windows
https://www.vagrantup.com/downloads.html
Vagrant commands
vagrant ssh
vagrant up
Options and such are specified in vagrantfile
vagrant stop
vagrant destroy
June 1st, 2016
“Hello, World” Really simple program with Docker and Vagrant configs and instructions https://github.com/SwiftAustin/HelloWorld
Vagrant “Hello, World”
start with: git clone https://github.com/SwiftAustin/HelloWorld.gitthen: cd HelloWorld
run: vagrant up
then: vagrant ssh
then: cd /Project && swift build && ./build/debug/Project
Docker “Hello, World”
start with: git clone https://github.com/SwiftAustin/HelloWorld.gitthen: cd HelloWorld
run: docker build -t "swiftaustin-docker-swift" .
then: docker run -v ${PWD}:/Project swiftaustin-docker-swift \ bash -c \ ”cd /Project && swift build && .build/debug/Project"
✤ swift build command expects a particular directory structure:
✤ Package.swift
✤ Sources/
✤ main.swift
✤ Tests/
✤ LinuxMain.swift
Swift Package Manager: A Brief Introduction
Playing with the REPL
✤ from vagrant ssh
✤ swift Welcome to Swift version 3.0-dev (LLVM 3863c393d9, Clang d03752fe45, Swift e996f0c248). Type :help for assistance. 1>
REPL with Docker
✤ REPL (and debugger) require root access (to be able to attach to processes)
✤ If you forget, you’ll get:
✤ To type, you also need -it for interactive and tty
docker run -it --privileged=true -v ${PWD}:/Project docker-swift swift
error: failed to launch REPL process: process launch failed: 'A' packet returned an error
Differences from OS X
✤ No Objective-C runtime
✤ Many casts between object types just fail
✤ Many libraries that work on OS X explode on Linux (often at runtime)
✤ e.g. I can put an Int64 into a Dictionary, but passing to SwiftyJSON crashes
✤ Many parts of Foundation just aren’t there
✤ Embrace your inner NSUnimplemented()