We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4372 - [patch] Add Xamarin.iOS support
Summary: [patch] Add Xamarin.iOS support
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: 2.0.9
Hardware: iPhone/iPod touch iOS (All)
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-08 17:23 UTC by Caleb Cornett
Modified: 2019-03-20 02:31 UTC (History)
1 user (show)

See Also:


Attachments
Patch to add support for Xamarin.iOS (868 bytes, patch)
2018-11-08 17:23 UTC, Caleb Cornett
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Caleb Cornett 2018-11-08 17:23:09 UTC
Created attachment 3467 [details]
Patch to add support for Xamarin.iOS

As you may know, Xamarin is Microsoft's toolkit for enabling developers to write apps for mobile platforms using C#. However, because of Apple's strict rules on dynamic code generation, Xamarin.iOS apps are AOT compiled, and all native libraries used in the project must be statically-linked.

When attempting to statically link libSDL2.a with a Xamarin.iOS project, it results in a build-time linker error about an "undefined symbol _SDL_main", indicating that the usual redefinition of main() doesn't work in this context. (Not surprising, since C# has a different signature for its Main function.)

To overcome this limitation and to enable use of SDL in Xamarin apps, I propose the attached patch. This patch handles the redefinition of main() and adds an SDL_XamarinRunApp() function, similar to SDL_WinRTRunApp(). All the relevant code is sectioned off inside #ifdef XAMARIN blocks, so normal iOS development is not affected.

I've tested this patch on iOS and tvOS, and it works like a charm. However, I'm sure it can be improved -- especially in regard to naming and organization. Additionally, this currently requires a compiler flag (-DXAMARIN) to build. Is that acceptable, or is there a better way to enable this feature?
Comment 1 Caleb Cornett 2019-03-20 02:30:05 UTC
Closing, as this was indirectly fixed by https://hg.libsdl.org/SDL/rev/e7f525b10380#l2.41
Comment 2 Caleb Cornett 2019-03-20 02:31:55 UTC
.