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

FR: Support for Swift Package Manager #3136

Closed
WarSunsOfPeace opened this issue Jun 4, 2019 · 108 comments · Fixed by #6312
Closed

FR: Support for Swift Package Manager #3136

WarSunsOfPeace opened this issue Jun 4, 2019 · 108 comments · Fixed by #6312

Comments

@WarSunsOfPeace
Copy link

With iOS support for Swift Package Manager in Xcode 11 can we please get that added to this project.

@google-oss-bot

This comment has been minimized.

@ryanwilson
Copy link
Member

ryanwilson commented Jun 4, 2019

Hey @w0mba7 - thanks for the report 😄

We're excited and looking into the best way we can support this as soon as we can, but there are a few dependencies and file structure changes we may need to do. We started experimenting with support on a branch at https://github.com/firebase/firebase-ios-sdk/tree/spm-master a few weeks ago and have a better idea of the approach we need.

We also started a discussion on binary framework distribution on the Swift forums but it looks like we may get some more information from a WWDC session this week titled Binary Frameworks in Swift
.

This won't be something we can do overnight but want to support it as soon as we can, there are a few bugs to work out as well (like SR-10707 that I discovered while working on adding support).

@possen
Copy link

possen commented Jun 6, 2019

#2135 linking issues.

@possen
Copy link

possen commented Jun 6, 2019

My experiment was to take the Carthage Binaries and add this to the Targets section but complains that the module map is in the wrong place:

error: package has unsupported layout;modulemap '/Users/user/Projects/RideCore/Carthage/Build/iOS/nanopb.framework/Modules/module.modulemap' should be inside the 'include' directory

moving things around in the folders and renaming did not seem to help.

     targets: [
        .target(
            name: "Core",
            dependencies: ["stuff"],
            path: "Carthage/Build/iOS",
            linkerSettings: [
                LinkerSetting.linkedFramework("FirebaseAnalytics"),
                LinkerSetting.linkedFramework("FirebaseCore"),
                LinkerSetting.linkedFramework("FirebaseDatabase"),
                LinkerSetting.linkedFramework("FirebaseMessaging"),
                LinkerSetting.linkedFramework("GoogleUtilities"),
                LinkerSetting.linkedFramework("leveldb-library"),
                LinkerSetting.linkedFramework("GoogleAppMeasurement"),
                LinkerSetting.linkedFramework("GTMSessionFetcher"),
                LinkerSetting.linkedFramework("nanopb"),
                LinkerSetting.linkedFramework("Protobuf")
            ]

@morganchen12 morganchen12 changed the title Support for Swift Package Manager FR: Support for Swift Package Manager Jun 11, 2019
@morganchen12

This comment has been minimized.

@paulb777
Copy link
Member

Follow the progress at https://github.com/firebase/firebase-ios-sdk/commits/spm-master. Suggestions and PRs welcome!

@paulb777
Copy link
Member

Much of Firebase Unit Testing relies on OCMock which does not yet support Swift PM. That could be a great place for someone in the community to contribute to accelerate the migration.

@paulb777
Copy link
Member

paulb777 commented Jul 9, 2019

For Firebase to support Swift Package Manager, there will need to be several changes to both Swift Package Manager and Firebase. See https://github.com/firebase/firebase-ios-sdk/commits/spm-master for the prototype implementation which successfully built a few of the Firebase libraries with SwiftPM. Below is a summary of some of the key requirements:

Binary library support
Some of the Firebase libraries may not open source. Thus for Firebase to completely move to SwiftPM, binary library support must be added, including support for depending on a source-based Package from a binary package. See the Swift forum discussion. The pitch to support framework search paths could provide a workaround.

Resource support
Firebase ML, Firebase In App Messaging and Firebase Firestore require resource support. There may be a workaround for Firestore, but not for the others. See Swift bug.

Separately versioned libraries per repo
Firebase currently separately versions its libraries from a single mono-repo. This could be accomplished with SwiftPM by adding multiple package support to a repo or by adding the ability to version libraries within a package. Xcode would also need to be similarly updated.

Firebase could consider abandoning separately versioning its libraries like it already does for binary and Carthage distributions. This would be especially unfortunate for managing new libraries with zero major versions of semantic versioning.

Build Settings
Some Firebase libraries rely upon being able to build some of their sources with and without Automatic Reference Counting (ARC). There does not seem to be a way to do this. See Forum discussion and Swift build setting proposal.

Module Map Generation
Objective-C modules aren't generated for Objective-C targets. This causes us to rely on changing our import statements to use local header paths instead of framework paths. See https://bugs.swift.org/browse/SR-10707

Testing - OCMock
Most of Firebase unit testing relies upon OCMock which does not yet have Swift Package Manager support.

Subspec support
Firebase relies upon subspecs so that different library combinations can choose different subsets of the GoogleUtilities support library. Now that static libraries/frameworks are better supported, it is probably feasible to split each GoogleUtilities subspec into a separate library.

Private Headers
Firebase uses the CocoaPods/Xcode private headers feature to share non-public APIs across libraries. It might be feasible for Firebase to abandon the use of this feature in favor of repo-relative import paths.

@possen
Copy link

possen commented Jul 16, 2019

Thanks for your work on this!

@possen
Copy link

possen commented Jul 18, 2019

The latest Xcode Beta 4 says under resolved issues "Swift packages that use unsafeFlags build settings can’t be used as a dependency. (50354068)" this could be a breakthrough in getting prebuilt binaries to work. It may allow "-F" to be passed as well as "no-objc-arc". Haven't tried it yet but thought I would let you know.

@ivanvorobei
Copy link

ivanvorobei commented Aug 6, 2019

Trying install spm-master branch via SPM, get this error:

Screenshot 2019-08-06 at 11 18 23

$(SRCROOT) in Package.swift

@ryanwilson
Copy link
Member

@ivanvorobei thanks for testing! Which version of Xcode are you using?

@ivanvorobei
Copy link

@ryanwilson I am use last beta of 11 Xcode.

@julienbodet
Copy link

julienbodet commented Aug 15, 2019

Trying install spm-master branch via SPM, get this error:

Screenshot 2019-08-06 at 11 18 23

$(SRCROOT) in Package.swift

I got the same error using Xcode Version 11.0 beta 5 (11M382q) when trying to add the package to my project. After a quick look at the documentation, it seems the path has to be relative to the project directory:

/// - Parameters:
///   - path: The path of the directory that contains the  headers. The path is relative to the target's directory.
///   - condition: A condition that restricts the application of the build setting.
public static func headerSearchPath(_ path: String, _ condition: PackageDescription.BuildSettingCondition? = nil) -> PackageDescription.CSetting

@paulb777
Copy link
Member

@ivanvorobei @julienbodet Thanks for the reports! Something has changed between Xcode 11 beta 2 and beta 5 that leads to this issue.

I've asked a question about it on the SwiftPM forum.

@paulb777
Copy link
Member

FYI, a forum discussion today about adding the -fno-objc-arc option to library builds. Firebase needs this in libraries that depend on Protobuf.

@vmanot
Copy link

vmanot commented Sep 18, 2019

Any update on this?

@paulb777
Copy link
Member

We'll do a full reassessment with the latest Xcode 11 in the next week or two, but it doesn't seem there has been much progress on most of the open issues.

@dvanwinkle
Copy link

@paulb777 (and anyone else working on this) Excellent work, exciting progress!

@ishabazz
Copy link

ishabazz commented Aug 3, 2020

Something changed yesterday and I can no longer update or install the package. It's worked of weeks and worked fine around 6:30 am, but I haven't been able to get it to work since sometime yesterday afternoon. Adding the package seems to work when the Firebase package is imported into another package, but adding Firebase directly or indirectly into a project fails with an error saying that the package can't be resolved. This consistently happens after the fetching of https://github.com/paulb777/nanopb.git. The error is quite long and includes some local path info but ends with rev-parse --verify '82230e9998a35a3d2144884204db64f045c880c4^{commit}' output: fatal: Needed a single revision

@paulb777
Copy link
Member

paulb777 commented Aug 3, 2020

@ishabazz It seems that SwiftPM only clones a limited set of repo branches. Our CI caught the issue and we should merge #6187 to master later today to resolve. In the meantime the branch pb-fix-git is a workaround.

@jchitel
Copy link

jchitel commented Aug 13, 2020

Are there installation instructions?

I'm new to Firebase and followed the console's setup instructions, simply swapping out the CocoaPods step with SPM (File > Add Swift Package > github URL > FirebaseAnalytics). Whatever I did was wrong because I couldn't get the SDK to actually contact the service. The only way I was able to get things working was by nixing SPM and manually downloading the frameworks, which is less than ideal.

@ttimpe
Copy link

ttimpe commented Aug 13, 2020

Are there installation instructions?

Please select the "master" branch when adding the repo as a Swift Package.

@ygee07
Copy link

ygee07 commented Aug 13, 2020

Screen Shot 2020-08-13 at 7 12 20 PM

Hi guys, I'm having a problem with FirebaseFirestore using the SPM, I'm sure I included it in the Targets -> Framework, Libraries

@jchitel
Copy link

jchitel commented Aug 13, 2020

@ttimpe That's what I did. Are things just supposed to work at that point? If I need Analytics and Crashlytics in my app, do I just need the FirebaseAnalytics and FirebaseCrashlytics packages? Or do I also need Firebase or FirebaseCore? The instructions in the console say that I should be able to import the module Firebase in my code, but that module isn't available for me via SPM. I need to use FirebaseCore instead.

@paulb777
Copy link
Member

@jchitel The Firebase module is available via SPM.

Screen Shot 2020-08-13 at 8 07 25 AM

@paulb777
Copy link
Member

@Greyder We'll likely need a reproducible example to help investigate.

@jchitel
Copy link

jchitel commented Aug 13, 2020

@paulb777 would it be better for me to create a separate issue to dig into this further? I'd rather not bloat this issue with my specific problems.

@paulb777
Copy link
Member

@jchitel Yes. Please create separate issues to discuss specific Swift Package Manager problems/questions.

@0xifarouk
Copy link

0xifarouk commented Aug 17, 2020

Hi, when I added Firebase Analytics using SPM, the app size got increased by 20 MB, I don't think that this is normal.

EDIT: I have opened an issue here with more details.

@Sherlouk
Copy link

Hey @FaroukZeino, as per Paul's comment previously it might be best to raise this as a new issue so it can be tracked and discussed on it's own.

@ramzesku
Copy link

I try connect firebase use swift package manager.

  1. Enter: https://github.com/firebase/FirebaseUI-iOS
  2. Enter branch: pb-spm

Screenshot 2020-08-19 at 19 54 42

3) Click next button.

I see error:
Showing All Messages
: package at 'https://github.com/firebase/FirebaseUI-iOS' @ 25f6725045da8f0057748af48cfa5c55651feebb is using Swift tools version 5.3.0 but the installed version is 5.2.0

What am I doing wrong?

Mac OS: 10.15.6
Xcode: 11.6

@paulb777
Copy link
Member

@ramzesku The referenced Firebase UI branch is a prototype of a small part of the API. It is not ready for use. Please follow firebase/FirebaseUI-iOS#886 for FirebaseUI.

@paulb777
Copy link
Member

Also Xcode 12 is required to use SPM with the master branch of https://github.com/firebase/firebase-ios-sdk.git. At least beta 4 is required for FirebaseAnalytics. At least beta 5 is required for SwiftUI preview support.

@khuffie
Copy link

khuffie commented Aug 23, 2020

I'm on Xcode 12 beta 5. I tried installing Firebase via SPM using the master branch and get the following error. I have Firebase, FirebaseAnalytics and FirebaseCrashlytics selected. Am I missing something in the setup process?

(Also, is Firebase Performance Monitoring available via SPM?)

Details

This app could not be installed at this time.
Domain: IXUserPresentableErrorDomain
Code: 1
Failure Reason: Could not install at this time.
Recovery Suggestion: Failed to load Info.plist from bundle at path /Users/khuffie/Library/Developer/CoreSimulator/Devices/51AC233A-4600-47F4-919D-E5640337061E/data/Library/Caches/com.apple.mobile.installd.staging/temp.NwfOQl/extracted/Widget Wizard.app/Frameworks/GoogleAppMeasurement.framework; Extra info about Info.plist: Couldn't stat /Users/khuffie/Library/Developer/CoreSimulator/Devices/51AC233A-4600-47F4-919D-E5640337061E/data/Library/Caches/com.apple.mobile.installd.staging/temp.NwfOQl/extracted/Widget Wizard.app/Frameworks/GoogleAppMeasurement.framework/Info.plist: No such file or directory
--
Failed to load Info.plist from bundle at path /Users/khuffie/Library/Developer/CoreSimulator/Devices/51AC233A-4600-47F4-919D-E5640337061E/data/Library/Caches/com.apple.mobile.installd.staging/temp.NwfOQl/extracted/Widget Wizard.app/Frameworks/GoogleAppMeasurement.framework; Extra info about Info.plist: Couldn't stat /Users/khuffie/Library/Developer/CoreSimulator/Devices/51AC233A-4600-47F4-919D-E5640337061E/data/Library/Caches/com.apple.mobile.installd.staging/temp.NwfOQl/extracted/Widget Wizard.app/Frameworks/GoogleAppMeasurement.framework/Info.plist: No such file or directory
Domain: MIInstallerErrorDomain
Code: 35
User Info: {
    FunctionName = "-[MIBundle _validateWithError:]";
    LegacyErrorString = PackageInspectionFailed;
    SourceFileLine = 131;
}
--


System Information

macOS Version 11.0 (Build 20A5343i)
Xcode 12.0 (17210.1)

@LualdiD
Copy link

LualdiD commented Aug 23, 2020

Is it possible to disable Firebase SPM when running a Catalyst app?
From the target, I set the platform for Firebase and FirebaseAnalytics to only iOS I get these 3 errors:

`
Showing All Messages
While building for Mac Catalyst, no library for this platform was found in '/Users/dylanlualdi/Library/Developer/Xcode/DerivedData/AppName-gagejbizaaploadvmidwqbbcikwt/SourcePackages/artifacts/Firebase/FirebaseAnalytics.xcframework'.

While building for Mac Catalyst, no library for this platform was found in '/Users/dylanlualdi/Library/Developer/Xcode/DerivedData/AppName-gagejbizaaploadvmidwqbbcikwt/SourcePackages/artifacts/Firebase/FIRAnalyticsConnector.xcframework'.

While building for Mac Catalyst, no library for this platform was found in '/Users/dylanlualdi/Library/Developer/Xcode/DerivedData/AppName-gagejbizaaploadvmidwqbbcikwt/SourcePackages/artifacts/Firebase/GoogleAppMeasurement.xcframework'.

`

Screenshot 2020-08-23 at 13 42 34

@paulb777
Copy link
Member

paulb777 commented Aug 23, 2020

@khuffie I'm not sure what's happening. It looks like somehow your app is trying to link GoogleAppMeasurement.framework dynamically instead of statically. Are you able to reproduce with https://github.com/firebase/quickstart-ios/tree/master/analytics?

Firebase Performance is not yet available via SPM.

@LualdiD With a quick investigation, I don't see an immediate way to disable Catalyst building for Firebase Analytics. There might be a way to temporarily adjust a Build Setting like the CocoaPods workaround, but that wouldn't be very stable. I'll follow up with the Analytics team to see if we can eliminate the sign up requirement so that we could include the Analytics Catalyst Early Access with SPM.

All, I'll reiterate the request to open a new issue for specific issues/questions like these ones. Thanks!

Swift Package Manager Support automation moved this from To do to Done Aug 25, 2020
Swift API improvements - Legacy - See also Swift API tag automation moved this from In progress to Done Aug 25, 2020
@paulb777
Copy link
Member

We're starting a Swift Package Manager beta for Firebase. To use it select the Firebase GitHub repository - https://github.com/firebase/firebase-ios-sdk.git and 6.31-spm-beta.

Limitations include:

  • Requires at least Xcode 12 beta 4.
  • SwiftUI Previews require Xcode 12 beta 5.
  • Analytics requires clients to add -ObjC linker option.
  • Analytics is only supported for iOS and cannot be used in apps that support other platforms.
  • Messaging, Performance, Firebase ML, and App Distribution are not initially available.
  • watchOS support is not initially available.

See more detailed instructions here.

I'm going to lock this issue for only future status updates.

Please create a new GitHub Issue(https://github.com/firebase/firebase-ios-sdk/issues/new?template=bug_report.md) for any questions, comments or issues about Firebase and Swift Package Manager (including for the limitations listed above).

See current open Swift Package Manager issues here.

@firebase firebase locked as resolved and limited conversation to collaborators Aug 25, 2020
@paulb777
Copy link
Member

paulb777 commented Nov 2, 2020

With the Firebase 7.0.0 release, we now support standard Swift Package Manager versioning. The beta status continues while we get the last few Firebase products supported and the Xcode Swift Package Manager implementation stabilizes.

Getting started instructions at https://github.com/firebase/firebase-ios-sdk/blob/master/SwiftPackageManager.md

Please open an issue with any questions or bugs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging a pull request may close this issue.