kinfey / AMapMAUIControls

MIT License
64 stars 19 forks source link

Support linking xcframework #6

Open dodikk opened 1 year ago

dodikk commented 1 year ago
It would be nice to have *.xcframework support out of box by MAUI

Sample project to reproduce https://github.com/dodikk/themis-maui-prototype


Modern iOS libs ship as *.xcframework artefacts which are capable of targeting multiple platforms.

I am attempting to bind the cossacklabs/themis lib built by Carthage (also tried their xcframework creation scripts) https://github.com/cossacklabs/themis

And my linker error is:

Building target "_LinkNativeExecutable" completely.   
        Tool xcrun execution finished (exit code = 1).

        Undefined symbols for architecture arm64:
          "_OBJC_CLASS_$_TSCell", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSCellContextImprint", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSCellSeal", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSCellToken", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSCellTokenEncryptedData", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSCellTokenEncryptedResult", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSComparator", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSKeyGen", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSMessage", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSSession", referenced from:
              objc-class-ref in registrar.o
          "_OBJC_CLASS_$_TSSessionTransportInterface", referenced from:
              objc-class-ref in registrar.o
          "_TSGenerateSymmetricKey", referenced from:
             -u command line option
        ld: symbol(s) not found for architecture arm64
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
dodikk commented 1 year ago

I had to add this to my MAUI app .csproj

<PropertyGroup Condition="$(TargetFramework.Contains('-ios'))">
        <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>

due to this error

Assets file project.assets.json doesnt have a target for "net7.0-ios/ios-arm64"
You may also need to include "ios-arm64" in your project's RuntimeIdentifiers
dodikk commented 1 year ago

Combining the dynamic libs of the framework to a single binary with lipo create seems like a flawed approach since both iPhone and Mac desktop might be using the same M1 chips in future (with slightly different API and different lib artefacts)

dodikk commented 1 year ago

Also Themis.Maui.Droid binding projects appear under the iOS platform dependencies despite the per-platform references

<ItemGroup>
        <ProjectReference Include="..\..\..\lib-bindings\themis-maui\themis.maui\themis.maui.csproj" />
    </ItemGroup>

    <ItemGroup Condition=" '$(TargetPlatformIdentifier)' == 'ios' ">
        <ProjectReference Include="..\..\..\lib-bindings\themis-maui\Themis.Maui.iOS\Themis.Maui.iOS.csproj" />
        <ProjectReference Include="..\..\..\lib-bindings\themis-maui\themis.ios.wrapper.maui\themis.ios.wrapper.maui.csproj" />
    </ItemGroup>

    <ItemGroup Condition=" '$(TargetPlatformIdentifier)' == 'android' ">
        <ProjectReference Include="..\..\..\lib-bindings\themis-maui\Themis.Maui.Droid\Themis.Maui.Droid.csproj" />
        <ProjectReference Include="..\..\..\lib-bindings\themis-maui\themis.droid.wrapper.maui\themis.droid.wrapper.maui.csproj" />
    </ItemGroup>

Screenshot 2023-03-03 at 15 25 04

dodikk commented 1 year ago

Combining the dynamic libs of the framework to a single binary with lipo create seems like a flawed approach since both iPhone and Mac desktop might be using the same M1 chips in future (with slightly different API and different lib artefacts)

Given this script and the themis.xcframework the following lipo error happens exactly as I have predicted.

lipo -create \
-output themis_fat.so \
./themis.xcframework/ios-arm64/themis.framework/themis \
./themis.xcframework/ios-arm64_x86_64-simulator/themis.framework/themis \
./themis.xcframework/macos-arm64_x86_64/themis.framework/Versions/A/themis 
fatal error: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lipo: ./themis.xcframework/ios-arm64/themis.framework/themis and ./themis.xcframework/ios-arm64_x86_64-simulator/themis.framework/themis have the same architectures (arm64) and can't be in the same fat output file