SDL icon indicating copy to clipboard operation
SDL copied to clipboard

Target to build xcframework on iOS

Open tjpadula opened this issue 3 years ago • 7 comments

I’ve been working on an iOS app using SDL. In so doing, I've run in to the common problem, with the release of Apple Silicon Macs, of having to constantly switch framework builds when switching between the simulator and a real device. Apple's solution for this is to use an xcframework, which was created for this purpose a few years back on Xcode 11.

The point of such a framework is to allow a single dynamically-linked lib for a client app that works on all combinations of device/simulator vs. Intel /Apple Silicon. (A conventional framework cannot do this, neither can statically linked libraries.)

I have this working to a first approximation on Xcode 11 and later. At this point, it builds SDL2.xcframework in a Products directory adjacent to SDL.xcodeproj. No other targets of the Xcode project have been changed. I have it on a branch and can of create a pull request if the build team would like to give it a go.

tjpadula avatar Aug 29 '22 21:08 tjpadula

Sure, that would be interesting to look at. Thanks!

slouken avatar Aug 30 '22 00:08 slouken

@tjpadula are you willing to share your branch? I am running into the same issues myself right now :)

tyrondis avatar Sep 02 '22 09:09 tyrondis

Never mind, found it and can confirm it works! Only thing I had to change was the include path inside SDL_uikit_main.c from SDL_main.h to SDL2/SDL_main.h.

tyrondis avatar Sep 02 '22 10:09 tyrondis

xcodebuild -create-xcframework can create an xcframework from multiple .a files, if anyone's interested in that sort of workaround for now. I've used it successfully in my projects that use SDL for iOS (by building a static library of SDL for each of the two main architecture sets - simulator platforms versus device platforms - and saving them, and using xcodebuild to combine them into an xcframework structure).

slime73 avatar Sep 02 '22 17:09 slime73

Ok, I have created a pull request after making sure there is relevant guidance in README-ios.md. This build has been tested on Xcode 11, 12, and 13, on both Intel and Apple Silicon (AS only for Xcode 13 of course).

tjpadula avatar Sep 05 '22 18:09 tjpadula

@tjpadula can we do the same for SDL_image? Tried to google how to set it up in Xcode but wasn't very successful. Any pointers?

tyrondis avatar Sep 08 '22 19:09 tyrondis

I haven't tried it. I could take a look in the next day or two. I don't see why it wouldn't work.

tjpadula avatar Sep 09 '22 01:09 tjpadula

The SDL libraries are now set up to build xcframeworks.

slouken avatar Nov 07 '23 16:11 slouken