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

iOS export of C++ GDExtension fails in 4.3-dev5 #90168

Closed
ybin64 opened this issue Apr 3, 2024 · 5 comments · Fixed by #95323
Closed

iOS export of C++ GDExtension fails in 4.3-dev5 #90168

ybin64 opened this issue Apr 3, 2024 · 5 comments · Fixed by #95323

Comments

@ybin64
Copy link

ybin64 commented Apr 3, 2024

Tested versions

Reproducable in 4.3-dev5, 4.3-dev [29b3d9e]
Works in 4.2.1

System information

Target iOS 17.4.1, build machine MacOS 14.4.1

Issue description

iOS export of a project with a C++ GDExtension fails in Godot 4.3-dev5.

I believe it's related to the following commit [iOS export] Improve .xcframework exporting.

I had 2 problems.

  1. Link problem during export.

     ld: file cannot be mmap()ed, errno=22 path=godot-gdextension-test/dylibs/bin/libgdexample.ios.template_debug.universal.framework/libgdexample.ios.template_debug.universal in
        'godot-gdextension-test/dylibs/bin/libgdexample.ios.template_debug.universal.framework/libgdexample.ios.template_debug.universal'
     clang: error: linker command failed with exit code 1 (use -v to see invocation)

    Fixed in Fixed link error during export.

  2. Runtime error on device, the libgdexample framework isn't found

    Caused by the problem 1 fix.

    dyld[6062]: Library not loaded: demo/bin/libgdexample.ios.template_debug.framework/libgdexample.ios.template_debug
      Referenced from: <C5B2228B-F230-351B-B46B-ECED5AACFCEB> /private/var/containers/Bundle/Application/7551DD31-129E-4BF8-8629-FB9A4A2915F9/godot-gdextension-test.app/godot-gdextension-test
      Reason: tried: 
        'demo/bin/libgdexample.ios.template_debug.framework/libgdexample.ios.template_debug' (no such file), 
        '/private/preboot/Cryptexes/OSdemo/bin/libgdexample.ios.template_debug.framework/libgdexample.ios.template_debug' (no such file), 
        'demo/bin/libgdexample.ios.template_debug.framework/libgdexample.ios.template_debug' (no such file)

    Fixed in Frameworks converted from .dylib are embedded as "CodeSignOnCopy" in the xcode projet

Both fixes are in the following branch. 4.3-dev-ios-gdextension-link-and-dylib-failure-fix but I'm pretty sure it's not the correct way to solve the problem, but may be useful for someone until the real fix.

Steps to reproduce

  • Use 4.3-dev5 and the matching export templates

  • Follow the instructions in gdextension_cpp_example

  • Add the following lines to demo/bin/gdexample.gdextension

ios.debug = "res://bin/libgdexample.ios.template_debug.universal.dylib"
ios.release = "res://bin/libgdexample.ios.template_release.universal.dylib"
  • Build the extension

  • Export an iOS project, will fail with a link error during the export

 ld: file cannot be mmap()ed, errno=22 path=godot-gdextension-test/dylibs/bin/libgdexample.ios.template_debug.universal.framework/libgdexample.ios.template_debug.universal in
    'godot-gdextension-test/dylibs/bin/libgdexample.ios.template_debug.universal.framework/libgdexample.ios.template_debug.universal'
 clang: error: linker command failed with exit code 1 (use -v to see invocation)

Minimal reproduction project (MRP)

N/A

@rjgameiro
Copy link

rjgameiro commented Aug 8, 2024

Godot 4.3 RC3 seems to still be suffering from this problem.
Tried the exact same project (plain GDExtension example from Godot documentation) with Godot 4.2.2 and Godot 4.3 RC3, and while 4.2.2 succeeds, 4.3 RC3 fails on build on iOS with the error:

Ld /Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/InstallationBuildProductsLocation/Applications/amber.app/amber normal (in target 'amber' from project 'amber')
cd /Users/rgameiro/Temporary/iOS
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -Xlinker -reproducible -target arm64-apple-ios13.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS17.5.sdk -O0 -L/Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/IntermediateBuildFilesPath/EagerLinkingTBDs/Debug-iphoneos -L/Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/BuildProductsPath/Debug-iphoneos -L. -LMoltenVK.xcframework -Lamber -Lamber.xcframework -LMoltenVK.xcframework/ios-arm64 -LMoltenVK.xcframework/ios-arm64_x86_64-maccatalyst -LMoltenVK.xcframework/ios-arm64_x86_64-simulator -Lamber/dylibs -Lamber.xcframework/ios-arm64 -Lamber.xcframework/ios-arm64_x86_64-simulator -Lamber/dylibs/bin -F/Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/IntermediateBuildFilesPath/EagerLinkingTBDs/Debug-iphoneos -F/Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/BuildProductsPath/Debug-iphoneos -F. -FMoltenVK.xcframework -Famber -Famber.xcframework -FMoltenVK.xcframework/ios-arm64 -FMoltenVK.xcframework/ios-arm64_x86_64-maccatalyst -FMoltenVK.xcframework/ios-arm64_x86_64-simulator -Famber/dylibs -Famber.xcframework/ios-arm64 -Famber.xcframework/ios-arm64_x86_64-simulator -Famber/dylibs/bin -filelist /Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/IntermediateBuildFilesPath/amber.build/Debug-iphoneos/amber.build/Objects-normal/arm64/amber.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/IntermediateBuildFilesPath/amber.build/Debug-iphoneos/amber.build/Objects-normal/arm64/amber_lto.o -Xlinker -no_deduplicate -Xlinker -final_output -Xlinker /Applications/amber.app/amber -stdlib\=libc++ -lMoltenVK -lgodot -framework libgdexample.ios.template_debug.universal -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/IntermediateBuildFilesPath/amber.build/Debug-iphoneos/amber.build/Objects-normal/arm64/amber_dependency_info.dat -o /Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/InstallationBuildProductsLocation/Applications/amber.app/amber
ld: file cannot be mmap()ed, errno=22 path=amber/dylibs/bin/libgdexample.ios.template_debug.universal.framework/libgdexample.ios.template_debug.universal in 'amber/dylibs/bin/libgdexample.ios.template_debug.universal.framework/libgdexample.ios.template_debug.universal'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
** ARCHIVE FAILED **
The following build commands failed.
Ld /Users/rgameiro/Library/Developer/Xcode/DerivedData/amber-geepphvxiicnsegpcjbqlufrernb/Build/Intermediates.noindex/ArchiveIntermediates/amber/InstallationBuildProductsLocation/Applications/amber.app/amber normal (in target 'amber' from project 'amber')
(1 failure)

This is what is getting exported by Godot 4.2.2 (for the GDExtension iOS framework):
GOOD-4 2 2

This is what is getting exported by Godot 4.3RC3:
BAD-4 3RC3

Also, the contents of the Info.plist files:

Good Info.plist (Godot 4.2.2)
GOOD-4 2 2-Info

Bad Info.plist (Godot 4.3RC3)
BAD-4 3RC3-Info

I can provide more details if asked.

@akien-mga
Copy link
Member

Could you attach the reproduction project to make testing easier? I know it's derived from our docs but it takes time to reproduce all the setup from the docs. You can remove the compiled objects/libs to keep size low.

CC @bruvzg

@akien-mga akien-mga modified the milestones: 4.x, 4.3 Aug 9, 2024
@rjgameiro
Copy link

Here goes... building extension with:
scons platform=ios custom_api_file=./godot-cpp/extension_api.json
...which was exported from Godot 4.3 RC3.
Removed AppStore Team ID from export settings.

gdextension_cpp_example.zip

@bruvzg
Copy link
Member

bruvzg commented Aug 9, 2024

Most likely something wrong with extension packaging, see generate_xcframework.sh in the https://github.com/godotengine/godot-cpp/tree/master/test as an example of building and packing GDExtension for iOS.

In the exported project should look like this:
Screenshot 2024-08-09 at 11 18 48

Running on a device:
Screenshot 2024-08-09 at 11 51 08

@fatduckling
Copy link

I managed to work around this problem by changing my dylibs to the framework format.
Something like:

xcodebuild -create-xcframework -library libtbb.dylib -output Tbb.xcframework
xcodebuild -create-xcframework -library libtbbmalloc.dylib -output TbbMalloc.xcframework

And in the .gdextension file:

...
[dependencies]

ios.arm64 = {
    "res://bin/libtbb.xcframework": "",
    "res://bin/libtbbmalloc.xcframework": "",
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Very Bad
Development

Successfully merging a pull request may close this issue.

7 participants