[godot] Fix various issues with GDExtension on Apple platforms#2768
[godot] Fix various issues with GDExtension on Apple platforms#2768badlogic merged 1 commit intoEsotericSoftware:4.2from
Conversation
|
@mihe thank you so much for this work! All your issue resolutions make sense. For the
I will investigate. I'm aware of the editor crashing on exit, but have not seen it crash on start-up. |
|
I've now tested this on both macOS and iOS, works as intended. I have added a simple mechanism that fetches the major.minor from the git branch name to be included in the Info.plist, which will work for our infra, but might not work in forks. I can still see the crash on editor exit, but I can not reproduce a crash on start-up as you reported. If you could open an issue with repro steps I'd be much obliged. |
Forgive the issue(s) and PR rolled into one, but there are a number of issues with the GDExtension builds for Apple platforms currently, which this PR tries to address.
I realize there's a lot to unpack here. This all started out as trying to figure out why the iOS builds weren't working when using the spine-godot GDExtension, and very much snowballed from there, unfortunately.
macOS
Info.plistpresent in this extension and that one was generated automatically instead.Resources/Info.plist, which serves as a manifest of sorts. However, this should ideally be done by the extension author instead.Info.plist(using SConsenv.Substfile) that matches the format that Godot itself uses, just as a starting point.template_debugandtemplate_releasebinaries were added into the same Framework bundles, which isn't correct, as the Framework bundles are effectively what are meant to be the shared libraries, so needs to host one binary per bundle instead.macosbuilds to result in a 1-to-1 mapping of Framework bundles and binaries.[libraries]entries for macOS in the*.gdextensionfile were referencing the binaries within the Framework bundles, which isn't entirely correct, for the reasons mentioned above, and also needed to be changed to accommodate for theInfo.plist, which otherwise wouldn't be found on export.[libraries]entries to reference the Framework bundles instead.spine-godot/build/build-extension.sh, were manually building for botharm64andx86_64and combining them into universal binaries withlipo. This is already done for you by the defaultarch=universal.macos-specific building and just let it rely on the default case instead.iOS
*.afiles (as seen here) and put into XCFramework bundles, which can't be linked against when Xcode builds the app.*.gdextensionfile (like this). However, this means that if you as the end-user rely on multiple GDExtensions, you'll almost certainly end up with collisions and/or binary incompatibilities between their different godot-cpp libraries, which can't be resolved without building every GDExtension from source and modifying them to reference the same godot-cpp XCFramework.simulatorfeature tag in the*.gdextensionfile to load the appropriate one, similar to how threaded and non-threaded web builds are loaded.install_name(a search path) to the linker, otherwise you'll get a dynamic linker error at runtime when you try to launch an iOS app that uses the extension.install_name_toolfound on macOS, in the case where you only distribute*.dylibfiles for iOS.-Wl,-install_name,@rpath/...as linker arguments when building, which achieves the same effect as what Godot does withinstall_name_tool.macosbuilds as well, but I don't believe it's necessary there, but doesn't seem to cause any problems either way.Info.plistalongside the binary, same as with macOS, so I added generation of that for iOS as well, which matches the format that Godot generates for you when you only distribute*.dylibfiles for iOS.General
*.gdextensionfile was using absolute resource paths when referencing the different libraries, which isn't strictly necessary, and restricts where the end-user can put the GDExtension in their project. It's possible to use relative paths instead.*.gdextensionfile instead.I've tested all this with both the
4.2branch of godot-cpp, as well as the4.3branch, and both seemed to work when used with Godot 4.4-rc2. However, when rebasing in some of the later changes to spine-runtimes4.2branch (5d23a7d...268d0e8) the4.2branch of godot-cpp started crashing as soon as you start the editor.