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

Build universal iOS framework #54

Merged
merged 3 commits into from
Sep 27, 2024
Merged

Build universal iOS framework #54

merged 3 commits into from
Sep 27, 2024

Conversation

AArnott
Copy link
Collaborator

@AArnott AArnott commented Sep 21, 2024

Most importantly, this exposes the native library as a "framework" in iOS so that a consuming iOS application will not be rejected by the App Store.

In addition to this though, we combine both x64 and arm64 simulator binaries into one universal binary, which should help make things "just work" whether the simulator runs on an x64 or an arm64 (Apple Silicone) mac.

Copy link

codecov bot commented Sep 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 20.82%. Comparing base (a143ecf) to head (95bff41).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #54   +/-   ##
=======================================
  Coverage   20.82%   20.82%           
=======================================
  Files          10       10           
  Lines         317      317           
  Branches       50       50           
=======================================
  Hits           66       66           
  Misses        245      245           
  Partials        6        6           
Flag Coverage Δ
LinuxHost 20.82% <ø> (ø)
Release 20.82% <ø> (ø)
WindowsHost 20.82% <ø> (ø)
macOSHost 20.82% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@AArnott AArnott force-pushed the ios_framework branch 2 times, most recently from 5cb3f3a to 337493a Compare September 21, 2024 23:19
Most importantly, this exposes the native library as a "framework" in iOS so that a consuming iOS application will not be rejected by the App Store.
In addition to this though, we combine both x64 and arm64 binaries into one *universal* binary, which should help make things "just work" whether in an emulator or a real device.
@AArnott AArnott force-pushed the ios_framework branch 7 times, most recently from 3e339f7 to 9217544 Compare September 22, 2024 13:34
@AArnott AArnott force-pushed the ios_framework branch 5 times, most recently from 6bf5e39 to 6c1f008 Compare September 22, 2024 19:50
@AArnott
Copy link
Collaborator Author

AArnott commented Sep 22, 2024

This change mostly looks good. But we have one issue and one question:

Issue

https://github.com/AArnott/iOSSampleInteropApp is a minimum iOS app to test this change. It builds at runtime, and appears to copy the native as well as the managed libraries into the app when targeting the emulator. But the app crashes with a DllNotFoundException when the native library is requires, saying that nerdbank_qrcodes couldn't be found. Why?

**System.DllNotFoundException:** 'nerdbank_qrcodes'

image

Since the file layout is equivalent to that used by the Sentry.Bindings.Cocoa package (which presumably works), I suspect the problem is in how I prepare the binary files.
The azure-pipelines/build_ios_framework.ps1 file introduce this PR makes use of lipo, install_name_tool and chmod based on what I could gather from a bunch of StackOverflow pages and other projects I could find on GitHub. But I don't fully understand how it's meant to work so I may have made a mistake there.

Open question

Is laying out the nupkg such that the native Apple framework is under the lib/net8.0-ios directory in a special resource pack the best way to go? It's the only way I can find that leads to MSBuild's Xamarin.iOS SDK automatically finding and deploying the right files. The alternative was to place it under the runtimes/ios-universal folder and add a buildTransitive/ import that adds a NativeReference item to the consuming project.

The package layout as it stands now
D:\PACKAGES\NUGET\NERDBANK.QRCODES\0.2.55-BETA-G209A879921
|   .nupkg.metadata
|   nerdbank.qrcodes.0.2.55-beta-g209a879921.nupkg
|   nerdbank.qrcodes.0.2.55-beta-g209a879921.nupkg.sha512
|   nerdbank.qrcodes.nuspec
|   README.md
|   THIRD_PARTY_DEPENDENCIES.txt
|   THIRD_PARTY_LICENSES.yml
|   
+---lib
|   +---net8.0
|   |       Nerdbank.QRCodes.dll
|   |       Nerdbank.QRCodes.xml
|   |       
|   +---net8.0-ios17.5
|   |   |   Nerdbank.QRCodes.dll
|   |   |   Nerdbank.QRCodes.xml
|   |   |   
|   |   \---Nerdbank.QRCodes.resources
|   |       |   manifest
|   |       |   
|   |       \---nerdbank_qrcodes.xcframework
|   |           |   Info.plist
|   |           |   
|   |           +---ios-arm64
|   |           |   \---nerdbank_qrcodes.framework
|   |           |           Info.plist
|   |           |           nerdbank_qrcodes
|   |           |           
|   |           \---ios-arm64_x86_64-simulator
|   |               \---nerdbank_qrcodes.framework
|   |                       Info.plist
|   |                       nerdbank_qrcodes
|   |                       
|   \---net8.0-windows7.0
|           Nerdbank.QRCodes.dll
|           Nerdbank.QRCodes.xml
|           
\---runtimes
    +---android-arm64
    |   \---native
    |           libnerdbank_qrcodes.so
    |           
    +---android-x64
    |   \---native
    |           libnerdbank_qrcodes.so
    |           
    +---linux-arm64
    |   \---native
    |           libnerdbank_qrcodes.so
    |           
    +---linux-x64
    |   \---native
    |           libnerdbank_qrcodes.so
    |           
    +---osx-arm64
    |   \---native
    |           libnerdbank_qrcodes.dylib
    |           
    +---osx-x64
    |   \---native
    |           libnerdbank_qrcodes.dylib
    |           
    +---win-arm64
    |   \---native
    |           nerdbank_qrcodes.dll
    |           
    \---win-x64
        \---native
                nerdbank_qrcodes.dll

@AArnott AArnott force-pushed the ios_framework branch 2 times, most recently from 5fa4125 to c8a1730 Compare September 27, 2024 03:18
@AArnott
Copy link
Collaborator Author

AArnott commented Sep 27, 2024

Possibly relevant tip: xamarin/xamarin-macios#21238

@AArnott AArnott force-pushed the ios_framework branch 2 times, most recently from 9f10d9b to 47b31ea Compare September 27, 2024 14:54
This leads to the Xamarin.iOS SDK automatically discovering the xcframework, which otherwise needs to be called out for inclusion using a `<NativeReference>` item pointing to the `runtimes\ios-universal\native\nerdbank_qrcodes.xcframework` directory with `Kind=Framework` metadata.
@AArnott AArnott marked this pull request as ready for review September 27, 2024 15:20
@AArnott AArnott merged commit 83760c7 into main Sep 27, 2024
8 checks passed
@AArnott AArnott deleted the ios_framework branch September 27, 2024 15:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant