Repository navigation
Conversation
… and other apple related stuff) retains my stuff: SDL3_main/-Dmain_callbacks; helpers for finding and linking Apple SDK's for iOS; and this thing where sanitize_c is not working on iOS (seems that Zig's UBSan does not understand something Apple-related)
…un always, and also unify SDK logic in one place
|
Nice thanks for the PR! I'm going to have access to a mac to test with next week, at which point I'll review all the Apple related PRs. No worries about conflicts with other open PRs I can sort all that out. :) |
|
Great, thank you! Happy to break this into pieces or remove things, whatever seems best. |
MasonRemaley
left a comment
There was a problem hiding this comment.
Thanks for the PR! Left some comments, feel free to push back on anything you think that I'm misunderstanding.
| \\than a classic SDL_main, defaults to false | ||
| ) orelse false; | ||
|
|
||
| const can_san = target.result.os.tag != .ios; |
There was a problem hiding this comment.
What triggers the sanitizer to fail? Instead of turning it off, maybe we can patch SDL to fix the UB. I've landed other UBSAN related fixes in SDL and they've been happy to merge them.
| .flags = flags, | ||
| }); | ||
|
|
||
| const main_lib = b.addLibrary(.{ |
There was a problem hiding this comment.
Does this need to be a separate static library, or could we instead configure the existing SDL library differently depending on whether or not the callbacks feature is enabled?
| // SDK's headers/frameworks/libs passed in explicitly. Scoped to the SDL library only, unlike | ||
| // `--sysroot` this does not re-roots paths across the whole build graph. | ||
| const system_paths: SystemPaths = .{ | ||
| // On Apple, if paths are not passed explicitly then fall back to the SDK found via `xcrun`. |
There was a problem hiding this comment.
I don't think we should have to bake in platform specific paths into this file. I would expect dependencies to be found one of three ways:
- Provided by the build system (e.g. via
build.zig.zon) - Provided by the system (e.g.
-fsys=...andlinkSystemLibrary/such) - Provided by the user (e.g.
--search-prefix)
I think this might be on me for not reviewing some of the previous macOS PRs carefully enough. I have access to a mac for a few weeks, so unless you feel motivated to take on the task of cleaning that up feel free to just move this part of the changes into your example and I can work on that separately.
You can leave the translate C change here for now though since IIUC that's necessary for this to work at all.
| , | ||
| ) orelse .static; | ||
|
|
||
| const main_callbacks = b.option(bool, "main_callbacks", |
There was a problem hiding this comment.
I think it would be reasonable to duplicate the example program and rename it to callbacks_example, and make use of this feature there.
Hi all,
This PR does a couple of things to get SDL working on iOS with SDL's callbacks.
-Dmain_callbacks: when passed,src/sdl_main.cincludes SDL'sSDL_main.haddAppleSdkPathsToModulewhich users can call in their builds to link UIKit etc as needed. I'm not sure if this part would be controversial and happy to remove it. It's used in my demo (below) so I could move it there, but I think that any iOS-targeting user would need something similar.I haven't updated the demo in this repo since I didn't want to force it to use callbacks, but I reworked it here:
https://github.com/cwindolf/zig-sdl3-callbacks-example. In that repository, you can
zig build ios-run -Dtarget=aarch64-ios-simulatorand see the rainbow appear on the iPhone of your choice.I wrote this in a vacuum so I apologize if it conflicts with other PRs or handles existing issues in a non-optimal way. I tried to get a handle on those questions, here are some notes:
-Dinclude_pathlogic as a special case, for instance. They also change this repo's demo app to use callbacks, but in a way which wouldn't work on iOS because iOS needs to run viaSDL_RunApp.Thank you for taking a look at this. Let me know if it's useful, and if so if there are any changes you'd suggest! For now, I haven't touched the README or the example. I wanted to check in about the approach first, but I could at least mention -Dmain_callbacks in the README if that's of interest. Not sure what to do about the example, I'm open to any options.