Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(functions): migrate cloud functions Apple implementation to Swift #17232

Merged
merged 6 commits into from
Mar 26, 2025

Conversation

SelaseKay
Copy link
Contributor

Description

Replace this paragraph with a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change.

Related Issues

Replace this paragraph with a list of issues related to this PR from the issue database. Indicate, which of these issues are resolved or fixed by this PR. Note that you'll have to prefix the issue numbers with flutter/flutter#.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide).
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • I signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

Copy link
Member

@russellwheatley russellwheatley left a comment

Choose a reason for hiding this comment

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

Need to test this via SPM build. Remove old .h and .m cloud functions files. Also need to update the Package.swift file, removing these: https://github.com/firebase/flutterfire/blob/feat/cloud_functions_stream_support/packages/cloud_functions/cloud_functions/ios/cloud_functions/Package.swift#L108-L113

// found in the LICENSE file.

// Auto-generated file. Do not edit.
public let versionNumber = "5.3.4"
Copy link
Member

Choose a reason for hiding this comment

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

cloud_functions will need adding here to update Constants.swift when we publish release: https://github.com/firebase/flutterfire/blob/feat/cloud_functions_stream_support/scripts/generate_versions_spm.dart#L134

s.ios.deployment_target = '13.0'

s.swift_version = '5.5'
Copy link
Member

Choose a reason for hiding this comment

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

can probably lower this to 5.0

Copy link
Member

@russellwheatley russellwheatley left a comment

Choose a reason for hiding this comment

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

You will have to symlink the new Swift file in macOS.

  • In terminal, root to directory you want to symlink to (i.e. macos/cloud_functions/....),
  • run command:
ln -s [RELATIVE PATH TO IOS FILE YOU WANT TO SYMLINK] [NAME OF FILE YOU WANT TO SYMLINK IN MACOS]

Here is an example to help you:

ln -s ../../../packages/firebase_core/firebase_core/ios/firebase_core/Sources/firebase_core/include/firebase_core/messages.g.h messages.g.h

Do this for both new Swift files; Constants.swift, FirebaseFunctionsPlugin.swift.

You will also need to edit the podspec and Package.swift file in macos/ directory like what you have done for iOS.

Copy link
Member

@russellwheatley russellwheatley left a comment

Choose a reason for hiding this comment

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

Also need to edit both podspecs this property: pod_target_xcconfig so it looks like this as we now set them from within Swift code: https://github.com/firebase/flutterfire/blob/main/packages/firebase_app_installations/firebase_app_installations/ios/firebase_app_installations.podspec#L38-L40

Also test macOS on cocoapods and SPM build. Thanks 😄

}

@objc public func firebaseLibraryName() -> String {
"flutter-fire-functions"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"flutter-fire-functions"
"flutter-fire-fn"

This needs to match what it was previously in podspec

Comment on lines 126 to 132
} catch {
completion(nil, FlutterError(
code: "illegal_argument",
message: error.localizedDescription,
details: nil
))
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this do/catch necessary? It wasn't in previous implementation and we catch or pass exception back via completion handler

Comment on lines 104 to 109
throw NSError(
domain: "com.firebase.functions",
code: -1,
userInfo: [
NSLocalizedDescriptionKey: "Either functionName or functionUri must be set",
]
Copy link
Member

Choose a reason for hiding this comment

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

this should just pass exception to completion handler like in previous implementation

Comment on lines 87 to 91
if let origin, !origin.isEmpty {
if let url = URL(string: origin) {
functions.useEmulator(withHost: url.host ?? "", port: url.port ?? 5001)
}
}
Copy link
Member

Choose a reason for hiding this comment

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

should also check that origin and port are defined rather than coalescing to empty string and passing default port.

Copy link
Member

@russellwheatley russellwheatley left a comment

Choose a reason for hiding this comment

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

I think that is the last bit from me, other than that, LGTM

@russellwheatley russellwheatley changed the title feat: migrate cloud functions ios implementation to swift feat(functions): migrate cloud functions Apple implementation to Swift Mar 26, 2025
@SelaseKay SelaseKay merged commit 9ebc7bc into main Mar 26, 2025
29 of 30 checks passed
@SelaseKay SelaseKay deleted the feat-functions-migration-swift branch March 26, 2025 16:21
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.

3 participants