CommunityToolkit / Maui.NativeLibraryInterop

Maui.NativeLibraryInterop is a community-created library of binding samples to help .NET MAUI developers interop with native libraries more easily
MIT License
181 stars 28 forks source link

Objective Sharpie `error: invalid SDK 'iphoneos-18.0' #62

Open Peru-S opened 2 days ago

Peru-S commented 2 days ago

Hi, I cloned this repo and ran dotnet build in maui.nativelibraryinterop/template/macios/NewBinding.MaciOS.Binding to generate the API defs (as described in Rachel Kang's excellent tutorial here: https://devblogs.microsoft.com/dotnet/native-library-interop-dotnet-maui/)

I see the following error:

.nuget/packages/communitytoolkit.maui.nativelibraryinterop.buildtasks/0.0.1-pre1/tools/Common.macios.targets(168,5): error SHRP0000: error: invalid SDK 'iphoneos18.0'

Also sharpie xcode -sdks returns nothing. [My xcode is in an external HDD, and xcode-select -p returns the correct location]

Not sure what the problem is. Is iOS18.0 too new?

[sharpie update throws an error too.]

Peru-S commented 2 days ago

I symlinked ln -s /Applications/Xcode.app/ and still it doesn't work - so it's definitely not an external HDD issue (and the SDKs are in /Library anyways). On a different machine with Xcode with SDK ios17.5 sharpie xcode -sdks works / builds the API defs.

Will there be a newer Objective Sharpie released? (Guessing it's not working with 18.0)

@rachelkang - I saw your demo, so wondering if you got it to work with Xcode 16?

pjcollins commented 1 day ago

Sharpie should support Xcode 16, as you've suspected there may be some environmental/configuration issue here. It seems that sharpie can't find your Xcode install -- what output do you get if you try to run: sharpie xcode -sdks -x /path/to/your/Xcode.app ?

My Xcode 16 shows an iphoneos18.0 install at: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS18.0.sdk/System/Library/Frameworks

Another problem may be that the .NET 8 iOS SDK that you are using does not yet support Xcode 16.

Peru-S commented 1 day ago

Thank you. sharpie xcode -x works :) However, I tried it with the net8.0 (Which doesn't work with XCode 16) and net9.0 (your latest in-progress PR). Your PR net9.0 requires manual sharpie bind for which I couldn't find the right command line parameters to work with the template.

Do you have a full example for invoking sharpie bind?

I tried the following:

native/NewBinding > sharpie bind -x /blah/ -sdk iphoneos18.0 -o ../../NewBinding.MaciOS.Binding -scope ./NewBinding/ ./NewBinding/NewBinding.h   -c -Ibuild/Release-iphoneos/NewBinding.framework/Headers/

and the result is this:


Binding...
  [write] ApiDefinitions.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:
... (lots of boiler plate text)

Done.

The final ApiDefinitions.cs has

using Foundation;

[Static]
[Verify (ConstantsInterfaceAssociation)]
partial interface Constants
{
    // extern double NewBindingVersionNumber;
    [Field ("NewBindingVersionNumber", "__Internal")]
    double NewBindingVersionNumber { get; }

    // extern const unsigned char[] NewBindingVersionString;
    [Field ("NewBindingVersionString", "__Internal")]
    byte[] NewBindingVersionString { get; }
}

which is not the API but ... something else?

I wonder if the net9.0 version can be made to use sharpie automatically just like the net8.0 (with maybe the -x option in the csproj perhaps?). If not, docs for the manual step will be super helpful. (the sharpie docs/interop docs are barely sufficient/usable).

Peru-S commented 21 hours ago

Let me summarize the question:

For the dotnet9 PR, what's the sharpie command to regenerate the template API cs file from swift/objc?

@pjcollins / @rachelkang FYI

Thank you!