-
Notifications
You must be signed in to change notification settings - Fork 4k
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): Swift Package Manager support #16770
Open
russellwheatley
wants to merge
15
commits into
main
Choose a base branch
from
functions-spm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
d93ef84
feat(functions): Swift Package Manager support
russellwheatley 4c6a0bf
chore: update Package.swift
russellwheatley 09860ca
update podspec
russellwheatley 1f9215e
macos initial
russellwheatley 2edb494
update podspec and package.swift
russellwheatley 2626770
macos podspec
russellwheatley cfbd009
final macos package.swift
russellwheatley 6bf5926
test: functions swift integration
russellwheatley 80c90e8
fix: add @ symbol to string
russellwheatley 04b108c
test: fix script
russellwheatley f3af3d6
last updates
russellwheatley 6fe57d9
more fixes
russellwheatley 181dcad
fix
russellwheatley ffd6353
format
russellwheatley 64bc216
fix: macos
russellwheatley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/cloud_functions/cloud_functions/example/ios/Flutter/Debug.xcconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
#include "Generated.xcconfig" |
2 changes: 1 addition & 1 deletion
2
packages/cloud_functions/cloud_functions/example/ios/Flutter/Release.xcconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
#include "Generated.xcconfig" |
2 changes: 1 addition & 1 deletion
2
packages/cloud_functions/cloud_functions/example/macos/Flutter/Flutter-Debug.xcconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" | ||
#include "ephemeral/Flutter-Generated.xcconfig" |
2 changes: 1 addition & 1 deletion
2
packages/cloud_functions/cloud_functions/example/macos/Flutter/Flutter-Release.xcconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" | ||
#include "ephemeral/Flutter-Generated.xcconfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/cloud_functions/cloud_functions/ios/cloud_functions/Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// swift-tools-version: 5.9 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
// Copyright 2024, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import Foundation | ||
import PackageDescription | ||
|
||
enum ConfigurationError: Error { | ||
case fileNotFound(String) | ||
case parsingError(String) | ||
case invalidFormat(String) | ||
} | ||
|
||
let functionsDirectory = String(URL(string: #file)!.deletingLastPathComponent().absoluteString | ||
.dropLast()) | ||
|
||
func loadFirebaseSDKVersion() throws -> String { | ||
let firebaseCoreScriptPath = NSString.path(withComponents: [ | ||
functionsDirectory, | ||
"..", | ||
"generated_firebase_sdk_version.txt", | ||
]) | ||
do { | ||
let version = try String(contentsOfFile: firebaseCoreScriptPath, encoding: .utf8) | ||
.trimmingCharacters(in: .whitespacesAndNewlines) | ||
return version | ||
} catch { | ||
throw ConfigurationError | ||
.fileNotFound("Error loading or parsing generated_firebase_sdk_version.txt: \(error)") | ||
} | ||
} | ||
|
||
func loadPubspecVersions() throws -> (packageVersion: String, firebaseCoreVersion: String) { | ||
let pubspecPath = NSString.path(withComponents: [functionsDirectory, "..", "..", "pubspec.yaml"]) | ||
do { | ||
let yamlString = try String(contentsOfFile: pubspecPath, encoding: .utf8) | ||
let lines = yamlString.split(separator: "\n") | ||
|
||
guard let packageVersionLine = lines.first(where: { $0.starts(with: "version:") }) else { | ||
throw ConfigurationError.invalidFormat("No package version line found in pubspec.yaml") | ||
} | ||
var packageVersion = packageVersionLine.split(separator: ":")[1] | ||
.trimmingCharacters(in: .whitespaces) | ||
.replacingOccurrences(of: "+", with: "-") | ||
packageVersion = packageVersion.replacingOccurrences(of: "^", with: "") | ||
|
||
guard let firebaseCoreVersionLine = lines.first(where: { $0.contains("firebase_core:") }) else { | ||
throw ConfigurationError | ||
.invalidFormat("No firebase_core dependency version line found in pubspec.yaml") | ||
} | ||
var firebaseCoreVersion = firebaseCoreVersionLine.split(separator: ":")[1] | ||
.trimmingCharacters(in: .whitespaces) | ||
firebaseCoreVersion = firebaseCoreVersion.replacingOccurrences(of: "^", with: "") | ||
|
||
return (packageVersion, firebaseCoreVersion) | ||
} catch { | ||
throw ConfigurationError.fileNotFound("Error loading or parsing pubspec.yaml: \(error)") | ||
} | ||
} | ||
|
||
let library_version: String | ||
let firebase_sdk_version_string: String | ||
let firebase_core_version_string: String | ||
let shared_spm_tag = "-firebase-core-swift" | ||
|
||
do { | ||
library_version = try loadPubspecVersions().packageVersion | ||
firebase_sdk_version_string = try loadFirebaseSDKVersion() | ||
firebase_core_version_string = try loadPubspecVersions().firebaseCoreVersion | ||
} catch { | ||
fatalError("Failed to load configuration: \(error)") | ||
} | ||
|
||
guard let firebase_sdk_version = Version(firebase_sdk_version_string) else { | ||
fatalError("Invalid Firebase SDK version: \(firebase_sdk_version_string)") | ||
} | ||
|
||
guard let shared_spm_version = Version("\(firebase_core_version_string)\(shared_spm_tag)") else { | ||
fatalError("Invalid firebase_core version: \(firebase_core_version_string)\(shared_spm_tag)") | ||
} | ||
|
||
let package = Package( | ||
name: "cloud_functions", | ||
platforms: [ | ||
.iOS("13.0"), | ||
], | ||
products: [ | ||
.library(name: "cloud-functions", targets: ["cloud_functions"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: firebase_sdk_version), | ||
.package(url: "https://github.com/firebase/flutterfire", exact: shared_spm_version), | ||
], | ||
targets: [ | ||
.target( | ||
name: "cloud_functions", | ||
dependencies: [ | ||
.product(name: "FirebaseFunctions", package: "firebase-ios-sdk"), | ||
// Wrapper dependency | ||
.product(name: "firebase-core-shared", package: "flutterfire"), | ||
], | ||
resources: [ | ||
.process("Resources"), | ||
], | ||
cSettings: [ | ||
.headerSearchPath("include"), | ||
.define("LIBRARY_VERSION", to: "\"\(library_version)\""), | ||
.define("LIBRARY_NAME", to: "\"flutter-fire-fn\""), | ||
] | ||
), | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/cloud_functions/cloud_functions/ios/generated_firebase_sdk_version.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
11.4.0 |
1 change: 0 additions & 1 deletion
1
packages/cloud_functions/cloud_functions/macos/Classes/FLTFirebaseFunctionsPlugin.h
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/cloud_functions/cloud_functions/macos/Classes/FLTFirebaseFunctionsPlugin.m
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
packages/cloud_functions/cloud_functions/macos/cloud_functions/Package.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
// swift-tools-version: 5.9 | ||
// The swift-tools-version declares the minimum version of Swift required to build this package. | ||
|
||
// Copyright 2024, the Chromium project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import Foundation | ||
import PackageDescription | ||
|
||
enum ConfigurationError: Error { | ||
case fileNotFound(String) | ||
case parsingError(String) | ||
case invalidFormat(String) | ||
} | ||
|
||
let functionsDirectory = String(URL(string: #file)!.deletingLastPathComponent().absoluteString | ||
.dropLast()) | ||
|
||
func loadFirebaseSDKVersion() throws -> String { | ||
let firebaseCoreScriptPath = NSString.path(withComponents: [ | ||
functionsDirectory, | ||
"..", | ||
"..", | ||
"ios", | ||
"generated_firebase_sdk_version.txt", | ||
]) | ||
do { | ||
let version = try String(contentsOfFile: firebaseCoreScriptPath, encoding: .utf8) | ||
.trimmingCharacters(in: .whitespacesAndNewlines) | ||
return version | ||
} catch { | ||
throw ConfigurationError | ||
.fileNotFound("Error loading or parsing generated_firebase_sdk_version.txt: \(error)") | ||
} | ||
} | ||
|
||
func loadPubspecVersions() throws -> (packageVersion: String, firebaseCoreVersion: String) { | ||
let pubspecPath = NSString.path(withComponents: [functionsDirectory, "..", "..", "pubspec.yaml"]) | ||
do { | ||
let yamlString = try String(contentsOfFile: pubspecPath, encoding: .utf8) | ||
let lines = yamlString.split(separator: "\n") | ||
|
||
guard let packageVersionLine = lines.first(where: { $0.starts(with: "version:") }) else { | ||
throw ConfigurationError.invalidFormat("No package version line found in pubspec.yaml") | ||
} | ||
var packageVersion = packageVersionLine.split(separator: ":")[1] | ||
.trimmingCharacters(in: .whitespaces) | ||
.replacingOccurrences(of: "+", with: "-") | ||
packageVersion = packageVersion.replacingOccurrences(of: "^", with: "") | ||
|
||
guard let firebaseCoreVersionLine = lines.first(where: { $0.contains("firebase_core:") }) else { | ||
throw ConfigurationError | ||
.invalidFormat("No firebase_core dependency version line found in pubspec.yaml") | ||
} | ||
var firebaseCoreVersion = firebaseCoreVersionLine.split(separator: ":")[1] | ||
.trimmingCharacters(in: .whitespaces) | ||
firebaseCoreVersion = firebaseCoreVersion.replacingOccurrences(of: "^", with: "") | ||
|
||
return (packageVersion, firebaseCoreVersion) | ||
} catch { | ||
throw ConfigurationError.fileNotFound("Error loading or parsing pubspec.yaml: \(error)") | ||
} | ||
} | ||
|
||
let library_version: String | ||
let firebase_sdk_version_string: String | ||
let firebase_core_version_string: String | ||
let shared_spm_tag = "-firebase-core-swift" | ||
|
||
do { | ||
library_version = try loadPubspecVersions().packageVersion | ||
firebase_sdk_version_string = try loadFirebaseSDKVersion() | ||
firebase_core_version_string = try loadPubspecVersions().firebaseCoreVersion | ||
} catch { | ||
fatalError("Failed to load configuration: \(error)") | ||
} | ||
|
||
guard let firebase_sdk_version = Version(firebase_sdk_version_string) else { | ||
fatalError("Invalid Firebase SDK version: \(firebase_sdk_version_string)") | ||
} | ||
|
||
guard let shared_spm_version = Version("\(firebase_core_version_string)\(shared_spm_tag)") else { | ||
fatalError("Invalid firebase_core version: \(firebase_core_version_string)\(shared_spm_tag)") | ||
} | ||
|
||
let package = Package( | ||
name: "cloud_functions", | ||
platforms: [ | ||
.macOS("10.15"), | ||
], | ||
products: [ | ||
.library(name: "cloud-functions", targets: ["cloud_functions"]), | ||
], | ||
dependencies: [ | ||
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: firebase_sdk_version), | ||
.package(url: "https://github.com/firebase/flutterfire", exact: shared_spm_version), | ||
], | ||
targets: [ | ||
.target( | ||
name: "cloud_functions", | ||
dependencies: [ | ||
.product(name: "FirebaseFunctions", package: "firebase-ios-sdk"), | ||
// Wrapper dependency | ||
.product(name: "firebase-core-shared", package: "flutterfire"), | ||
], | ||
resources: [ | ||
.process("Resources"), | ||
], | ||
cSettings: [ | ||
.headerSearchPath("include"), | ||
.define("LIBRARY_VERSION", to: "\"\(library_version)\""), | ||
.define("LIBRARY_NAME", to: "\"flutter-fire-fn\""), | ||
] | ||
), | ||
] | ||
) |
1 change: 1 addition & 0 deletions
1
...loud_functions/macos/cloud_functions/Sources/cloud_functions/FLTFirebaseFunctionsPlugin.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../ios/cloud_functions/Sources/cloud_functions/FLTFirebaseFunctionsPlugin.m |
File renamed without changes.
1 change: 1 addition & 0 deletions
1
...ctions/macos/cloud_functions/Sources/cloud_functions/include/FLTFirebaseFunctionsPlugin.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../../ios/cloud_functions/Sources/cloud_functions/include/FLTFirebaseFunctionsPlugin.h |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this could be shared between different plugins? Or is this generated for each one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not possible in a clean way. Can't import local files into Package.swift and can't specify a dependency to be used in Package.swift 😔