21
June 1, 2016 Open-Source Swift: Up and Running Swift<Austin>() -> [Meetup][0]

Open Source Swift: Up and Running

Embed Size (px)

Citation preview

Page 1: Open Source Swift: Up and Running

June 1, 2016

Open-Source Swift: Up and RunningSwift<Austin>() -> [Meetup][0]

Page 2: Open Source Swift: Up and Running

Slides will be postedNo need to try to write everything down.I’ll post a link to the Meetup.com comments for this meeting.

Page 3: Open Source Swift: Up and Running

Please, STOP me at your convenienceSwift is newIt is changing very quicklyWe’re all learning this togetherPlease share your experience with us

Page 4: Open Source Swift: Up and Running

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.)

Page 5: Open Source Swift: Up and Running

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)

Page 6: Open Source Swift: Up and Running

Containers all the way down…

✤ We’re going to talk through a couple of options:

✤ Docker

✤ Vagrant

✤ I’m sure there are others

Page 7: Open Source Swift: Up and Running

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

Page 8: Open Source Swift: Up and Running

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

Page 9: Open Source Swift: Up and Running

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)

Page 10: Open Source Swift: Up and Running

Installing DockerMac or Windows

https://www.docker.com/products/docker-toolbox

Page 11: Open Source Swift: Up and Running

Docker commands

docker run -it -v `pwd`:/Project swiftaustin-docker-swift ls /Project

docker build -t "swiftaustin-docker-swift" .

Page 12: Open Source Swift: Up and Running

Vagrant

✤ Free VM software

✤ Build from spec file

✤ I tend to use this for development/debugging, and then move to Docker for deployment

Page 13: Open Source Swift: Up and Running

Installing VagrantMac or Windows

https://www.vagrantup.com/downloads.html

Page 14: Open Source Swift: Up and Running

Vagrant commands

vagrant ssh

vagrant up

Options and such are specified in vagrantfile

vagrant stop

vagrant destroy

Page 15: Open Source Swift: Up and Running

June 1st, 2016

“Hello, World” Really simple program with Docker and Vagrant configs and instructions https://github.com/SwiftAustin/HelloWorld

Page 16: Open Source Swift: Up and Running

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

Page 17: Open Source Swift: Up and Running

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"

Page 18: Open Source Swift: Up and Running

✤ swift build command expects a particular directory structure:

✤ Package.swift

✤ Sources/

✤ main.swift

✤ Tests/

✤ LinuxMain.swift

Swift Package Manager: A Brief Introduction

Page 19: Open Source Swift: Up and Running

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>

Page 20: Open Source Swift: Up and Running

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

Page 21: Open Source Swift: Up and Running

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()