Skip to content

Carthage

Ken Harris edited this page Dec 18, 2020 · 10 revisions

December 2020: everything I wrote below was true and accurate through mid-2020. Then macOS 11 and the Apple M1 happened, and things got icky. It's been 6 months and people still seem to be picking through the rubble.

Fortunately, all of the dependencies I used to get from Carthage are also available via SPM. It's still not as mature as (pre-BS) Carthage, but it's good enough, and it's the future of Mac development, so you might as well switch now.


Carthage is the best system, so far, for managing dependencies for Mac applications.

To install: brew install carthage

To use a project via Carthage:

  • write a Cartfile, which lists dependencies and version specs
  • run carthage update (with params...), which generates a Cartfile.resolved, which locks down the exact versions, and downloads/builds them
  • drag the frameworks from Carthage/Build/... into your app

Git:

  • commit Cartfile and Cartfile.resolved
  • ignore Carthage/

Writing Cartfiles

Carthage mostly uses semver but intentionally violates part 4: ~> in Carthage claims to mean "compatible with version", but ~> 0.1 will upgrade 0.1 to 0.2, even though semver says there's not (necessarily) any compatibility between these. (They say this "keeps ~> useful for 0.x.y versions", which is a strange way to say it'll make all hell break loose and you won't know why everything broke.) To save your own sanity, never use ~> in a Cartfile with a version number less than 1.0. Use == instead, which is what you actually meant. You can switch to ~> when it hits 1.0.

Running carthage

You probably want --platform Mac. Many projects will support 2-4 platforms, and this will save a bunch of time.

You probably want --no-use-binaries. Some projects will include binaries built with a particular compiler, and a minor upgrade of the Swift compiler (like 3.0.1 -> 3.0.2) is enough to render them unusable.

(I have no idea why there's no config to let me specify these.)

TODO: how to publish a project with Carthage

TODO: how to upgrade Carthage if you're on a system without Xcode 9, even though there's newer versions that you can run?

Clone this wiki locally