Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow library podspec to declare Swift Package Manager dependencies (#…
…44627) Summary: React-Native uses Cocapods for native dependency management on iOS. While CocoaPods is flexible and popular, Apple's Swift Package Manager is the new standard. Currently consuming packages available only via Swift Package Manager is not possible. This change implements a single extension so .podspec files can declare Swift Package Manager dependencies via ```ruby ReactNativePodsUtils.spm_dependency(s, url: 'https://github.com/apple/swift-atomics.git', requirement: {kind: 'upToNextMajorVersion', minimumVersion: '1.1.0'}, products: ['Atomics'] ) ``` bypass-github-export-checks ## Changelog: [IOS] [ADDED] - libraries can now declare Swift Package Manager dependencies in their .podspec with `ReactNativePodsUtils.spm_dependency` Pull Request resolved: #44627 Test Plan: https://github.com/mfazekas/rn-spm-rfc-poc/ Is a simple demo for the feature: 1. Podspec declare dependency with: ```ruby if const_defined?(:ReactNativePodsUtils) && ReactNativePodsUtils.respond_to?(:spm_dependency) ReactNativePodsUtils.spm_dependency(s, url: 'https://github.com/apple/swift-atomics.git', requirement: {kind: 'upToNextMajorVersion', minimumVersion: '1.1.0'}, products: ['Atomics'] ) else raise "Please upgrade React Native to >=0.75.0 to use SPM dependencies." end ``` 2. [`import Atomics`](https://github.com/mfazekas/rn-spm-rfc-poc/blob/e4eb1034f7498dedee4cb673d327c34a6048bda2/ios/MultiplyInSwift.swift#L1C2-L1C15) and [`ManagedAtomic`](https://github.com/mfazekas/rn-spm-rfc-poc/blob/e4eb1034f7498dedee4cb673d327c34a6048bda2/ios/MultiplyInSwift.swift#L7-L13) is used in the code 3.) `spm_dependency` causes the dependency to be added via `post_install` hook in the workspace <img width="261" alt="image" src="https://github.com/facebook/react-native/assets/52435/ad6aee1c-ac88-4c84-8aa3-50e148c4f5b2"> 4.) `spm_dependecy` causes the library to be linked with `Atomics` library <img width="817" alt="image" src="https://github.com/facebook/react-native/assets/52435/bfc8dfc0-aeb7-4c75-acbd-937eab1cbf80"> Limitations: 1.) only works `USE_FRAMEWORKS=dynamic pod install` otherwise the linker fails [with known Xcode issue - duplicate link issue](https://forums.swift.org/t/objc-flag-causes-duplicate-symbols-with-swift-packages/27926) 2.) .xcworkspace needs to be reopened after `pod install` - this could be worked around by not removing/readding spm dependencies ### See also: react-native-community/discussions-and-proposals#587 (comment) react-native-community/discussions-and-proposals#787 Reviewed By: cortinico Differential Revision: D58947066 Pulled By: cipolleschi fbshipit-source-id: ae3bf955cd36a02cc78472595fa003cc9e843dd5
- Loading branch information