Skip to content

Commit 4dec854

Browse files
authored
Merge pull request #215 from callstack/feat/swift-package-manager
Add Swift Package Manager support
1 parent d95ecb2 commit 4dec854

9 files changed

Lines changed: 5244 additions & 3757 deletions

File tree

‎.github/actions/build-app/action.yml‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ inputs:
2424
required: false
2525
default: 'true'
2626

27+
ios-package-manager:
28+
description: 'iOS dependency manager (pods or spm)'
29+
required: false
30+
default: 'pods'
31+
2732
platform:
2833
description: 'Platform (example: android or ios))'
2934
required: true
@@ -82,9 +87,9 @@ runs:
8287
fi
8388
8489
if [[ '${{ inputs.platform }}' == 'ios' ]]; then
85-
# Use xcode 16 for RN 0.80+
90+
# Use Xcode 16.4 for RN 0.80+; macos-15 includes its iOS 18.5 simulator runtime.
8691
if [[ '${{ inputs.rn-ver }}' == "0.8"* || "${{ inputs.rn-ver }}" == "latest" ]]; then
87-
sudo xcode-select --switch /Applications/Xcode_16.2.app/Contents/Developer
92+
sudo xcode-select --switch /Applications/Xcode_16.4.app/Contents/Developer
8893
fi
8994
fi
9095
@@ -94,11 +99,18 @@ runs:
9499
if [[ '${{ inputs.platform }}' == 'ios' ]]; then
95100
brew install xcbeautify
96101
97-
# Update pods after adding new module
98-
npx pod-install
102+
xcodebuild_container=(-workspace "ios/${APP_NAME}.xcworkspace")
103+
if [[ '${{ inputs.ios-package-manager }}' == 'spm' ]]; then
104+
npx react-native spm add --deintegrate --yes
105+
xcodebuild_container=(-project "ios/${APP_NAME}.xcodeproj")
106+
else
107+
# Update pods after adding new module
108+
npx pod-install
109+
fi
99110
100111
# Build iOS App
101-
xcodebuild -scheme ${{ env.APP_NAME }} -workspace ios/${{ env.APP_NAME }}.xcworkspace -configuration Release -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' | xcbeautify --quiet
112+
set -o pipefail
113+
xcodebuild -scheme "${APP_NAME}" "${xcodebuild_container[@]}" -configuration Release -sdk iphonesimulator -destination 'generic/platform=iOS Simulator' | xcbeautify --quiet
102114
103115
# set output variable
104116
echo "app_path=$(find ~/Library/Developer/Xcode/DerivedData -type d -name "${{ env.APP_NAME }}.app")" >> $GITHUB_OUTPUT

‎.github/workflows/main.yml‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
branches:
99
- master
1010

11+
permissions:
12+
contents: read
13+
1114
concurrency:
1215
group: ${{ github.workflow }}-${{ github.ref }}
1316
cancel-in-progress: true
@@ -73,9 +76,9 @@ jobs:
7376
store-artifacts: true
7477
platform: android
7578

76-
build-ios:
77-
name: Build iOS
78-
runs-on: macos-14
79+
build-ios-pods:
80+
name: Build iOS (CocoaPods)
81+
runs-on: macos-15
7982
strategy:
8083
fail-fast: false
8184
max-parallel: 3
@@ -92,3 +95,24 @@ jobs:
9295
module-to-install: ${{ github.workspace }}
9396
store-artifacts: true
9497
platform: ios
98+
99+
build-ios-spm:
100+
name: Build iOS (SPM)
101+
runs-on: macos-15
102+
strategy:
103+
fail-fast: false
104+
max-parallel: 3
105+
matrix:
106+
rn_ver: [ latest ] # also, can be any npm tag: 0.71-stable, next, nightly
107+
steps:
108+
- name: Checkout repository
109+
uses: actions/checkout@v3
110+
with:
111+
fetch-depth: 0
112+
- uses: ./.github/actions/build-app
113+
with:
114+
rn-ver: ${{ matrix.rn_ver }}
115+
module-to-install: ${{ github.workspace }}
116+
store-artifacts: false
117+
platform: ios
118+
ios-package-manager: spm

‎.gitignore‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ android.iml
4040
#
4141
example/ios/Pods
4242

43+
# Swift Package Manager (Package.swift at the repo root)
44+
.build/
45+
.swiftpm/
46+
Package.resolved
47+
4348
# node.js
4449
#
4550
node_modules/

‎Package.swift‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// swift-tools-version: 6.0
2+
/**
3+
* Swift Package Manager support.
4+
*
5+
* This is a hand-maintained ("self-managed") manifest: React Native's SPM
6+
* autolinker sees a checked-in Package.swift and uses it as-is instead of
7+
* generating a wrapper around this package — see `findSelfManagedPackageDir`
8+
* in react-native/scripts/spm/generate-spm-autolinking.js. CocoaPods keeps
9+
* using react-native-image-editor.podspec, so apps on RN < 0.87 are unaffected.
10+
*
11+
* Two contracts the autolinker imposes, both easy to break silently:
12+
*
13+
* 1. The package, its single library product and the target must all be named
14+
* `ImageEditor`. The `swiftpmConfig.name` in package.json pins this name so
15+
* CocoaPods' dashed pod name does not become the SPM product name. The
16+
* aggregator references us as
17+
* `.product(name: "ImageEditor", package: "ImageEditor")`, so renaming any
18+
* of the three fails resolution with "no product named ... available".
19+
*
20+
* 2. The `.package(path:)` references below are constant relative strings, not
21+
* paths to discover at manifest-evaluation time. The autolinker routes this
22+
* package through a symlink at
23+
* `<appRoot>/build/generated/autolinking/libs/ImageEditor`, and SwiftPM
24+
* resolves a manifest's relative package paths against that symlink without
25+
* canonicalizing it, so both packages sit at a fixed depth in every app:
26+
* build/xcframeworks -> ../../../../xcframeworks
27+
* build/generated/ios -> ../../../ios
28+
* That is exactly what react-native/scripts/spm/scaffold-package-swift.js
29+
* emits. Do not replace them with `#filePath` walks or absolute paths.
30+
*
31+
* React headers need no search paths here — they arrive through the products
32+
* listed on the target. `RCTImage` is not a separate product: the React
33+
* xcframework vends RCTImageLoader / RCTImageUtils / RCTConvert flat under the
34+
* `React` module and umbrella, and exports RCTTransformImage et al.
35+
*/
36+
37+
import PackageDescription
38+
39+
let package = Package(
40+
name: "ImageEditor",
41+
platforms: [.iOS(.v15)],
42+
products: [
43+
.library(name: "ImageEditor", targets: ["ImageEditor"]),
44+
],
45+
dependencies: [
46+
.package(name: "ReactNative", path: "../../../../xcframeworks"),
47+
.package(name: "React-GeneratedCode", path: "../../../ios"),
48+
],
49+
targets: [
50+
.target(
51+
name: "ImageEditor",
52+
dependencies: [
53+
.product(name: "ReactHeaders", package: "ReactNative"),
54+
.product(name: "ReactNativeHeaders", package: "ReactNative"),
55+
.product(name: "ReactNativeDependenciesHeaders", package: "ReactNative"),
56+
.product(name: "ReactAppHeaders", package: "React-GeneratedCode"),
57+
],
58+
// Scoped to `ios` so SPM discovers sources itself — a new native
59+
// file needs no manifest edit. `publicHeadersPath: "."` keeps the
60+
// same include surface as CocoaPods (`#import "RNCFileSystem.h"`),
61+
// and keeps SPM's artifacts (.build/, .swiftpm/) out of the source
62+
// dir's way.
63+
path: "ios",
64+
publicHeadersPath: ".",
65+
cxxSettings: [
66+
// DEBUG/NDEBUG must match the prebuilt React.framework's
67+
// config-gated C++ ABI: NDEBUG strips DebugStringConvertible's
68+
// vtable and shifts the ShadowNode layout codegen'd types
69+
// inherit, so a mismatched Release link fails on undefined
70+
// symbols. Mirrors React Native's own SPM manifests.
71+
.define("DEBUG", .when(configuration: .debug)),
72+
.define("NDEBUG", .when(configuration: .release)),
73+
],
74+
linkerSettings: [
75+
.linkedFramework("UIKit"),
76+
.linkedFramework("Foundation"),
77+
.linkedFramework("CoreGraphics"),
78+
]
79+
),
80+
],
81+
// Required by the React headers (concepts, std::optional) and by the
82+
// codegen'd spec this module imports.
83+
cxxLanguageStandard: .cxx20
84+
)

‎README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ npm install @react-native-community/image-editor --save
4444
npx pod-install
4545
```
4646

47+
> [!NOTE]
48+
> **Swift Package Manager** — React Native 0.87+ supports building the iOS side with SPM. Once your app is configured to use React Native's SPM integration, this library's `Package.swift` is picked up by the autolinker automatically. Apps on React Native 0.77–0.86 continue to use CocoaPods through `react-native-image-editor.podspec`, which compiles the same `ios/` sources.
49+
4750
## Usage
4851

4952
Start by importing the library:

‎example/.yarnrc.yml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
approvedGitRepositories:
2+
- "**"
3+
4+
enableScripts: true
5+
6+
npmMinimalAgeGate: 0

0 commit comments

Comments
 (0)