Skip to content

feat: Swift Package Manager dependency support for Flutter iOS/macOS SDK#804

Open
NandanPrabhu wants to merge 16 commits into
mainfrom
flutter-pod-to-spm
Open

feat: Swift Package Manager dependency support for Flutter iOS/macOS SDK#804
NandanPrabhu wants to merge 16 commits into
mainfrom
flutter-pod-to-spm

Conversation

@NandanPrabhu

@NandanPrabhu NandanPrabhu commented Apr 2, 2026

Copy link
Copy Markdown
Contributor
  • All new/changed/fixed functionality is covered by tests (or N/A)
  • I have added documentation for all new/changed functionality (or N/A)

📋 Changes

Adds Swift Package Manager (SPM) support to the iOS/macOS (darwin) native plugin, addressing #793. CocoaPods support is retained as a fallback, so this is non-breaking for existing consumers.

SPM packaging

  • Adds auth0_flutter/darwin/auth0_flutter/Package.swift declaring the auth0_flutter SPM target (iOS 14 / macOS 11), depending on Auth0.swift ≥ 2.21.2, JWTDecode.swift 3.3.0, and SimpleKeychain 1.3.0.
  • Sets sharedDarwinSource: true in pubspec.yaml so Flutter resolves iOS and macOS from a single source tree under darwin/auth0_flutter/Sources/auth0_flutter/.
  • Adds PASSKEYS_PLATFORM Swift compilation condition via swiftSettings in Package.swift (previously only provided by the CocoaPods podspec).

CocoaPods fallback (retained)

  • auth0_flutter/darwin/auth0_flutter.podspec updated to point source_files at Sources/auth0_flutter/ — the canonical location shared with SPM.
  • ios/ and macos/ podspecs kept for CocoaPods consumers; their Classes/ directories contain symlinks into darwin/Classes/, which in turn symlink to Sources/auth0_flutter/.
  • A scripts/generate-symlinks.sh script regenerates the full symlink chain (darwin/Classes/ → Sources/, ios/Classes/ → darwin/Classes/, macos/Classes/ → darwin/Classes/) and is enforced by the Symlinks CI job on every PR.

Plugin entry point

  • Removes the Objective-C shim (Auth0FlutterPlugin.h/.m) and renames SwiftAuth0FlutterPluginAuth0FlutterPlugin to match the pluginClass declared in pubspec.yaml. No public Dart API change.

CI

  • setup-darwin: sets up Xcode before flutter pub get, enables SPM (flutter config --enable-swift-package-manager), caches and installs CocoaPods, then patches the Flutter-generated FlutterGeneratedPluginSwiftPackage/Package.swift deployment targets to 14.0 (iOS) / 11.0 (macOS).
  • unit-tests-darwin: runs xcodebuild test against Runner.xcworkspace (CocoaPods workspace, which includes the SPM-resolved plugin).
  • iOS coverage converted from .xcresult to Cobertura XML via xcresultparser before the Codecov upload.
  • Adds .github/workflows/check-symlinks.yml CI job that runs scripts/generate-symlinks.sh and fails if any symlink is out of sync.

Tests

  • Plugin registration tests renamed to Auth0FlutterPluginTests.
  • Credentials Manager tests updated to use credentialsManager.store(credentials:) instead of hand-built NSKeyedArchiver fixtures.

📎 References

🎯 Testing

  • iOS and macOS native unit tests pass in CI via xcodebuild against Runner.xcworkspace (Xcode 26.2); Android and Windows unit suites unchanged.
  • The Symlinks CI job validates that darwin/Classes/, ios/Classes/, and macos/Classes/ symlinks are consistent with Sources/auth0_flutter/ on every PR.
  • Manual verification: from auth0_flutter/example, run flutter config --enable-swift-package-manager then flutter run on an iOS simulator or device; exercise login/logout, credentials manager, and DPoP flows.
  • CocoaPods fallback can be verified by running flutter config --no-enable-swift-package-manager and building the example app.

Reviewer note: this PR is large by file count because darwin/Classes/ files changed from full Swift source to single-line symlinks — git counts the old content as deletions and the canonical files under Sources/auth0_flutter/ as additions. The substantive surface is Package.swift, the podspecs, the CI actions, and the plugin/test renames.

@NandanPrabhu NandanPrabhu changed the title cocoapods to spm conversion feat: Flutter SPM support for iOS plugin Apr 2, 2026
@NandanPrabhu NandanPrabhu marked this pull request as ready for review April 8, 2026 14:08
@NandanPrabhu NandanPrabhu requested a review from a team as a code owner April 8, 2026 14:08
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

Comment thread .github/workflows/main.yml
@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

@NandanPrabhu

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
✅ Action performed

Full review finished.

Comment thread scripts/generate-symlinks.sh
Comment thread scripts/generate-symlinks.sh Outdated
Comment thread auth0_flutter/darwin/auth0_flutter.podspec Outdated
Comment thread .github/workflows/main.yml Outdated
Comment thread auth0_flutter/example/pubspec.yaml Outdated
Comment thread auth0_flutter/darwin/auth0_flutter/Package.swift Outdated
../../../darwin/Classes/MethodHandler.swift

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would revert all the path-related changes across all files. There are a lot of them, and I'd remove those changes from this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The path/symlink restructuring is required for this PR: SPM needs a single canonical source tree (darwin/auth0_flutter/Sources/auth0_flutter/), and CocoaPods (ios/, macos/, darwin/Classes/) needs to keep working off the same files without duplication, so the symlinks are what let both dependency managers point at one source of truth. What you were hitting was a real bug though — scripts/generate-symlinks.sh miscalculated the ../ depth and left ~185 symlinks dangling across darwin/ios/macos. That's fixed in 4dc9e76: the depth is now computed relative to Classes/ instead of the full repo path, and I re-ran the script and verified every symlink resolves (0 dangling). I also added a post-generation check to the script itself so this can't silently regress again. Given the alternative (duplicating ~60 Swift files three times, or dropping CocoaPods support entirely) I'd like to keep the symlink approach — let me know if you still see broken links after pulling 4dc9e76.

@@ -1 +1 @@
../../../darwin/Classes/MyAccountAPI/MyAccountEnrollPasskeyMethodHandler.swift No newline at end of file
../../../../darwin/Classes/MyAccountAPI/MyAccountEnrollPasskeyMethodHandler.swift No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we also verify if these symlink changes are intended. it seems to be broken currently as per my testing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Confirmed intended and now verified working — this was the same depth-calculation bug reported by @utkrishtsahu on scripts/generate-symlinks.sh, fixed in 4dc9e76. I re-ran scripts/generate-symlinks.sh against current main-rebased HEAD and confirmed 0 dangling symlinks across darwin/Classes/, ios/Classes/, and macos/Classes/ (including this file). Could you re-pull and re-test? If it's still broken for you I'd like to see the specific symlink/error so I can repro.

flutter config --enable-swift-package-manager must run after Flutter
is installed and before flutter pub get so that SPM-based dependencies
(Auth0.swift resolved via Package.swift) are properly set up when
building and running native iOS/macOS unit tests.
The FlutterGeneratedPluginSwiftPackage (created during flutter pub get)
picks up the iOS deployment target from the Xcode toolchain. When Xcode
was configured after pub get, the generated Package.swift defaulted to
iOS 13.0 instead of reading the project's IPHONEOS_DEPLOYMENT_TARGET
of 14.0, causing:

  error: The package product 'auth0-flutter' requires minimum platform
  version 14.0 for the iOS platform, but this target supports 13.0

Fix: move "Setup Xcode" and "Save Xcode version" steps before
"Enable Swift Package Manager" and "flutter pub get".
- Restores darwin/Classes/ with ObjC stubs (Auth0FlutterPlugin.h/.m),
  SwiftAuth0FlutterPlugin.swift, and symlinks for all Swift source files
  pointing to darwin/auth0_flutter/Sources/auth0_flutter/
- Restores ios/ and macos/ top-level: .gitignore, Assets/.gitkeep (symlink),
  and auth0_flutter.podspec (Classes/**/* source_files, v2.2.0, Auth0 2.21.2,
  PASSKEYS_PLATFORM xcconfig)
- Restores ios/Classes/ and macos/Classes/ symlinks for all source files
  pointing through darwin/Classes/
- All darwin/ios/macos files now match main branch structure
Auth0FlutterPlugin.swift is the SPM entry point and belongs only in
darwin/auth0_flutter/Sources/auth0_flutter/. CocoaPods uses
SwiftAuth0FlutterPlugin.swift instead.
- Updates Package.swift to require Auth0.swift >= 2.21.2 (adds
  updateAuthenticationMethod and other newer APIs used by source files)
- Adds PASSKEYS_PLATFORM Swift define to SPM target so passkey source
  files and test assertions compile correctly under SPM
- Adds explicit Flutter import (#if os(iOS)) to 15 test files that use
  FlutterError without importing Flutter — needed under SPM where types
  are not transitively available from @testable import auth0_flutter
- Updates unit-tests-darwin action to use -workspace (includes Pods.xcodeproj
  so Pods_Runner.framework is built as part of the test build)
- Updates Package.resolved to pin Auth0.swift 2.22.0 for iOS and macOS
- Updates Xcode project files to reflect pod install with SPM enabled
…x CI sed replacement

- Bump auth0_flutter SPM package to .upToNextMajor(from: "2.21.2") since useDPoP()
  and updateAuthenticationMethod() require 2.21.2+
- Add swiftSettings: [.define("PASSKEYS_PLATFORM")] so passkey types compile under SPM
- Fix sed replacement in setup-darwin action: remove escaped dot in replacement string
  to prevent generating invalid Package.swift with \.iOS/\.macOS syntax
- Fixes broken darwin/ios/macos symlinks in generate-symlinks.sh: depth
  was computed from the full repo-relative path instead of the path
  relative to Classes/, producing one extra "../" and leaving 185
  symlinks dangling
- Adds a post-generation check that verifies every symlink resolves
- Normalizes platform comparison in setup-darwin/action.yml to use the
  lowercased step output, avoiding a case-sensitivity mismatch
- Trims darwin/auth0_flutter.podspec source_files/public_header_files
  to Swift-only, since the ObjC shim (.h/.m) no longer exists
- Pins xcresultparser to 2.0.1 in CI instead of installing latest
- Relaxes Auth0.swift pin in all three podspecs to '~> 2.21' to match
  Package.swift's .upToNextMajor(from: "2.21.2")
- Reverts the .env pubspec asset to commented-out, since it turns a
  missing .env into a hard build failure for contributors
- Package.swift now uses exact: "2.22.0" instead of
  .upToNextMajor(from: "2.21.2")
- All three podspecs now pin '2.22.0' exactly instead of '~> 2.21'
- Matches the version already locked in the checked-in
  Package.resolved files under example/ios and example/macos, so SPM
  and CocoaPods consumers resolve to the same Auth0.swift release
- Package.swift and all three podspecs now pin exact: "2.24.1"
- Updates the checked-in Package.resolved files under example/ios and
  example/macos to the matching revision so SPM resolves without
  re-fetching
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.

Add Swift Package Manager support

3 participants