Skip to content

Add Swift Package Manager manifest (React Native 0.87 SwiftPM) - #723

Merged
gre merged 2 commits into
masterfrom
swiftpm-manifest
Oct 7, 2026
Merged

gre merged 2 commits into
masterfrom
swiftpm-manifest

Conversation

@gre

@gre gre commented Oct 7, 2026

Copy link
Copy Markdown
Owner

Supersedes #722: keeps @serpixel's commit as-is and adds a follow-up commit on top.

Why

RN 0.87's SwiftPM autolinking hard-fails for any autolinked library without a Package.swift. Reproduced on a fresh RN 0.87.1 app with react-native-view-shot@6.1.0:

error: Package.swift is missing for library "react-native-view-shot" — it ships no Swift Package Manager support.

CocoaPods users are unaffected; the podspec stays the source of truth there.

Follow-up changes on top of #722

  • Define RCT_NEW_ARCH_ENABLED. SwiftPM autolinking is New Architecture only, but nothing defined it, so RNViewShot.mm compiled without its TurboModule code (getTurboModule: / NativeRNViewShotSpec absent from the object file) and only worked through the legacy interop layer.
  • Drop the AUTO-SCAFFOLDED markers. With them, react-native spm scaffold treats the file as its own and regenerates it in consumers' node_modules whenever the cache slot changes. Without them, the autolinker reports it as Self-managed.
  • Declare ios/PrivacyInfo.xcprivacy as a resource, matching the podspec's resource_bundles (it was only picked up implicitly before).
  • Scope the target to ios/, exclude RNViewShot.xcodeproj, and remove the prefix header and unsafeFlags (not needed).
  • Keep iOS 15.0: 15.1 fails against RN's generated Autolinked aggregate.
  • Ignore SwiftPM's .build/ and .swiftpm/ in git and npm.

Tests

New CI job, Build iOS App (SwiftPM). It packs the library, installs it in a fresh RN 0.87.1 app switched to SwiftPM, builds Release for the simulator, and asserts that:

  • Package.swift ships in the npm tarball
  • the autolinker uses it as self-managed (not scaffolded)
  • the privacy manifest is bundled
  • getTurboModule: is compiled in

Verified locally as well: Debug and Release simulator builds of a fresh RN 0.87.1 SwiftPM app, captureRef returns a valid PNG at runtime, and the job steps were replayed from scratch.

🤖 Generated with Claude Code

serpixel and others added 2 commits October 7, 2026 11:11
Generated with RN 0.87.1's `react-native spm scaffold` from the podspec and
validated with `swift package dump-package` (swift-tools-version 6.0). The
two React path dependencies resolve through RN 0.87's autolinking alias at
app resolve time (same shape react-native-safe-area-context ships); they do
not resolve in a bare clone. CocoaPods users are unaffected.

Needed for React Native 0.87 SwiftPM autolinking, where autolinked native
libraries without a manifest fail the package resolve.
Package.swift:
- Define RCT_NEW_ARCH_ENABLED. SwiftPM autolinking is New Architecture
  only, but nothing defined it, so RNViewShot compiled without its
  TurboModule code and only ran through the legacy interop layer.
- Drop the scaffolder markers so `react-native spm scaffold` treats the
  manifest as self-managed instead of regenerating it per cache slot.
- Declare ios/PrivacyInfo.xcprivacy as a resource (parity with the
  podspec's resource_bundles) rather than relying on implicit detection.
- Scope the target to ios/, exclude RNViewShot.xcodeproj.
- Remove the prefix header and unsafeFlags: the React headers already
  pull in Foundation/UIKit.
- Keep iOS 15.0: 15.1 fails against RN's generated Autolinked aggregate.

CI: new build-ios-spm job packs the library, installs it in a fresh
RN 0.87.1 app switched to SwiftPM, builds Release for the simulator, and
asserts Package.swift ships in the tarball, the autolinker uses it as
self-managed, the privacy manifest is bundled, and getTurboModule: is
compiled in.

Ignore SwiftPM's .build/ and .swiftpm/ in git and npm.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@gre
gre requested a balanced review from Copilot October 7, 2026 11:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation is focused, matches React Native’s SwiftPM contract, and its targeted CI job passes.

Review effort: Balanced
Findings: None

What changed in this PR

Adds SwiftPM support for React Native 0.87 autolinking while preserving CocoaPods behavior.

Changes:

  • Adds a self-managed SwiftPM manifest with TurboModule and privacy-resource support.
  • Adds an end-to-end SwiftPM iOS build check.
  • Ignores SwiftPM build artifacts.
File Description
Package.swift Defines the iOS SwiftPM package and dependencies.
.github/​workflows/​ci.yml Tests packaging, autolinking, building, resources, and TurboModule symbols.
.gitignore Excludes local SwiftPM artifacts.
.npmignore Excludes SwiftPM artifacts from npm packages.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@gre
gre marked this pull request as ready for review October 7, 2026 12:59
@gre
gre merged commit 1dc0e5e into master Oct 7, 2026
19 checks passed
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.

3 participants