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(perf): Swift Package Manager support #16849

Merged
merged 9 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/all_plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ jobs:
runs-on: macos-latest
timeout-minutes: 30
env:
FLUTTER_DEPENDENCIES: "cloud_firestore firebase_remote_config cloud_functions firebase_database firebase_auth firebase_storage firebase_analytics firebase_messaging firebase_app_check firebase_in_app_messaging"
FLUTTER_DEPENDENCIES: "cloud_firestore firebase_remote_config cloud_functions firebase_database firebase_auth firebase_storage firebase_analytics firebase_messaging firebase_app_check firebase_in_app_messaging firebase_performance"
steps:
- uses: actions/checkout@d632683dd7b4114ad314bca15554477dd762a938
- uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/scripts/swift-integration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Future<void> buildSwiftExampleApp(String platform, String plugins) async {

print('Building example app with swift (SPM) integration for $plugins');

final directory = Directory('packages/firebase_core/firebase_core/example/$platform');
final directory =
Directory('packages/firebase_core/firebase_core/example/$platform');
if (!directory.existsSync()) {
print('Directory does not exist: ${directory.path}');
exit(1);
Expand Down
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"
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"
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ Pod::Spec.new do |s|
s.license = { :file => '../LICENSE' }
s.authors = 'The Chromium Authors'
s.source = { :path => '.' }
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.source_files = 'firebase_performance/Sources/firebase_performance/**/*.{h,m}'
s.public_header_files = 'firebase_performance/Sources/firebase_performance/include/*.h'
s.dependency 'Flutter'
s.dependency 'firebase_core'
s.dependency 'Firebase/Performance', firebase_sdk_version
s.ios.deployment_target = '13.0'
s.static_framework = true

s.pod_target_xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => "LIBRARY_VERSION=\\@\\\"#{library_version}\\\" LIBRARY_NAME=\\@\\\"flutter-fire-perf\\\"",
'GCC_PREPROCESSOR_DEFINITIONS' => "LIBRARY_VERSION=\\\"#{library_version}\\\" LIBRARY_NAME=\\\"flutter-fire-perf\\\"",
'DEFINES_MODULE' => 'YES'
}
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// 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 performanceDirectory = String(URL(string: #file)!.deletingLastPathComponent().absoluteString
.dropLast())

func loadFirebaseSDKVersion() throws -> String {
let firebaseCoreScriptPath = NSString.path(withComponents: [
performanceDirectory,
"..",
"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: [
performanceDirectory,
"..",
"..",
"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: "firebase_performance",
platforms: [
.iOS("13.0"),
],
products: [
.library(name: "firebase-performance", targets: ["firebase_performance"]),
],
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: "firebase_performance",
dependencies: [
.product(name: "FirebasePerformance", 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-perf\""),
]
),
]
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

#import "FLTFirebasePerformancePlugin.h"

#if __has_include(<firebase_core/FLTFirebasePluginRegistry.h>)
#import <firebase_core/FLTFirebasePluginRegistry.h>
#else
#import <FLTFirebasePluginRegistry.h>
#endif

NSString *const kFLTFirebasePerformanceChannelName = @"plugins.flutter.io/firebase_performance";

Expand Down Expand Up @@ -214,11 +218,11 @@ - (NSDictionary *_Nonnull)pluginConstantsForFIRApp:(FIRApp *)firebase_app {
}

- (NSString *_Nonnull)firebaseLibraryName {
return LIBRARY_NAME;
return @LIBRARY_NAME;
}

- (NSString *_Nonnull)firebaseLibraryVersion {
return LIBRARY_VERSION;
return @LIBRARY_VERSION;
}

- (NSString *_Nonnull)flutterChannelName {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
@import FirebasePerformance;
#import <Flutter/Flutter.h>
#import <TargetConditionals.h>
#if __has_include(<firebase_core/FLTFirebasePlugin.h>)
#import <firebase_core/FLTFirebasePlugin.h>
#else
#import <FLTFirebasePlugin.h>
#endif

@interface FLTFirebasePerformancePlugin : FLTFirebasePlugin <FlutterPlugin, FLTFirebasePlugin>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
11.4.0
Loading