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

Support building via the Swift Package Manager #4555

Closed
Arvin-J opened this issue Jan 17, 2017 · 36 comments
Closed

Support building via the Swift Package Manager #4555

Arvin-J opened this issue Jan 17, 2017 · 36 comments

Comments

@Arvin-J
Copy link

Arvin-J commented Jan 17, 2017

The Swift Package Manager supports building C, C++, Objective-C, Objective-C++ and Swift, so it should be possible to support building Realm Swift via SwiftPM. This is a requirement to being able to build Realm Swift on Linux (#3263).

@jpsim
Copy link
Contributor

jpsim commented Jan 17, 2017

Hi @flyingnoob thanks for your interest in Realm! We're tracking SwiftPM support as part of a larger task to take preliminary steps towards making a proof-of-concept demonstration of Realm Swift building on Linux. However, it might make sense for this task to be specifically tracked on its own, so I'll keep this ticket alive but will edit it to clarify exactly what this means.

Don't hold your breath for SwiftPM support, however. Realm already officially supports at least 4-5 separate installation methods and each one requires a significant amount of infrastructure, testing and automation, so we're not exactly keen on adding another unless the gains are worth the investment.

@jpsim jpsim changed the title suport swiftpackagemanager? Support building via the Swift Package Manager Jan 17, 2017
@hsienchiaolee
Copy link

More so than Linux support, having SwiftPM support is useful for Swift Scripts on OSX. I am currently using a pre-populated Realm database on an iOS app. Generating the database through Tests or other hacks seems less ideal than having a swift script.

However, I do understand the amount of work that would have to go into this, just thought I'd bring up more use cases. 😊

@jpsim
Copy link
Contributor

jpsim commented Jan 17, 2017

The Realm Swift framework can be used in Swift scripts as built by the different build options we currently support. It might be more convenient for you to do so via SwiftPM, but that shouldn't block you until then.

@BrandonZacharie
Copy link

BrandonZacharie commented Mar 16, 2017

My use case is similar to @hsienchiaolee. I have a project where we want to ditch CocoaPods in favor of SPM; linux support is not a concern. RealmSwift is the only dependency blocking that at the moment.

@Sajjon
Copy link

Sajjon commented Mar 25, 2017

👍 for SPM support

@mobilinked
Copy link

👍

@TimothyMDean
Copy link

TimothyMDean commented Apr 5, 2017

+1

My use case is similar: I want to use SPM for a set of modules that I'd REALLY like to ditch CocoaPods for. The use of RealmSwift in these modules is the only thing keeping me from doing that. Linux support is not a factor for me.

@fontno
Copy link

fontno commented Apr 20, 2017

👍 and thanks for the great work you guys do.

@rex-remind101
Copy link

👍

@rickw
Copy link

rickw commented Apr 28, 2017

👍 +1

(so far I have found no way to build with swift build without the library being in the Package.swift file)

@hervouinc
Copy link

👍

2 similar comments
@markjarecki
Copy link

👍

@heyzooi
Copy link

heyzooi commented Jun 1, 2017

👍

@kashifshaikh
Copy link

👍 for SPM

Well once Swift PM becomes the defacto standard, the community will probably leave cocoapods and carthage behind. It's possible that Xcode will let you add packages through a nice interface.

The swift community needs to have an easy package manager, similar to Nugets on Visual Studio.

@EmDee
Copy link

EmDee commented Jun 23, 2017

👍

We need a proper way to resolve sub-dependencies and SPM does this nicely (compared to Carthage).

@jpsim
Copy link
Contributor

jpsim commented Jul 5, 2017

Super tiny progress update. Now that swiftlang/swift-package-manager#1249 is available in a Swift snapshot, I'm able to build realm-core using SwiftPM and invoke it from Swift.

That being said, don't get too excited about this just yet, this isn't being highly prioritized and is unlikely to see much active development from within Realm for some time.

@carmen-gh
Copy link

👍

1 similar comment
@michael-betemps
Copy link

👍

@heyzooi
Copy link

heyzooi commented Jun 21, 2018

@jpsim i'm wondering if you have any news?

@jpsim
Copy link
Contributor

jpsim commented Jun 21, 2018

I don't. Perhaps someone still at Realm can comment.

@heyzooi
Copy link

heyzooi commented Jun 21, 2018

@jpsim oh i'm sorry, I didn't know that you had left the company

@heyzooi
Copy link

heyzooi commented Jun 21, 2018

@tgoyne i'm wondering if you have any news?

@heyzooi
Copy link

heyzooi commented Jun 24, 2018

I just create a PR for this:

#5828

Hopefully will be approved

@janandre
Copy link

janandre commented Jun 6, 2019

Just watching WWDC 2019 sessions. Xcode 11 now supports SPM.
I am already using the xcode11 branch, to hotfix build failures.

Would like to drop CocoaPods as soon as possible.
Whats the progress here?

@tgoyne
Copy link
Member

tgoyne commented Jun 6, 2019

SPM still intentionally doesn’t support non-system binary libraries, so we have to find a way to hack around that and make it do things it’s designed not to do.

@tgoyne
Copy link
Member

tgoyne commented Jun 7, 2019

Some good news on that front: https://twitter.com/daniel_dunbar/status/1137005810297401350

@adamawolf
Copy link

adamawolf commented Sep 6, 2019

Seems like this can be closed as SwiftPM support has been added here: #6187, thanks @tgoyne

🎉

Would be great if https://realm.io/docs/swift/latest/ could be updated with SwiftPM integration instructions.

let package = Package(
    name: "MyPackage",
    dependencies: [
        .package(
            url: "https://github.com/realm/realm-cocoa.git",
            from: "3.17.3"
        )
    ],
    ...
}

did the trick for me. ❤️

@mikemee
Copy link

mikemee commented Sep 30, 2019

FWIW, I followed the guide below with (released) Xcode 11 and was able to add Realm 3.18 to my project and remove Carthage completely:

https://medium.com/better-programming/add-swift-package-dependency-to-an-ios-project-with-xcode-11-remote-local-public-private-3a7577fac6b2

Add both Realm and RealmSwift when prompted by Xcode.

EDIT: This all appears to run fine from within Xcode, but so far neither Xcode Server nor Bitrise CI tools are able to run tests as they're both failing to build properly (for different reasons).

EDIT 2: Xcode Server was getting double link targets from an Obj-C file in my project including the generated header. Removing the #include fixed that. Bitrise CI is still failing with some weirdness, so I'm disabling that.

Overall, CI builds are now ~6 minutes longer than with Carthage, as it seems the Realm code is complied anew every time vs just linking in the pre-compiled framework. SPM isn't all 🌹 🌹 🌹 .

EDIT 3: I had to replace the SPM Realm with the Carthage one and re-release, as some users had crashes when the SPM Realm tried to open their pre-existing Realm database. No idea what the root cause was, or even the pattern (though come to think of it, both customers who communicated with me were running iOS 10.3.x). Fortunately, switching back did fix the problem for them.

@gtroshin
Copy link

Hey!

xcodebuild command line tools use ssh protocol by default. But I see that realm-cocoa uses realm-core via https which causes problems in CI. Can it be fixed? Should I create a separate issue for it?

https://developer.apple.com/documentation/swift_packages/building_apps_that_use_swift_packages_in_continuous_integration_workflows

If you’re not using Xcode Server, use SSH–based Git URLs for your packages instead and configure your SSH credentials. Your CI pipeline likely uses the xcodebuild command directly, which requires that you set up your known_hosts file in the ~/.ssh directory of the macOS user that runs your CI tasks. xcodebuild honors your SSH configuration - there’s no additional setup required.

@tgoyne
Copy link
Member

tgoyne commented Oct 25, 2019

That is only applicable to private repositories. SPM doesn't support supplying a login to clone https-based URLs, but you don't need to log in to clone realm-core.

@gtroshin
Copy link

gtroshin commented Oct 28, 2019

That is only applicable to private repositories. SPM doesn't support supplying a login to clone https-based URLs, but you don't need to log in to clone realm-core.

@tgoyne

In case when you consume all SPM dependencies via ssh, including realm-cocoa xcodebuild cli will not be able to fetch realm-core because it used via HTTPS.

I had to fork realm-cocoa and change it in Package.swift to make it work. Should I create a new issue and attach logs so you can try to reproduce it?

@MalcolmnDEV
Copy link

Is there SPM support for RealmSwift yet ?

@ThePragmaticArt
Copy link

This support should be coming with Xcode 12 on the horizon...

@peimanrn
Copy link

Are we there yet ?

@leemaguire
Copy link
Contributor

Building with SPM is supported, but we have yet to add support for Realm Sync via SPM.

@andreasley
Copy link

Release 10.5.0 brings support for MongoDB Realm (Sync) when using SPM. Thanks, team Realm!

@tgoyne tgoyne closed this as completed Dec 17, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests