IOS CBL and Catalyst

I have an iPad app based on CBL Mobile 1.x. I would love to use Catalyst to port to the Mac.

What is involved in getting the CBL Mobile framework built for Catalyst?

Is there any plans to add support for this?

T

There are no plans to do anything to 1.x anymore, and no plans to add this additional architecture to 2.x.

This is possible using a new Xcode 11 framework format called XCFrameworks. See the corresponding WWDC session 416 titled: “Binary Frameworks in Swift” for details. It’s very similar to building a fat binary framework, but you don’t need to merge the framework contents by hand. And you can also mix and match platforms.

I’ve successfully build an XCFramework version of CBL 2.5 as a test, but I had to make changes to account for deprecations in iOS 13 and a few APIs that are unavailable on the Catalyst platform. The former changes will likely need to be made anyway to support Xcode 11 / iOS 13.

I suspect XCFrameworks will be the preferred way to deliver a single framework bundle that supports both the simulator and iOS devices, potentially along with Catalyst.

I’m very happy to see XCFrameworks – the inability to have multi-platform frameworks has been a real pain in the butt to us since 2011 (for doing device vs simulator builds.)

That said, I haven’t had any time yet to learn about them or adapt our Xcode frameworks to generate them. And we wouldn’t be able to release any XCFramework binaries until at least September, since they require Xcode 11 and we can’t release software built with beta dev tools.

@lightandshadow: I assume you can’t just add Mac frameworks to a Catalyst build target? Since it is building a Mac application, after all? That would be the quick and easy way to make this work today.

@jens I’m so happy you are at least hoping to make this work. It’s very important to me and most of the other CBL developers I know!

Todd

1 Like

I have yet to document this clearly, as it was somewhat of a trial and error process. But the key changes were to add the additional “x86_64 i386” architectures to the assigned.xconfig for the target, then use xcodebuild to create archives for all three platforms. I was creating a Swift only app, so I built the Swift version of CBL.

xcodebuild archive -scheme "CBL Swift" -destination "generic/platform=OS X" -destination "generic/platform=ios" -destination "generic/platform=iOS Simulator" SKIP_INSTALL=NO

This builds three archives, that show up in the Organizer window, from which you can extract the resulting frameworks. I ended up copying them into subfolders since they were named the same, then used xcodebuild again to create the xcframework.

xcodebuild -create-xcframework -framework ./iosdevice/CouchbaseLiteSwift.framework -framework ./iossimulator/CouchbaseLiteSwift.framework -framework ./macos/CouchbaseLiteSwift.framework -output CouchbaseLiteSwift.xcframework

This xcframework can be added under the Frameworks, Libraries, and Embedded Content section under the General tab for the target. It should be listed as both “macOS + iOS” in the platforms column. At this point, you can build for a device, the simulator or your Mac, if you’re checked the Mac option under the Devices section.

Cool! Pull requests welcome :wink:

I have a 2.5 branch that works, but I’ll want to recreate with just the minimal number of changes necessary. I suspect there is a more direct route, as opposed to the wandering path I took to get there.

I’d like to also get this working with 1.x as my primary project has yet to migrate to 2.x. However, we currently use a custom build of 1.4 that cherry picks a commit from 1.4.1.

+1 on the 1.4x support!

T

For 1.x, we run a build phase script which executes BuildFatLibrary.sh to generate a fat library, but the script for building library per platform.

You can create an independent script to generate XCFramework by building CBL-iOS from CI iOS scheme and CBL-MacOS from CI MacOS scheme and combining them. You will need to disable the build phase that builds the fat library as well.