matrix-org / matrix-ios-sdk

The Matrix SDK for iOS
Apache License 2.0
450 stars 213 forks source link

SPM Support #760

Open theolampert opened 4 years ago

theolampert commented 4 years ago

I'm not sure if this is even possible right now or desired but having support for Swift Package Manager could be worth considering.

helje5 commented 4 years ago

I've prepared a Package.swift for the Olm stuff, we'll see whether I can get this integrated, presumably the precondition before this can fly for the SDK.

mikecsh commented 3 years ago

Hello - has there been any further movement towards SPM support? 📦

helje5 commented 3 years ago

I sent @manuroe my Olm SPM changes a few months ago, never got any subsequent feedback.

ferologics commented 3 years ago

+1

Johennes commented 3 years ago

It looks like beyond matrix-org/olm#51 and making libbase58 work with SPM (which is pretty easy given that it contains just a single source file) a real blocker is that SPM still doesn't seem to support mixed language targets.

'MatrixSDK' /Users/.../matrix-ios-sdk: error: target at '/Users/.../matrix-ios-sdk/MatrixSDK' contains mixed language source files; feature not supported

At the same time, splitting MatrixSDK into two targets by language doesn't seem possible because some of the Swift interfaces are imported back into Objective-C (see e.g. here).

So this more or less seems like a dead end until SPM adds support for mixed language targets. 😞

ferologics commented 3 years ago

@manuroe do you think it would be possible to do a small refactor of the obj-c / swift interface? Or are the two intertwined to a degree that it would prove impractical to even attempt such endeavor? If it's like 10 files then this effort would not be so invasive. I'm happy to help.

Johennes commented 3 years ago

Looks like there are 36 Swift files

$ find MatrixSDK | grep -oE "\.(swift|m)$" | sort | uniq -c
 269 .m
  36 .swift

but only four Objective-C files import the auto-generated Swift header

$ grep -r 'import.*MatrixSDKSwiftHeader.h' MatrixSDK
MatrixSDK/Crypto/Data/MXDeviceListOperationsPool.m:#import "MatrixSDKSwiftHeader.h"
MatrixSDK/MXSession.m:#import "MatrixSDKSwiftHeader.h"
MatrixSDK/Utils/MXUIKitBackgroundModeHandler.m:#import "MatrixSDKSwiftHeader.h"
MatrixSDK/Data/MXRoomSummaryUpdater.m:#import "MatrixSDKSwiftHeader.h"

MatrixSDK.h lists 13 headers as being used by Swift.

//  Bridging to Swift
#import "MXCryptoStore.h"
#import "MXRealmCryptoStore.h"
#import "MXCryptoAlgorithms.h"
#import "MXOlmDevice.h"
#import "MXEventDecryptionResult.h"
#import "MXPushRuleEventMatchConditionChecker.h"
#import "MXPushRuleDisplayNameCondtionChecker.h"
#import "MXPushRuleRoomMemberCountConditionChecker.h"
#import "MXPushRuleSenderNotificationPermissionConditionChecker.h"
#import "MXMegolmDecryption.h"
#import "MXOlmDecryption.h"
#import "MXCachedSyncResponse.h"
#import "MXBackgroundCryptoStore.h"

Those files import other headers though so the interface is probably a lot bigger.

I haven't checked how complicated it would be to disentangle this. However, one downside of making, say, the Objective-C code not depend on any of the Swift code is that this will probably make it harder to convert any Objective-C code to Swift in the future.

ferologics commented 2 years ago

Alternatively, the package could link to a binary distribution of the MatrixSDK xcframework. There's already a script that can build it, so maybe it's possible to set this up with some Github action on each release?

kiliankoe commented 2 years ago

FWIW this is what's done through niochat/MatrixSDK more or less. It is still kicked of manually on releases, but is totally usable.

AlexandreHauber commented 2 years ago

It seems the niochat one mentioned by kiliankoe stopped being updated (it is stuck in 0.19.0 for more than two years now), and the oficial repo still does not support it. 😔 Anyone knows if there is an update on that?

pixlwave commented 2 years ago

it is stuck in 0.19.0 for more than two years now

FWIW, I think 0.19.0 came out in June this year.

kloenk commented 2 years ago

Nio updated some months ago. All of the maintainers are sadly currently without much time. So yes it's quite slow development at the moment.

AlexandreHauber commented 2 years ago

it is stuck in 0.19.0 for more than two years now

FWIW, I think 0.19.0 came out in June this year.

Omg, you are right @pixlwave. My bad, completely misread it. June 19th, not June 2019. Sorry y'all.

AlexandreHauber commented 2 years ago

@Kloenk Nio is based on the Globekeeper version of Matrix right? I could try to generate a new version. Not sure exactly how to generate the binaries, but I could take a look.

kloenk commented 2 years ago

I'm not sure which is the Globekeeper version. So not sure.

I did not generate the binary archive that we are using. It's packaged here

ferologics commented 2 years ago

@AlexandreHauber Globekeeper forked the Nio binary package distribution repo. The SDK has been modified for our use so I'd advise against using it.

If you need the latest MatrixSDK you're best off forking from Nio and preparing your own release 🙂.

At the moment it's unclear whether the MatrixSDK will support binary SPM distribution in this repo, though it would be a nice addition.

AlexandreHauber commented 2 years ago

Thanks @Kloenk.

@ferologics thanks for the clarification, I got it backwards then, hehe. I forked from matrix-ios-sdk and started moving the files to the right folder structure (Source / Tests / Multiple targets due do objc + swift code), but got stuck with some issues with Olm. Looking for a solution I found this thread and the discussion brought by Johennes, so I kind of dropped it.

I also saw your link to the script to generate the binaries. It seems that for now maybe the easier is to try to use this script, generate binaries for the 0.20.9 version and open a PR for the Nio.

AlexandreHauber commented 2 years ago

In the end, thanks to the efforts of Nio's team, it was really easy to generate a new build. I just had to fork Nio's repository and activate the workflow on Github Actions. After it successfully built, updating to the right file & checksum on Package.swift was all that was needed.

If anyone is interested on Matrix 0.20.10 (released 24h ago) with SPM support, please follow this link: https://github.com/AlexandreHauber/MatrixSDK

Don't know how many hours spent on other approaches before finding this 🥲.