feat: Swift Package Manager dependency support for Flutter iOS/macOS SDK#804
feat: Swift Package Manager dependency support for Flutter iOS/macOS SDK#804NandanPrabhu wants to merge 13 commits into
Conversation
29e7c3d to
4128680
Compare
fd7f369 to
d3b8c46
Compare
d3b8c46 to
035c772
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
If you'd like a full re-review of all changes in this PR (not just new commits), I can trigger that: ✅ Action performedFull review finished. |
✅ Action performedReview finished.
|
✅ Action performedFull review finished. |
✅ Action performedFull review finished. |
|
@coderabbitai full review |
✅ Action performedFull 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 |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
| .library(name: "auth0-flutter", targets: ["auth0_flutter"]), | ||
| ], | ||
| dependencies: [ | ||
| .package(url: "https://github.com/auth0/Auth0.swift", .upToNextMajor(from: "2.21.2")), |
There was a problem hiding this comment.
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.
📋 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
auth0_flutter/darwin/auth0_flutter/Package.swiftdeclaring theauth0_flutterSPM target (iOS 14 / macOS 11), depending on Auth0.swift ≥ 2.21.2, JWTDecode.swift 3.3.0, and SimpleKeychain 1.3.0.sharedDarwinSource: trueinpubspec.yamlso Flutter resolves iOS and macOS from a single source tree underdarwin/auth0_flutter/Sources/auth0_flutter/.PASSKEYS_PLATFORMSwift compilation condition viaswiftSettingsinPackage.swift(previously only provided by the CocoaPods podspec).CocoaPods fallback (retained)
auth0_flutter/darwin/auth0_flutter.podspecupdated to pointsource_filesatSources/auth0_flutter/— the canonical location shared with SPM.ios/andmacos/podspecs kept for CocoaPods consumers; theirClasses/directories contain symlinks intodarwin/Classes/, which in turn symlink toSources/auth0_flutter/.scripts/generate-symlinks.shscript regenerates the full symlink chain (darwin/Classes/ → Sources/,ios/Classes/ → darwin/Classes/,macos/Classes/ → darwin/Classes/) and is enforced by theSymlinksCI job on every PR.Plugin entry point
Auth0FlutterPlugin.h/.m) and renamesSwiftAuth0FlutterPlugin→Auth0FlutterPluginto match thepluginClassdeclared inpubspec.yaml. No public Dart API change.CI
setup-darwin: sets up Xcode beforeflutter pub get, enables SPM (flutter config --enable-swift-package-manager), caches and installs CocoaPods, then patches the Flutter-generatedFlutterGeneratedPluginSwiftPackage/Package.swiftdeployment targets to 14.0 (iOS) / 11.0 (macOS).unit-tests-darwin: runsxcodebuild testagainstRunner.xcworkspace(CocoaPods workspace, which includes the SPM-resolved plugin)..xcresultto Cobertura XML viaxcresultparserbefore the Codecov upload..github/workflows/check-symlinks.ymlCI job that runsscripts/generate-symlinks.shand fails if any symlink is out of sync.Tests
Auth0FlutterPluginTests.credentialsManager.store(credentials:)instead of hand-builtNSKeyedArchiverfixtures.📎 References
🎯 Testing
xcodebuildagainstRunner.xcworkspace(Xcode 26.2); Android and Windows unit suites unchanged.SymlinksCI job validates thatdarwin/Classes/,ios/Classes/, andmacos/Classes/symlinks are consistent withSources/auth0_flutter/on every PR.auth0_flutter/example, runflutter config --enable-swift-package-managerthenflutter runon an iOS simulator or device; exercise login/logout, credentials manager, and DPoP flows.flutter config --no-enable-swift-package-managerand building the example app.