xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.44k stars 508 forks source link

[ObjectiveSharpie] System.Exception: Unsupported clang availability platform: 'maccatalyst_app_extension' #18098

Open svaldetero opened 1 year ago

svaldetero commented 1 year ago

Steps to Reproduce

sharpie version: 3.5.61-c2b0b612 macOS Ventura 13.3.1 (22E261) Using Stripe release downloaded from: https://github.com/stripe/stripe-ios/releases/tag/23.6.1

$ sharpie xcode -sdks                                                                                 
sdk: appletvos16.4              arch: arm64   
sdk: assetruntime.tvos16.4      arch: arm64   
sdk: appletvos16.1              arch: arm64   
sdk: assetruntime.ios16.4       arch: arm64   armv7   
sdk: iphoneos16.4               arch: arm64   armv7   
sdk: iphoneos16.1               arch: arm64   armv7   
sdk: ios16.4-macabi             arch: x86_64  arm64   
sdk: ios16.1-macabi             arch: x86_64  arm64   
sdk: macosx13.3                 arch: x86_64  arm64   
sdk: macosx13.0                 arch: x86_64  arm64   
sdk: watchos9.4                 arch: armv7k  arm64   
sdk: assetruntime.watchos9.4    arch: armv7k  arm64   
sdk: watchos9.1                 arch: armv7k  arm64

sharpie bind --output=Stripe.Terminal.iOS --namespace=Stripe.Terminal.iOS --sdk=iphoneos16.4 StripeApplePay.xcframework/ios-arm64/StripeApplePay.framework/Headers/*h

This is the corresponding line in the StripeApplePay-Swift.h file: - (void)presentApplePayWithCompletion:(void (^ _Nullable)(void))completion SWIFT_AVAILABILITY(maccatalyst_app_extension,unavailable,message="UsepresentApplePay(from:completion:)in App Extensions.") SWIFT_AVAILABILITY(ios_app_extension,unavailable,message="UsepresentApplePay(from:completion:)in App Extensions.");

Expected Behavior

This should have built the ApiDefinition.cs and the StructsandEnums.cs files

Actual Behavior

Gives: [ObjectiveSharpie] Unsupported clang availability platform: 'maccatalyst_app_extension'

Environment

Version information ``` Visual Studio Professional 2022 for Mac Version 17.5.2 (build 14) Installation UUID: 2d712079-9f67-46a1-bf49-e165c4d934bd Runtime .NET 7.0.1 (64-bit) Architecture: Arm64 Microsoft.macOS.Sdk 12.3.2372; git-rev-head:754abbf6a3563f6267e5717ae832b4ac25b1f2fb; git-branch:release/7.0.1xx-xcode13.3 Roslyn (Language Service) 4.5.0-3.23056.2+97881342e427ff5cdcba8f12b12ff8e6f3564431 NuGet Version: 6.4.0.117 .NET SDK (Arm64) SDK: /usr/local/share/dotnet/sdk/7.0.202/Sdks SDK Versions: 7.0.202 7.0.201 7.0.200 7.0.103 7.0.101 7.0.100 7.0.100-rc.2.22477.23 6.0.407 6.0.406 6.0.404 6.0.403 6.0.402 6.0.401 6.0.400 6.0.301 6.0.300 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET SDK (x64) SDK Versions: 3.1.426 3.1.425 3.1.424 3.1.423 3.1.422 3.1.421 3.1.420 .NET Runtime (Arm64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 7.0.4 7.0.3 7.0.1 6.0.15 6.0.14 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.6 6.0.5 6.0.0 .NET Runtime (x64) Runtime: /usr/local/share/dotnet/x64/dotnet Runtime Versions: 3.1.32 3.1.31 3.1.30 3.1.29 3.1.28 3.1.27 3.1.26 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Xamarin.Android Version: 13.2.0.6 (Visual Studio Professional) Commit: xamarin-android/d17-5/a200af1 Android SDK: /Users/svaldetero/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 12.0 (API level 31) 11.0 (API level 30) 10.0 (API level 29) 13.0 (API level 33) SDK Command-line Tools Version: 7.0 SDK Platform Tools Version: 33.0.2 SDK Build Tools Version: 32.0.0 Build Information: Mono: 6dd9def Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@9f02d77 Microsoft Build of OpenJDK Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk 11.0.16.1 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Eclipse Temurin JDK Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Android SDK Manager Version: 17.5.0.33 Hash: f0c0c52 Branch: remotes/origin/d17-5~2 Build date: 2023-03-09 19:43:41 UTC Android Device Manager Version: 0.0.0.1245 Hash: 7f8a990 Branch: 7f8a990 Build date: 2023-03-09 19:43:41 UTC Xamarin Designer Version: 17.5.3.47 Hash: e8b5d371c3 Branch: remotes/origin/d17-5 Build date: 2023-03-09 19:43:36 UTC Apple Developer Tools Xcode: 14.3 21812 Build: 14E222b Xamarin.Mac Not Installed Xamarin.iOS Version: 16.2.0.6 Visual Studio Professional Hash: 8dbac9331 Branch: xcode14.2 Build date: 2023-02-08 15:12:08-0500 Build Information Release ID: 1705020014 Git revision: f95e127ba5837148420d81c7c14c47ca8eade102 Build date: 2023-03-09 19:41:47+00 Build branch: release-17.5 Build lane: release-17.5 Operating System Mac OS X 13.3.1 Darwin 22.4.0 Darwin Kernel Version 22.4.0 Mon Mar 6 20:59:28 PST 2023 root:xnu-8796.101.5~3/RELEASE_ARM64_T6000 arm64 Enabled user installed extensions .NET Core Extensions 0.6 ```

Build Logs

Example Project (If Possible)

rolfbjarne commented 1 year ago

I can confirm the problem.

It looks like you can just remove the offending maccatalyst_app_extension availability from the headers by doing something like this:

$ sed -i '' -e 's/SWIFT_AVAILABILITY[\(]maccatalyst_app_extension,unavailable[\)]//g' -e 's/SWIFT_AVAILABILITY[\(]maccatalyst_app_extension,unavailable.*[\)] //g' *.xcframework/*/*.framework/Headers/*.h

basically removing SWIFT_AVAILABILITY(maccatalyst_app_extension,unavailable*) from the headers, and now sharpie produces something that might be useful, there's still an error though, not sure if that prevents you from using the result:

$ sharpie bind --output=Stripe.Terminal.iOS --namespace=Stripe.Terminal.iOS --sdk=iphoneos16.4 StripeApplePay.xcframework/ios-arm64/StripeApplePay.framework/Headers/*h
Parsing 2 header files...
In file included from /var/folders/43/h027tm1n101cdrq2_b6n9n2m0000gn/T/tmp7be072b0.h:1:
/Users/rolf/Downloads/Stripe.xcframework/StripeApplePay.xcframework/ios-arm64/StripeApplePay.framework/Headers/StripeApplePay-Swift.h:235:9: fatal error: module 'StripeCore' not found
@import StripeCore;
 ~~~~~~~^~~~~~~~~~

Binding...
  [write] ApiDefinitions.cs
  [write] StructsAndEnums.cs

Binding Analysis:
  Automated binding is complete, but there are a few APIs which have been flagged with [Verify] attributes. While the entire binding should be audited for best API design practices, look more closely at APIs with the following Verify attribute hints:

  ConstantsInterfaceAssociation (306 instances):
    There's no foolproof way to determine with which Objective-C interface an extern variable declaration may be associated. Instances of these are bound as [Field] properties in a partial interface into a nearby concrete interface to produce a more intuitive API, possibly eliminating the 'Constants' interface altogether.

  MethodToProperty (516 instances):
    An Objective-C method was bound as a C# property due to convention such as taking no parameters and returning a value (non-void return). Often methods like these should be bound as properties to surface a nicer API, but sometimes false-positives can occur and the binding should actually be a method.

  StronglyTypedNSArray (49 instances):
    A native NSArray* was bound as NSObject[]. It might be possible to more strongly type the array in the binding based on expectations set through API documentation (e.g. comments in the header file) or by examining the array contents through testing. For example, an NSArray* containing only NSNumber* instances can be bound as NSNumber[] instead of
    NSObject[].

  PlatformInvoke (6260 instances):
    In general P/Invoke bindings are not as correct or complete as Objective-C bindings (at least currently). You may need to fix up the library name (it defaults to '__Internal') and return/parameter types manually to conform to C calling conventionsfor the target platform. You may find you don't even want to expose the C API in your binding, but if you do,
     you'll probably also want to relocate the definition to a more appropriate class and expose a stronger type-safe wrapper. For P/Invoke guidance, see http://www.mono-project.com/docs/advanced/pinvoke/.

  InferredFromMemberPrefix (117 instances):
    The name of this originally anonymous declaration was taken from a common prefix of its members.

  Once you have verified a Verify attribute, you should remove it from the binding source code. The presence of Verify attributes intentionally cause build failures.

  For more information about the Verify attribute hints above, consult the Objective Sharpie documentation by running 'sharpie docs' or visiting the following URL:

    http://xmn.io/sharpie-docs
1 error generated.
Error while processing /var/folders/43/h027tm1n101cdrq2_b6n9n2m0000gn/T/tmp7be072b0.h.

Done. Exiting with error code 1.
error: Clang failed to parse input and exited with code 1
svaldetero commented 1 year ago

Thanks for the workaround. Is this something that Objective Sharpie will fix or should this be the official workaround for any "unsupported clang availability platform"? I only created the issue since I saw previous ones for similar errors.

rolfbjarne commented 1 year ago

We might fix it in Objective-Sharpie at some point, but it's unlikely to be any time soon. Until then, this workaround can be the official workaround.