Xamarin-macios: [xcode11-support] xcframework support

Created on 11 Jun 2019  路  12Comments  路  Source: xamarin/xamarin-macios

xcframework are a new format of frameworks which allow multiple platforms to live side by side.

We should teach binding projects (XI and XM) to accept xcframework bundles.

In addition, we need to research how we can leverage this:

enhancement

Most helpful comment

@awattar @chamons It is possible to strip non-iOS architectures out of dynamic frameworks during build using a script such as Realm's for submitting to App Store. For frameworks that have switched to XCFramework, the relevant frameworks could be pulled out of the XCFramework and merged as required.

However, another problem is approaching with Apple Silicon. Xcode 12 builds simulator binaries for x86_64, i386, and now arm64 by default, for running in simulator on Apple Silicon. If attempting to make a fat binary, the arm64 simulator slice conflicts with the iOS arm64 slice. The arm64 simulator slice can be removed with lipo, but this means that the framework can't run in simulator on Apple Silicon. As such, I have to distribute a fat binary which doesn't support Apple Silicon for Xamarin. This means that until XCFrameworks are supported, many Xamarin projects using binary libraries and frameworks will not run in the simulator on Apple Silicon.

All 12 comments

Hi. Any ETA for this enhancement?

Thanks for the interest @awattar - In general we don't have ETA for enhancements. Either they are in work or our backlog.

Right now the teams is focused on Xcode 12 and the port to .NET 6, so it may be some time before we pick this up.

Thanks @chamons. It started to be a problem because apps referencing dynamic frameworks cannot be distributed to AppStore due to unsupported architecture - x86_64 so most of them were switched to modern xcframeworks that are currently unsupported by the Xamarin.iOS bindings/apps. Workarounds require special IPA handling or creating cumbersome configurations for simulator/device.

It is not something new but over a year old enhancement that could be put somewhere in the schedule for the sake of loyal developers and their customers ;)

@awattar @chamons It is possible to strip non-iOS architectures out of dynamic frameworks during build using a script such as Realm's for submitting to App Store. For frameworks that have switched to XCFramework, the relevant frameworks could be pulled out of the XCFramework and merged as required.

However, another problem is approaching with Apple Silicon. Xcode 12 builds simulator binaries for x86_64, i386, and now arm64 by default, for running in simulator on Apple Silicon. If attempting to make a fat binary, the arm64 simulator slice conflicts with the iOS arm64 slice. The arm64 simulator slice can be removed with lipo, but this means that the framework can't run in simulator on Apple Silicon. As such, I have to distribute a fat binary which doesn't support Apple Silicon for Xamarin. This means that until XCFrameworks are supported, many Xamarin projects using binary libraries and frameworks will not run in the simulator on Apple Silicon.

@nrbrook that's a very good point, and we'll have it in mind when we're adding simulator support on Apple Silicon

We've just hit this with Reveal's SDK - we're in a tight spot here: we can't really afford _not_ to support Apple Silicon in our framework, but this necessitates shipping as an XCFramework so that there's no overlapping slices.

Is there an ETA on support for Xamarin consuming XCFrameworks?

10046 has landed in main

@spouliot

I'm on the Xamarin.iOS 14.9.0.27 that should have #10046, but I'm still having this problem:

warning: ignoring file /<ProjectPath>/obj/iPhoneSimulator/Debug - Staging/device-builds/iphone12.8-14.2/mtouch-cache/<FrameworkName>.xcframework, building for iOS Simulator-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x50 0x4B 0x03 0x04 0x14 0x00 0x00 0x00 0x08 0x00 0xD1 0x83 0x8F 0x51 0xD8 0x5E )

My csproj contains this

    <NativeReference Include="Frameworks\<FrameworkName>.xcframework">
      <Kind>Framework</Kind>
      <Frameworks>Foundation</Frameworks>
    </NativeReference>

Am I doing something wrong?

@fklingler yes, an xcframework is a directory, which has several subdirectories for arch/platforms. A valid mach-o file inside them would start with:

0000000 ca fe ba be

but yours is

0000000 50 4b 03 04

which looks like a ZIP archive.

I'm on the Xamarin.iOS 14.9.0.27 that should have #10046,

Also the commit associated with PR#10046 shows the first package to have this code is 14.9.0.52.

I'm not sure I understood your first answer, as my xcframework is a directory and not a zip archive.
Thanks anyway! I'm gonna wait for the 14.9.0.52 build to be released and will try again.

Was this page helpful?
0 / 5 - 0 ratings