Skip to content

Fix SwiftPM: keep the SwiftPM codegen Package.swift when codegen runs - #60488

Draft
chrfalch wants to merge 1 commit into
mainfrom
spm-ios-manifest-no-transient
Draft

chrfalch wants to merge 1 commit into
mainfrom
spm-ios-manifest-no-transient

Conversation

@chrfalch

@chrfalch chrfalch commented Dec 2, 2026

Copy link
Copy Markdown
Collaborator

Summary:

In a SwiftPM app, a build in the Xcode window can fail with Missing package product '<library>' after a native library is removed or added, and the error stays after more builds and after an Xcode restart. Only deleting Xcode's PIFCache folder in derived data fixes it.

The cause:

  1. spm update, and the "Sync SPM Autolinking" build phase, run codegen.
  2. Codegen writes build/generated/ios/Package.swift from the CocoaPods template. In a SwiftPM app that version points to a package path that does not exist.
  3. Seconds later, the SwiftPM scripts write the SwiftPM version back.
  4. An open Xcode can resolve packages at any time (for example, during indexing). If it does so in those seconds, package resolution fails, and Xcode caches a build plan that pairs the new Autolinked Package.swift with the old targets. Later builds reuse that plan.

This change: codegen keeps an existing Package.swift that is the SwiftPM version, detected by a line of Package.swift.spm-template. CocoaPods apps are unchanged.

Limits:

  • On the first setup, and after build/ is deleted, no file exists yet, so codegen still writes the CocoaPods version once before the SwiftPM scripts replace it. Xcode has no cached plan for the project at that point.
  • After spm deinit, an existing SwiftPM Package.swift now stays in build/generated/ios. CocoaPods builds do not use it.

Changelog:

[IOS] [FIXED] - SwiftPM: codegen no longer briefly replaces the SwiftPM Package.swift, which could make Xcode fail with "Missing package product" until its cache was deleted

Test Plan:

Unit tests:

yarn jest packages/react-native/scripts/codegen packages/react-native/scripts/spm --no-cache -i

29 suites, 1322 tests passed. The new generatePackageSwift-test.js has 3 tests; without the fix, "keeps the SwiftPM Package.swift installed by the SwiftPM scripts" fails. eslint and flow focus-check on both files: no errors.

App (RN 0.89.0-rc.4, SwiftPM app, Xcode 27.2, fixed file copied into node_modules; an npm dependencies script runs npx react-native spm update so the update happens while the project is open in Xcode):

  • Read build/generated/ios/Package.swift every 50 ms during spm update, npm uninstall and npm install: without the fix it was the CocoaPods version for about 6 s; with the fix it never was.
  • With the project open in the Xcode window: npm uninstall @react-native-picker/picker, start a build at the moment the Autolinked Package.swift drops the library, then build twice more.
Without the fix With the fix (2 runs)
Build during the update Fails: Missing package product 'rncpicker_RNCPicker.RNCPicker' Succeeds
Next 2 builds Fail, same error Succeed
Reinstall, build — Succeeds, library compiled

In a SwiftPM app, `spm update` and the "Sync SPM Autolinking" build phase run
codegen, which overwrote build/generated/ios/Package.swift with the CocoaPods
template. The SwiftPM scripts wrote the SwiftPM version back seconds later.
If an open Xcode resolved packages in between, it cached a broken build plan,
and every later build failed with "Missing package product" until the
PIFCache in derived data was deleted.

Codegen now keeps an existing Package.swift that is the SwiftPM version.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: Expo Partner: Expo Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant