Skip to content

feat(ios): add a compile-only link: false Swift Package Manager mode - #4372

Merged
mfazekas merged 1 commit into
mainfrom
feat/ios-spm-link-false
Oct 19, 2026
Merged

mfazekas merged 1 commit into
mainfrom
feat/ios-spm-link-false

Conversation

@mfazekas

Copy link
Copy Markdown
Contributor

Description

Adds a compile-only Swift Package Manager mode: $RNMapboxMapsSwiftPackageManager = { link: false } (or { "link": false } in the Expo plugin options). Use it when another Swift package already brings MapboxMaps, for example the Mapbox Navigation SDK. The rnmapbox-maps pod then compiles against the MapboxMaps package product without linking or embedding it: it gets a build-order dependency on the product and the products dir as a Swift include path. The other package links the only copy.

The dependency is added after the Podfile's post_install hooks, because react_native_post_install drops all package references. At that point project.new can reuse the UUID of an existing object. CocoaPods' stabilize_target_uuids resets @generated_uuids to the few leftover UUIDs, and Pod::Project's counter-based generator then restarts near 0. Depending on the project's object count, the package reference got the root PBXProject's UUID (46EB2E00000000), and Xcode reported "The project 'Pods' is damaged". The new objects now get MD5-derived UUIDs, the same way CocoaPods stabilizes target UUIDs, so they can't collide and re-running pod install is byte-identical. This is the same bug as react/react-native#57576, but in rnmapbox's own hook.

Checklist

  • I've read CONTRIBUTING.md
  • I updated the doc/other generated code with running yarn generate in the root folder
  • I have tested the new feature on /example app.
    • In V11 mode/ios
    • In New Architecture mode/ios
    • In V11 mode/android
    • In New Architecture mode/android
  • I added/updated a sample - if a new feature was implemented (/example)

Tested with RN 0.84 and CocoaPods 1.16.2:

  1. A navigation app that links the Navigation SDK 3.23.1 through SPM, with { link: false }: clean pod install, then a second pod install with an identical project.pbxproj. Debug build, launch, map and turn-by-turn guidance work, and a Release archive succeeds. The app has exactly one MapboxMaps copy, and librnmapbox-maps.a defines no MapboxMaps symbols.
  2. The /example app: pod install and a debug build both with the default (CocoaPods) setup and with RNMBX_SPM=1 (true).
  3. yarn lint, yarn type:check, yarn unittest, and the plugin test for the new option. Three Android gradle snapshot tests in yarn test:plugin fail on main as well.

Screenshot OR Video

Component to reproduce the issue you're fixing

Before the fix, the collision happened on every clean pod install in the navigation app. Where the object count leaves enough spare UUIDs it doesn't, so this RUBYOPT=-r hook provokes it: it drops the leftover UUIDs right before the compile-only step. Without the fix, rootObject resolves to the mapbox-maps-ios package reference, and xcodebuild -list fails with -[XCRemoteSwiftPackageReference _setSavedArchiveVersion:]: unrecognized selector. With the fix, the project has no duplicate IDs and loads.

require 'cocoapods'
module ProvokeUuidRestart
  def run_podfile_post_install_hooks
    super
    pods_project.instance_variable_set(:@available_uuids, [])
    pods_project.instance_variable_set(:@generated_uuids, [])
  end
end
Pod::Installer.prepend(ProvokeUuidRestart)

With `$RNMapboxMapsSwiftPackageManager = { link: false }` the rnmapbox-maps pod compiles against MapboxMaps
but doesn't link it: it gets a build-order dependency on the package product and the products dir as a Swift
include path. Another Swift package that brings MapboxMaps, e.g. the Navigation SDK, links the only copy.

The dependency is added after the Podfile's post_install hooks, because react_native_post_install drops all
package references. There CocoaPods' counter-based UUIDs have restarted (stabilize_target_uuids resets them),
so `project.new` could return the root PBXProject's UUID and corrupt Pods.xcodeproj. The objects get
MD5-derived UUIDs instead, which also keeps re-running `pod install` byte-identical.
@mfazekas
mfazekas merged commit 5818b4d into main Oct 19, 2026
9 checks passed
@mfazekas
mfazekas deleted the feat/ios-spm-link-false branch October 19, 2026 12:07

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant