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

Expose low-level building blocks as API #12140

Closed
Therzok opened this issue Jul 19, 2021 · 6 comments
Closed

Expose low-level building blocks as API #12140

Therzok opened this issue Jul 19, 2021 · 6 comments
Labels
enhancement The issue or pull request is an enhancement help wanted This is an issue or pull request where we request help from the community to fix or complete iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac
Milestone

Comments

@Therzok
Copy link
Contributor

Therzok commented Jul 19, 2021

Steps to Reproduce

  1. Try to manually bind a selector
  2. Observe that the messaging API is internal
  3. Bind it manually

Expected Behavior

Users of Xamarin.Mac should have some way to use the low-level APIs (maybe in some Unsafe namespace?)

That way, someone could technically write their own variation of bindings for performance improvements (avoiding marshalling between NSString <-> string for string bound APIs that have to marshal to NSString in native).

The APIs in question would be: selector constants, messaging API and Pinvoke definitions.

Actual Behavior

They're all internal/private

@rolfbjarne
Copy link
Member

Users of Xamarin.Mac should have some way to use the low-level APIs (maybe in some Unsafe namespace?)

That way, someone could technically write their own variation of bindings for performance improvements (avoiding marshalling between NSString <-> string for string bound APIs that have to marshal to NSString in native).

The APIs in question would be: selector constants, messaging API and Pinvoke definitions.

There's no reason you can't write this code yourself, or even copy our code.

We've documented this, with some helper code you can copy: https://docs.microsoft.com/en-us/xamarin/ios/internals/objective-c-selectors#creating-your-own-signatures

They're all internal/private

There's a reason for this: there's a lot of them, and they're generated. Every function signature needs a different P/Invoke, and it ends up being a pretty big list. In the early days of MonoTouch these P/Invokes were public, but it turned out a nightmare to maintain, because as we changed implementation details, the set of generated P/Invokes changed, and suddenly we were unintentionally breaking the API, and we had to copy the missing generated P/Invokes to manually written code, and rinse and repeat for quite a few releases.

@Therzok
Copy link
Contributor Author

Therzok commented Jul 19, 2021

Duplicating the code does not make much sense - JITing twice, different assemblies, etc. It would probably be okay to have it as a non-supported API, as in, have a way to reference that dll as a non stable impl.

@rolfbjarne
Copy link
Member

Duplicating the code does not make much sense - JITing twice, different assemblies, etc. It would probably be okay to have it as a non-supported API, as in, have a way to reference that dll as a non stable impl.

At that point it might just as well be shipped differently (NuGet for instance).

@Therzok
Copy link
Contributor Author

Therzok commented Jul 19, 2021

Another possible impl would be source generation similar to dotnet/pinvoke#565

@dalexsoto
Copy link
Member

I am not sold on the idea of these being public even if they get versioned in NuGet, as @rolfbjarne mentioned things change on each release and if people get stuck or another package depends on a specific one because things changed and there are members that are no longer available but the latest SDK depends on the latest version because of new p/invokes are required it gets really hairy and painful really fast.

The source generator idea is not bad but I think at this point is not in the scope of .NET 6

@dalexsoto dalexsoto added this to the Future milestone Jul 26, 2021
@dalexsoto dalexsoto added enhancement The issue or pull request is an enhancement help wanted This is an issue or pull request where we request help from the community to fix or complete iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac labels Jul 26, 2021
@dalexsoto
Copy link
Member

We have discussed this idea further and we all agreed on not being in the scope of the project, if you need any p/invokes these should live and be maintained in the project that needs them.

@ghost ghost locked as resolved and limited conversation to collaborators Apr 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement The issue or pull request is an enhancement help wanted This is an issue or pull request where we request help from the community to fix or complete iOS Issues affecting Xamarin.iOS macOS Issues affecting Xamarin.Mac
Projects
None yet
Development

No branches or pull requests

3 participants