Slide 1

Slide 1 text

Ruthlessly Simple Dependency Management with Carthage

Slide 2

Slide 2 text

What Why How to use it How it works

Slide 3

Slide 3 text

Justin Spahr-Summers @jspahrsummers

Slide 4

Slide 4 text

The Problem

Slide 5

Slide 5 text

Dependencies in Cocoa (historically) 1. Copied source files 2. Zipped binaries 3. SVN externals, Git submodules 4. Git subtrees

Slide 6

Slide 6 text

Dependencies on other platforms 1. Dependency managers

Slide 7

Slide 7 text

Our Problem

Slide 8

Slide 8 text

GitHub for Mac has what could be called “excessively nested submodules.” 1 Me, late 2014

Slide 9

Slide 9 text

GitHub for Mac Mantle Squirrel OctoKit ReactiveCocoa ReactiveViewModel

Slide 10

Slide 10 text

Why not use CocoaPods?

Slide 11

Slide 11 text

Podspecs

Slide 12

Slide 12 text

Less control

Slide 13

Slide 13 text

Centralized

Slide 14

Slide 14 text

!

Slide 15

Slide 15 text

@robrix @mdiep @keithduncan @alanjrogers

Slide 16

Slide 16 text

Our goals ⁶ ⁵ 1. Pick compatible versions for all dependencies 2. Check out dependencies with Git 3. Build frameworks with Xcode

Slide 17

Slide 17 text

Using Carthage

Slide 18

Slide 18 text

Step 1: Create a Cartfile github "Mantle/Mantle" ~> 1.5 github "ReactiveCocoa/ReactiveCocoa" >= 2.4.7 github "ReactiveCocoa/ReactiveCocoaLayout" == 0.5.2

Slide 19

Slide 19 text

Step 2: Run Carthage $ carthage update *** Fetching Mantle *** Fetching ReactiveCocoa *** Fetching ReactiveCocoaLayout *** Fetching Archimedes *** Downloading Archimedes at "1.1.4" *** Downloading Mantle at "1.5.4" *** Downloading ReactiveCocoa at "v2.4.7" *** Downloading ReactiveCocoaLayout at "0.5.2"

Slide 20

Slide 20 text

Step 3: Link Frameworks

Slide 21

Slide 21 text

Step 4: Strip architectures (iOS only)

Slide 22

Slide 22 text

That’s it!

Slide 23

Slide 23 text

“Ruthlessly Simple”

Slide 24

Slide 24 text

Easy: familiar or approachable Simple: fewer concepts and concerns1 1 See Rich Hickey’s talk, Simple Made Easy

Slide 25

Slide 25 text

CocoaPods is easy Carthage is simple

Slide 26

Slide 26 text

Simpler tools are…

Slide 27

Slide 27 text

Easier to understand

Slide 28

Slide 28 text

Easier to maintain Easier to contribute to

Slide 29

Slide 29 text

More flexible More composable

Slide 30

Slide 30 text

Enhanced when other tools improve

Slide 31

Slide 31 text

Behind the Scenes

Slide 32

Slide 32 text

Parse the Cartfile Resolve the dependency graph Download all dependencies Build each framework

Slide 33

Slide 33 text

! Parsing Parse OGDL into a list of dependencies github "ReactiveCocoa/ReactiveCocoa" >= 2.4.7

Slide 34

Slide 34 text

! Parsing Parse OGDL into a list of dependencies github "ReactiveCocoa/ReactiveCocoa" >= 2.4.7 Determine the type of each dependency github "ReactiveCocoa/ReactiveCocoa"

Slide 35

Slide 35 text

! Parsing Parse OGDL into a list of dependencies github "ReactiveCocoa/ReactiveCocoa" >= 2.4.7 Determine the type of each dependency github "ReactiveCocoa/ReactiveCocoa" Parse any Semantic Version >= 2.4.7

Slide 36

Slide 36 text

㿃 Resolving CarthageDemo/Cartfile: github "Mantle/Mantle" ~> 1.5 github "ReactiveCocoa/ReactiveCocoa" >= 2.4.7 github "ReactiveCocoa/ReactiveCocoaLayout" == 0.5.2

Slide 37

Slide 37 text

㿃 Resolving Create a graph of the latest dependency versions Demo ReactiveCocoa 3.0 ReactiveCocoaLayout 0.5.2 Mantle 1.5.4

Slide 38

Slide 38 text

㿃 Resolving Insert dependency Cartfiles into the graph Demo ReactiveCocoa 3.0 ReactiveCocoaLayout 0.5.2 Mantle 1.5.4 2.4.7 Archimedes 1.1.4

Slide 39

Slide 39 text

㿃 Resolving If requirements conflict, throw out the graph Demo ReactiveCocoa 3.0 ReactiveCocoaLayout 0.5.2 Mantle 1.5.4 2.4.7 Archimedes 1.1.4

Slide 40

Slide 40 text

㿃 Resolving Try a new graph with the next possible version Demo ReactiveCocoa 2.4.7 ReactiveCocoaLayout 0.5.2 Mantle 1.5.4

Slide 41

Slide 41 text

㿃 Resolving Repeat until a valid graph is found Demo ReactiveCocoa 2.4.7 ReactiveCocoaLayout 0.5.2 Mantle 1.5.4 2.4.7 Archimedes 1.1.4

Slide 42

Slide 42 text

! Downloading 1. Fetch the repository into Carthage’s cache

Slide 43

Slide 43 text

! Downloading 1. Fetch the repository into Carthage’s cache 2. Copy the right version into Carthage/Checkouts

Slide 44

Slide 44 text

! Building 1. Symlink Carthage/Build into the dependency folder

Slide 45

Slide 45 text

! Building 1. Symlink Carthage/Build into the dependency folder 2. List framework schemes from the .xcodeproj

Slide 46

Slide 46 text

! Building 1. Symlink Carthage/Build into the dependency folder 2. List framework schemes from the .xcodeproj 3. Build each scheme for all supported architectures

Slide 47

Slide 47 text

! Building 1. Symlink Carthage/Build into the dependency folder 2. List framework schemes from the .xcodeproj 3. Build each scheme for all supported architectures 4. Combine multiple architectures with lipo

Slide 48

Slide 48 text

! Building 1. Symlink Carthage/Build into the dependency folder 2. List framework schemes from the .xcodeproj 3. Build each scheme for all supported architectures 4. Combine multiple architectures with lipo 5. Copy the built frameworks into Carthage/Build

Slide 49

Slide 49 text

✨ BONUS: Prebuilt binaries! ✨ *** Downloading ReactiveCocoa at "v2.4.7"

Slide 50

Slide 50 text

CarthageKit

Slide 51

Slide 51 text

Technical Choices

Slide 52

Slide 52 text

Dynamic frameworks vs. static libraries 4 iOS 8+ only 4 Can include resources 4 Self-contained and ready-to-use 4 Avoid duplicate symbol errors 4 Required for Swift

Slide 53

Slide 53 text

Swift vs. Objective-C 4 Type safety 4 Value types (especially enums) 4 Much faster to write 4 Better modularization 4 The Next Big Thing™

Slide 54

Slide 54 text

ReactiveCocoa 4 Simplifies networking (with the GitHub API) 4 Simplifies the dependency resolver 4 Simplifies shelling out, via ReactiveTask 4 Carthage helps test RAC 3.0 in the real world

Slide 55

Slide 55 text

1.0

Slide 56

Slide 56 text

Per-project settings

Slide 57

Slide 57 text

Review CarthageKit API Review command line flags

Slide 58

Slide 58 text

Profit!!! !

Slide 59

Slide 59 text

What Why How to use it How it works

Slide 60

Slide 60 text

Questions? Comments? Slides and notes, plus my demo project, are available at: https://github.com/jspahrsummers/carthage-talk Thanks to everyone who reviewed this presentation, and to Realm for inviting me to speak!2 2 ❤ Matt Diephouse, Rob Rix, Alan Rogers, Keith Duncan, Nacho Soto, Tom Brow, James Lawton, Arwa Jumkawala, JP Simard, Tim Anglade, Brendan Forster, Benjamin Encz, Robert Böhnke, and you!