Skip to content

Add Swift Package Manager support - #6

Merged
retyui merged 1 commit into
mainfrom
spm-support
Nov 26, 2026
Merged

retyui merged 1 commit into
mainfrom
spm-support

Conversation

@retyui

@retyui retyui commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Adds a hand-written Package.swift so React Native's SPM autolinker (RN 0.87+) picks the library up as a self-managed package. CocoaPods keeps using DetectMaestro.podspec, unchanged.

Ref: callstack/react-native-image-editor#215

Changes

  • Package.swift: SPM can't compile Swift and ObjC++ in one target, so sources are split:
    • DetectMaestroImpl (Swift) — DetectMaestroModuleImpl.swift
    • DetectMaestro (ObjC++) — the RN module, depends on DetectMaestroImpl (one-way, no cycle)
    • Defines RCT_NEW_ARCH_ENABLED=1 (SPM is New Architecture only) and DEBUG/NDEBUG to match the prebuilt React framework.
  • ios/DetectMaestroModule.mm: __has_include guards so the same file builds under both:
    • CocoaPods: imports DetectMaestro-Swift.h and "DetectMaestro.h" as before.
    • SPM: imports <ReactCodegen/DetectMaestro/DetectMaestro.h> and declares the @objc(DetectMaestroModuleImpl) interface directly (@import isn't allowed in ObjC++ without -fcxx-modules).
  • package.json: swiftpmConfig.name = "DetectMaestro", and Package.swift added to files.
  • CI (modeled on callstack/react-native-image-editor main.yml): Build Android, Build iOS (CocoaPods) and Build iOS (SPM) jobs on RN latest (macos-15 + Xcode 16.4 for iOS). build-app creates apps with @react-native-community/cli init --pm yarn, links the module via portal:, and uses npx pod-install or spm add --deintegrate. Legacy react-native init is kept for RN < 0.75 (E2E). Node 20 / Ruby 3.2 defaults.
  • README.md: SPM note. .gitignore: SPM build artifacts.

Testing

Fresh RN 0.88.1 app, library installed from npm pack:

  • SPM (npx react-native spm add --deintegrate): Debug + Release builds succeed; app runs on simulator and DetectMaestro.isMaestro() returns false.
  • CocoaPods (pod install): Release build succeeds; same runtime result.

Not tested: CocoaPods on older RN (0.65–0.72) / old architecture (that code path is unchanged).

@retyui
retyui force-pushed the spm-support branch 2 times, most recently from 0960295 to 0c2a87b Compare November 26, 2026 10:28
@retyui
retyui merged commit 582a142 into main Nov 26, 2026
5 of 10 checks passed
@retyui
retyui deleted the spm-support branch November 26, 2026 10:32
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