Skip to content

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

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

feat: Swift Package Manager dependency support for Flutter iOS/macOS SDK#804
NandanPrabhu wants to merge 13 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
@NandanPrabhu

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

@NandanPrabhu — looks like your message got cut off (missing the b — it's @coderabbitai). What can I help you with?

If you'd like a full re-review of all changes in this PR (not just new commits), I can trigger that:

✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@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.

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
../../../../darwin/Classes/MyAccountAPI/MyAccountConfirmEnrollmentMethodHandler.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.

why do we have changes in this file ?

link_depth=$(echo "$darwin_link" | awk -F '/' '{print NF-1}')
# We need to go up (link_depth) levels then down into auth0_flutter/Sources/auth0_flutter/
up=$(printf '../%.0s' $(seq 1 "$link_depth"))
ln -sf "${up}auth0_flutter/Sources/auth0_flutter/$rel" "$darwin_link"

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.

he up calculation is off here. link_depth is counting from the full path (auth0_flutter/darwin/Classes/...), so we end up with too many ../ and the link points at auth0_flutter/Sources/auth0_flutter/... instead of auth0_flutter/darwin/auth0_flutter/Sources/.... I pulled the branch and every link under darwin/Classes/ is dangling. Can you base the depth on the path relative to darwin/Classes/ instead?

# Depth of the link inside ios/Classes/
link_depth=$(echo "$platform_link" | awk -F '/' '{print NF-1}')
up=$(printf '../%.0s' $(seq 1 "$link_depth"))
ln -sf "${up}darwin/Classes/$rel" "$platform_link"

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.

Same problem as above down here — the ios/macos links resolve to /darwin/Classes/... and miss the auth0_flutter/ prefix, so they're all broken too. I counted 183 dangling symlinks total across darwin/ios/macos. Worth adding a quick test that actually resolves the links after generating them.

s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.source_files = 'auth0_flutter/Sources/auth0_flutter/**/*.{h,m,swift}'
s.public_header_files = 'auth0_flutter/Sources/auth0_flutter/include/**/*.h'

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.

There's no include/ folder (or any .h/.m files) under Sources/auth0_flutter/ anymore since we dropped the ObjC shim, so this public_header_files line and the .{h,m} part of source_files above will just make CocoaPods warn about missing files. Can we trim these down to Swift-only?

working-directory: auth0_flutter/example/ios
run: bundle exec slather coverage -x --scheme Runner Runner.xcodeproj
run: |
brew install a7ex/homebrew-formulae/xcresultparser

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.

This installs xcresultparser unpinned from a third-party tap on every run — bit risky for reproducibility and supply chain, and it'll break coverage silently if the CLI flags change upstream. Could we pin a version?

Comment thread auth0_flutter/example/pubspec.yaml
.library(name: "auth0-flutter", targets: ["auth0_flutter"]),
],
dependencies: [
.package(url: "https://github.com/auth0/Auth0.swift", .upToNextMajor(from: "2.21.2")),

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.

SPM uses .upToNextMajor(from: "2.21.2") for Auth0.swift but the podspecs pin 2.21.2 exactly, and Package.resolved already moved to 2.22.0. So the SPM and CocoaPods paths can end up on different versions. Fine if that's on purpose, just flagging.

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