mapbox / mapbox-gl-native-ios

Interactive, thoroughly customizable maps for iOS powered by vector tiles and OpenGL
https://www.mapbox.com/mobile/
Other
210 stars 121 forks source link

Allow installing prebuilt binary from this repository using Carthage #143

Open 1ec5 opened 4 years ago

1ec5 commented 4 years ago

A developer should be able to install this SDK by specifying a github origin in their Cartfile and running carthage update. The origin should point to this repository or, if that isn’t feasible, a repository set up specifically for Carthage installation.

Problem

As of #60 in v5.6.0, developers need to specify a binary origin when installing the SDK via Carthage. The binary origin doesn’t support transitive dependencies, so we also tell them to require MapboxMobileEvents separately. This requirement is expressed only informally on a webpage, not formally in a Cartfile, so Carthage cannot enforce the MapboxMobileEvents specification or detect when it is incompatible with another library’s MapbxoxMobileEvents specification.

mapbox/mapbox-navigation-ios#2299 describes a crash at runtime that occurred because of a version mismatch between the map and navigation SDKs. However, a version mismatch could instead produce a build failure or undefined behavior at runtime, depending on what changed in MapboxMobileEvents between the two required versions.

As long as the map SDK relies on an informal dependency, version mismatches will continue to occur any time the map SDK or the navigation SDK requires something new in MapboxMobileEvents.

Proposed changes

I think the most straightforward solution would require aligning this project to how Carthage is designed to be used:

Intended usage

The developer would include just this one line in their Cartfile and run carthage update:

github "mapbox/mapbox-gl-native-ios" ~> 5.7

Carthage will use the GitHub API to fetch the binary artifact from the latest matching release. It will also clone this repository and check out the corresponding tag in order to read the Cartfile, even if this project doesn’t use Carthage internally.

We’d continue to update the JSON binary specification so that anyone following the current installation instructions would continue to get a working build. But we would replace the binary origin with the github origin in the SDK’s installation instructions.

Side effects and caveats

There are some consequences to this approach, but I don’t think they’re showstoppers:

Alternative solutions

If it isn’t feasible to point Carthage to this repository for some reason, we could set up a repository specifically for Carthage installation, as proposed in https://github.com/mapbox/mapbox-gl-native/issues/1623#issuecomment-161186752.

133 proposes to make it possible to build this SDK from source. That would enable the use of a github origin and avoid dependency hell. However, building from source consumes considerable time, power, and disk space. It would also require Carthage to clone this repository’s submodules. For routine installations, we should still support downloading a prebuilt binary – while allowing Carthage to fully manage its dependencies – via the approach proposed above.

/cc @mapbox/maps-ios @mapbox/navigation-ios @mapbox/mobile-telemetry

captainbarbosa commented 4 years ago

Thank you for writing up this very detailed summary @1ec5. I appreciate it.

There will no longer be any distinction between iOS and macOS tags. The next time I release the macOS map SDK, it’ll be part of the same release as the iOS map SDK with the same version.

Could you say more about this? How does a developer distinguish using one versus another then?

1ec5 commented 4 years ago

If the archive is formatted the way carthage archive would normally format it, the iOS framework would be in Carthage/Build/iOS/ and the macOS framework would be in Carthage/Build/Mac/. For example, Octokit.swift provides prebuilt binaries for iOS, macOS, tvOS, and watchOS, all in the same archive.

Carthage will download the whole archive, including both frameworks, no matter which platform you’re developing for. (If you pass --platform iOS into carthage bootstrap, it won’t copy the macOS framework into your project’s Carthage/Build/Mac/ folder, though that doesn’t take much time anyways. The --platform tag is primarily for cross-platform dependencies built from source.) If you’re setting up your project for the first time, it’s up to you to manually add the framework to the application target, but you already have to look inside your Carthage/Build/iOS/ folder today.

In other words, the iOS and macOS map SDKs would be released together as a single SDK from the developer’s perspective. It means the macOS map SDK releases process would need to become more automated, including mapbox/mapbox-gl-native#14754. The fact that I haven’t taken care of this automation blocks future macOS releases but shouldn’t block iOS releases. That said, once I do manage to include a macOS framework in the archive for a given release, all releases after that point will need to include both platforms, because Carthage only bothers fetching the latest matching tag; it doesn’t crawl back through history to find a tag with a framework for the current platform.

zugaldia commented 4 years ago

cc: @alfwatt @julianrex