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(core): support for using SPM (Swift Package Manager) #12786

Merged
merged 49 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3b81fa1
feat(core): support for package swift
russellwheatley May 15, 2024
09aa361
chore: core example app updates
russellwheatley May 15, 2024
3ff39e5
fix: package integration requires exact package name
russellwheatley May 16, 2024
b9f7df9
ios updates
russellwheatley May 17, 2024
0f29a97
hide package.resolved
russellwheatley May 17, 2024
01adfca
chore: remove ios config
russellwheatley May 17, 2024
f17a719
format
russellwheatley May 17, 2024
04a671f
fix up the pigeon setup
russellwheatley May 17, 2024
5250627
license for Package.swift
russellwheatley May 17, 2024
e02ba2c
update preprocessor definitions for podspec and package.swift
russellwheatley May 17, 2024
a56af80
update code for LIBRARY_NAME & LIBRARY_VERSION
russellwheatley May 17, 2024
bd55dff
working version
russellwheatley May 17, 2024
ea62464
Merge branch 'master' into spm-core-2
russellwheatley May 22, 2024
5ae50bf
works on `flutter run` but not in Xcode
russellwheatley May 23, 2024
5a2ede9
hard code lib versions
russellwheatley May 23, 2024
f55f0c6
format
russellwheatley May 23, 2024
c4ea595
move macos
russellwheatley May 23, 2024
6a73e6a
fix symlink
russellwheatley May 23, 2024
f503c29
Discard changes to packages/firebase_core/firebase_core/ios/firebase_…
russellwheatley May 23, 2024
d2adbef
update core ios podspec after mistakenly reverting changes
russellwheatley May 24, 2024
41f2321
fix: macOS.podspec header/source files
russellwheatley May 24, 2024
2b1ebe7
ci: integrationt test for SPM firebase_core
russellwheatley May 24, 2024
764bb5f
update integration test
russellwheatley May 24, 2024
b520a67
no-codesign
russellwheatley May 24, 2024
7cc820b
pod deintegrate
russellwheatley May 24, 2024
a9d02ad
check build is successful as well
russellwheatley May 24, 2024
31c3935
update Package.swift with ability to get versions dynamically
russellwheatley May 24, 2024
4b78c08
rm unused output
russellwheatley May 24, 2024
11d3ee6
get exitcode
russellwheatley May 24, 2024
e01ffdd
macos package swift
russellwheatley May 28, 2024
7d3d225
rm macos from iOS package swift
russellwheatley May 28, 2024
5d95766
ci: swift integration into own shell script + macos build
russellwheatley May 28, 2024
df77338
optional include for macOS release
russellwheatley May 28, 2024
7613444
update swift script
russellwheatley May 28, 2024
1329b2e
debug script
russellwheatley May 28, 2024
a021747
update macos test
russellwheatley May 28, 2024
a3c7a66
incorrect mac path
russellwheatley May 28, 2024
b9379b4
stop exiting script
russellwheatley May 28, 2024
6c6d828
Merge branch 'master' into spm-core-2
russellwheatley May 31, 2024
95ade96
Apply suggestions from code review
russellwheatley Sep 4, 2024
8100b13
chore(core): bump ios version for swift
russellwheatley Sep 4, 2024
9ca913f
Merge branch 'main' into spm-core-2
russellwheatley Sep 4, 2024
1eaa3d1
chore(core): bump minimum macOS version
russellwheatley Sep 4, 2024
15a4d36
Merge branch 'main' into spm-core-2
russellwheatley Sep 11, 2024
0107af0
test: clean up disk space on macOS runner
russellwheatley Sep 11, 2024
0fb8313
test: further clean up
russellwheatley Sep 11, 2024
3fcaeb1
test: remove swift clean up
russellwheatley Sep 11, 2024
4d81d07
test: remove further clean up
russellwheatley Sep 11, 2024
758c3cb
chore(core): move to iOS 13 for core swift
russellwheatley Sep 12, 2024
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
18 changes: 17 additions & 1 deletion .github/workflows/all_plugins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,23 @@ jobs:
run: |
melos exec -c 1 --scope="*example*" --dir-exists="web" -- \
"flutter build web"

swift-integration:
runs-on: macos-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: subosito/flutter-action@2783a3f08e1baf891508463f8c6653c258246225
with:
# TODO - enabling swift is on `master` channel at the moment. Update when it's on `stable`
channel: 'master'
- uses: bluefireteam/melos-action@5a8367ec4b9942d712528c398ff3f996e03bc230
with:
melos-version: '5.3.0'
- name: 'Swift Integration Setup'
run: flutter config --enable-swift-package-manager
- name: 'Build Apps with Swift Package Manager'
run: ./.github/workflows/scripts/swift-integration.sh

test:
runs-on: ubuntu-latest
timeout-minutes: 30
Expand Down
17 changes: 17 additions & 0 deletions .github/workflows/ios.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,23 @@ jobs:
- name: 'Install Tools'
run: |
sudo npm i -g firebase-tools
- name: 'Free up space'
run: |
sudo rm -rf \
/usr/local/share/.cache \
/Users/runner/Library/Caches \
/Users/runner/Library/Developer/Xcode/DerivedData \
/Users/runner/Library/Developer/CoreSimulator/Caches \
/opt/microsoft/msedge \
/opt/microsoft/powershell \
/opt/pipx \
/usr/lib/mono \
/usr/local/julia* \
/usr/local/lib/android \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/dotnet
df -h /
- name: 'Build Application'
working-directory: ${{ matrix.working_directory }}
run: |
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/scripts/swift-integration.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

set -e

# Just Core example has pure Swift capability at the moment


# firebase_core iOS example

# Setup for SPM integration
cd packages/firebase_core/firebase_core/example/ios
rm Podfile
pod deintegrate

# Run the flutter build command and capture the output and exit status
flutter_output=$(flutter build ios --no-codesign)
flutter_exit_code=$?

# Check if the flutter build command was successful
if [[ $flutter_exit_code -ne 0 ]]; then
echo "Flutter build failed with exit code $flutter_exit_code."
exit 1
fi

# Check the output for the specific string
if [[ "$flutter_output" =~ "Running pod install" ]]; then
exit 1
else
echo "Successfully built iOS project using Swift Package Manager."
fi

# firebase_core macOS example

# Setup for SPM integration
cd ../macos
rm Podfile
pod deintegrate

# Run the flutter build command and capture the output and exit status
flutter_output=$(flutter build macos)
flutter_exit_code=$?

# Check if the flutter build command was successful
if [[ $flutter_exit_code -ne 0 ]]; then
echo "Flutter build failed with exit code $flutter_exit_code."
exit 1
fi

# Check the output for the specific string
if [[ "$flutter_output" =~ "Running pod install" ]]; then
exit 1
else
echo "Successfully built macOS project using Swift Package Manager."
exit 0
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ flutter_export_environment.sh

examples/all_plugins/pubspec.yaml

Package.resolved
Podfile.lock
Pods/
.symlinks/
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 @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = 78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */; };
russellwheatley marked this conversation as resolved.
Show resolved Hide resolved
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
Expand Down Expand Up @@ -56,6 +57,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
78A318202AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage in Frameworks */,
CC8B39E3ACF96AAA7558280C /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -149,13 +151,15 @@
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
FE9FCD1596DCB6AB2B208201 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
dependencies = (
);
name = Runner;
packageProductDependencies = (
78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */,
);
productName = Runner;
productReference = 97C146EE1CF9000F007C117D /* Runner.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -184,6 +188,9 @@
Base,
);
mainGroup = 97C146E51CF9000F007C117D;
packageReferences = (
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */,
);
productRefGroup = 97C146EF1CF9000F007C117D /* Products */;
projectDirPath = "";
projectRoot = "";
Expand Down Expand Up @@ -261,30 +268,6 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
};
FE9FCD1596DCB6AB2B208201 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/FirebaseCore/FirebaseCore.framework",
"${BUILT_PRODUCTS_DIR}/FirebaseCoreInternal/FirebaseCoreInternal.framework",
"${BUILT_PRODUCTS_DIR}/GoogleUtilities/GoogleUtilities.framework",
"${BUILT_PRODUCTS_DIR}/PromisesObjC/FBLPromises.framework",
);
name = "[CP] Embed Pods Frameworks";
outputPaths = (
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCore.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FirebaseCoreInternal.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/GoogleUtilities.framework",
"${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/FBLPromises.framework",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
Expand Down Expand Up @@ -580,6 +563,20 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCLocalSwiftPackageReference section */
781AD8BC2B33823900A9FFBB /* XCLocalSwiftPackageReference "FlutterGeneratedPluginSwiftPackage" */ = {
isa = XCLocalSwiftPackageReference;
relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage;
};
/* End XCLocalSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
78A3181F2AECB46A00862997 /* FlutterGeneratedPluginSwiftPackage */ = {
isa = XCSwiftPackageProductDependency;
productName = FlutterGeneratedPluginSwiftPackage;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 97C146E61CF9000F007C117D /* Project object */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<PreActions>
<ExecutionAction
ActionType = "Xcode.IDEStandardExecutionActionsCore.ExecutionActionType.ShellScriptAction">
<ActionContent
title = "Run Prepare Flutter Framework Script"
scriptText = "/bin/sh &quot;$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh&quot; prepare&#10;">
<EnvironmentBuildable>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "97C146ED1CF9000F007C117D"
BuildableName = "Runner.app"
BlueprintName = "Runner"
ReferencedContainer = "container:Runner.xcodeproj">
</BuildableReference>
</EnvironmentBuildable>
</ActionContent>
</ExecutionAction>
</PreActions>
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
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.release.xcconfig"
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "ephemeral/Flutter-Generated.xcconfig"
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ 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_core/Sources/firebase_core/**/*.{h,m}'
s.public_header_files = 'firebase_core/Sources/firebase_core/include/**/*.h'

s.ios.deployment_target = '13.0'

Expand All @@ -37,7 +37,7 @@ Pod::Spec.new do |s|

s.static_framework = true
s.pod_target_xcconfig = {
'GCC_PREPROCESSOR_DEFINITIONS' => "LIBRARY_VERSION=\\@\\\"#{library_version}\\\" LIBRARY_NAME=\\@\\\"flutter-fire-core\\\"",
'GCC_PREPROCESSOR_DEFINITIONS' => "LIBRARY_VERSION=\\\"#{library_version}\\\" LIBRARY_NAME=\\\"flutter-fire-core\\\"",
'DEFINES_MODULE' => 'YES'
}
end
110 changes: 110 additions & 0 deletions packages/firebase_core/firebase_core/ios/firebase_core/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// 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 iosRootDirectory = String(URL(string: #file)!.deletingLastPathComponent().absoluteString
.dropLast())

func loadPubspecVersion() throws -> String {
let pubspecPath = NSString.path(withComponents: [iosRootDirectory, "..", "..", "pubspec.yaml"])
do {
let yamlString = try String(contentsOfFile: pubspecPath, encoding: .utf8)
if let versionLine = yamlString.split(separator: "\n")
.first(where: { $0.starts(with: "version:") }) {
let version = versionLine.split(separator: ":")[1].trimmingCharacters(in: .whitespaces)
return version.replacingOccurrences(of: "+", with: "-")
} else {
throw ConfigurationError.invalidFormat("No version line found in pubspec.yaml")
}
} catch {
throw ConfigurationError.fileNotFound("Error loading or parsing pubspec.yaml: \(error)")
}
}

func loadFirebaseSDKVersion() throws -> String {
let firebaseCoreScriptPath = NSString.path(withComponents: [
iosRootDirectory,
"..",
"..",
"..",
"firebase_core",
"ios",
"firebase_sdk_version.rb",
])
do {
let content = try String(contentsOfFile: firebaseCoreScriptPath, encoding: .utf8)
let pattern = #"def firebase_sdk_version!\(\)\n\s+'([^']+)'\nend"#
if let regex = try? NSRegularExpression(pattern: pattern, options: []),
let match = regex.firstMatch(
in: content,
range: NSRange(content.startIndex..., in: content)
) {
if let versionRange = Range(match.range(at: 1), in: content) {
return String(content[versionRange])
} else {
throw ConfigurationError.invalidFormat("Invalid format in firebase_sdk_version.rb")
}
} else {
throw ConfigurationError.parsingError("No match found in firebase_sdk_version.rb")
}
} catch {
throw ConfigurationError
.fileNotFound("Error loading or parsing firebase_sdk_version.rb: \(error)")
}
}

let library_version: String
let firebase_sdk_version_string: String

do {
library_version = try loadPubspecVersion()
firebase_sdk_version_string = try loadFirebaseSDKVersion()
} 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)")
}

let package = Package(
name: "firebase_core",
platforms: [
.iOS("12.0"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch 👍

],
products: [
.library(name: "firebase-core", targets: ["firebase_core"]),
],
dependencies: [
.package(url: "https://github.com/firebase/firebase-ios-sdk", from: firebase_sdk_version),
],
targets: [
.target(
name: "firebase_core",
dependencies: [
// No product for firebase-core so we pull in the smallest one
.product(name: "FirebaseInstallations", package: "firebase-ios-sdk"),
],
resources: [
.process("Resources"),
],
cSettings: [
.headerSearchPath("include/firebase_core"),
.define("LIBRARY_VERSION", to: "\"\(library_version)\""),
.define("LIBRARY_NAME", to: "\"flutter-fire-core\""),
]
),
]
)
Loading
Loading