Save 37% off PRO during our Black Friday Sale! »

Ruthlessly Simple Dependency Management with Carthage

Ruthlessly Simple Dependency Management with Carthage

Carthage is a new dependency manager for Objective-C and Swift projects, intended to be the simplest way to add frameworks to a Cocoa application. Carthage works by delegating tasks to Xcode and Git, minimizing new concepts as much as possible, so you can continue to use the tools you’re already familiar with.

This talk will explain what Carthage is and how to use it, then dive into the philosophy of ruthless simplicity that inspired the project. We’ll also compare and contrast Carthage with CocoaPods, the original dependency manager for Cocoa. Finally, we’ll explore how Carthage is architected under-the-hood, and the benefits we’ve seen from writing it completely in Swift.

B946e4cecdd5bfea759e92590b943ccb?s=128

Justin Spahr-Summers

April 02, 2015
Tweet

Transcript

  1. Ruthlessly Simple Dependency Management with Carthage

  2. What Why How to use it How it works

  3. Justin Spahr-Summers @jspahrsummers

  4. The Problem

  5. Dependencies in Cocoa (historically) 1. Copied source files 2. Zipped

    binaries 3. SVN externals, Git submodules 4. Git subtrees
  6. Dependencies on other platforms 1. Dependency managers

  7. Our Problem

  8. GitHub for Mac has what could be called “excessively nested

    submodules.” 1 Me, late 2014
  9. GitHub for Mac Mantle Squirrel OctoKit ReactiveCocoa ReactiveViewModel

  10. Why not use CocoaPods?

  11. Podspecs

  12. Less control

  13. Centralized

  14. !

  15. @robrix @mdiep @keithduncan @alanjrogers

  16. Our goals ⁶ ⁵ 1. Pick compatible versions for all

    dependencies 2. Check out dependencies with Git 3. Build frameworks with Xcode
  17. Using Carthage

  18. Step 1: Create a Cartfile github "Mantle/Mantle" ~> 1.5 github

    "ReactiveCocoa/ReactiveCocoa" >= 2.4.7 github "ReactiveCocoa/ReactiveCocoaLayout" == 0.5.2
  19. 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"
  20. Step 3: Link Frameworks

  21. Step 4: Strip architectures (iOS only)

  22. That’s it!

  23. “Ruthlessly Simple”

  24. Easy: familiar or approachable Simple: fewer concepts and concerns1 1

    See Rich Hickey’s talk, Simple Made Easy
  25. CocoaPods is easy Carthage is simple

  26. Simpler tools are…

  27. Easier to understand

  28. Easier to maintain Easier to contribute to

  29. More flexible More composable

  30. Enhanced when other tools improve

  31. Behind the Scenes

  32. Parse the Cartfile Resolve the dependency graph Download all dependencies

    Build each framework
  33. ! Parsing Parse OGDL into a list of dependencies github

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

    "ReactiveCocoa/ReactiveCocoa" >= 2.4.7 Determine the type of each dependency github "ReactiveCocoa/ReactiveCocoa"
  35. ! 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
  36. 㿃 Resolving CarthageDemo/Cartfile: github "Mantle/Mantle" ~> 1.5 github "ReactiveCocoa/ReactiveCocoa" >=

    2.4.7 github "ReactiveCocoa/ReactiveCocoaLayout" == 0.5.2
  37. 㿃 Resolving Create a graph of the latest dependency versions

    Demo ReactiveCocoa 3.0 ReactiveCocoaLayout 0.5.2 Mantle 1.5.4
  38. 㿃 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
  39. 㿃 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
  40. 㿃 Resolving Try a new graph with the next possible

    version Demo ReactiveCocoa 2.4.7 ReactiveCocoaLayout 0.5.2 Mantle 1.5.4
  41. 㿃 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
  42. ! Downloading 1. Fetch the repository into Carthage’s cache

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

    Copy the right version into Carthage/Checkouts
  44. ! Building 1. Symlink Carthage/Build into the dependency folder

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

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

    List framework schemes from the .xcodeproj 3. Build each scheme for all supported architectures
  47. ! 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
  48. ! 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
  49. ✨ BONUS: Prebuilt binaries! ✨ *** Downloading ReactiveCocoa at "v2.4.7"

  50. CarthageKit

  51. Technical Choices

  52. 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
  53. 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™
  54. 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
  55. 1.0

  56. Per-project settings

  57. Review CarthageKit API Review command line flags

  58. Profit!!! !

  59. What Why How to use it How it works

  60. 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!