Open LeadAssimilator opened 2 months ago
While the proper binding in this case is arguably INSCoding instead of NSCoding or even NSObject (both cause the registrar to use id), something doesn't appear to be correct in the registrar code gen when using NSCoding. I think this used to work in old versions ok, and the fact this only manifests in release builds (at least in the default configuration) makes these bugs more difficult to catch.
I can reproduce the problem, and you're correct, the registrar is generating invalid code (test case shows this in https://github.com/rolfbjarne/xamarin-macios/commit/48cd49a5a96b0bfaa784a01b07089d6f0fcf44ff).
In your case the correct type to use is INSCoding
instead of NSCoding
(in fact NSCoding
shouldn't even exist, so I've created a PR to eventually remove it (#21257)).
this only manifests in release builds
It manifests in device builds (even debug ones).
For performance reasons there are two rather different registrar implementations between device and simulator builds, and in this particular case it turns out the device version has a bug.
My bad on the debug vs. release - it slipped my mind that I also flipped to device as a force of habit. Glad that you reproduced it easily.
Once the models for various classes are removed, will sharpie pick that up or will it also need changes?
I do wonder why sharpie seems to prefer models over ifaces in the cases where either would suffice, since I think the iface is what you really want anyway, at least in all the cases I have encountered. Having it make the seemingly wrong choice just adds to the binding fixup tedium, along with having to still manually add iface skeletons and switch types to them in various cases, address all the verify attrs and fixup all the delegate method names it ruins. I realize it can't be perfect, but I do wish whomever is maintaining sharpie would actually use it on large and/or widely used libraries so it would improve.
Once the models for various classes are removed, will sharpie pick that up or will it also need changes?
No, sharpie will keep doing what it's doing until we fix it - in this case the generated code just wouldn't compile because those types would be missing.
I realize it can't be perfect, but I do wish whomever is maintaining sharpie would actually use it on large and/or widely used libraries so it would improve.
Agreed, although as usual it comes down to resource management and never having enough time to do everything we want to do.
Not sure if this is related, but another registrar compile issue occurred on maccatalyst (didn't try others) with --registrar:static
if using NSUrlSessionDataDelegate - INSUrlSessionDataDelegate works as expected though:
// -(instancetype _Nonnull)initWithDelegate:(id<NSURLSessionDataDelegate> _Nonnull __strong)delegate delegateQueue:(NSOperationQueue * _Nonnull __strong)delegateQueue __attribute__((ns_consumes_self)) __attribute__((ns_returns_retained));
[Export ("initWithDelegate:delegateQueue:")]
NativeHandle Constructor (NSUrlSessionDataDelegate @delegate, NSOperationQueue delegateQueue);
obj/Debug/net8.0-maccatalyst/maccatalyst-x64/linker-cache/registrar.h:3805:29: error: type argument 'Microsoft_MacCatalyst__Foundation_NSUrlSessionDataDelegate' must be a pointer (requires a '*')
3805 | -(id) initWithDelegate:(id<Microsoft_MacCatalyst__Foundation_NSUrlSessionDataDelegate>)p0 delegateQueue:(NSOperationQueue *)p1;
That's the exact same issue.
Apple platform
iOS
Framework version
net8.0-*
Affected platform version
Microsoft.iOS.Sdk.net8.0_17.5/17.5.8030
Description
Given the following native code:
And corresponding sharpie binding:
Yields the following compiler error:
Steps to Reproduce
Did you find any workaround?
Use the arguably more correct INSCoding for the binding instead of NSCoding.
Build logs
No response