This repo contains a starter XCode project and SCons configuration to build GDNative library for iOS platform.
XCode project allows to build .framework or .xcframework (using specific script).
SCons configuration builds a static (.a) or dynamic (.dylib) iOS library.
All resulting products can be used for creating GDNative library in Godot project.
To generate libgdnative.fat.a perform inside godot-cpp directory:
scons platform=ios ios_arch=armv7 target=<target> -j4
scons platform=ios ios_arch=arm64 target=<target> -j4
scons platform=ios ios_arch=arm64 ios_simulator=yes target=<target> -j4
scons platform=ios ios_arch=x86_64 ios_simulator=yes target=<target> -j4
lipo -create bin/libgodot-cpp.ios.<target>.arm64.a bin/libgodot-cpp.ios.<target>.armv7.a -output bin/gdnative.fat.device.a
lipo -create bin/libgodot-cpp.ios.<target>.x86_64.simulator.a bin/libgodot-cpp.ios.<target>.arm64.simulator.a -output bin/gdnative.fat.simulator.a
For more detailed information about building gdnative binary and using resulting dynamic or static library go to Godot Docs
Change Bundle Identifier to some unique value. Each framework should have different bundle identifiers.
Change Product Name parameter in Build Settings tab to the name you would want to use.
Add source files to project.
Using static (.a) library will require adding and linking libgdnative.fat.a that was previously built to exported iOS app. This can be simplified by moving libgdnative.fat.a to godot project folder and adding it as dependency in .gdnlib file.
To build .a library run:
scons platform=ios arch=<arch> target_name=<library_name> gdnative_lib_path=<optional path to gdnative libraries> gdnative_lib=<optional library name>
To build .dylib library run:
scons platform=ios arch=<arch> target_name=<library_name> mode=dynamic gdnative_lib_path=<optional path to gdnative libraries> gdnative_lib=<optional library name>
To create a .xcframework from .a
library run:
xcodebuild -create-xcframework \
-library <library_1> \
...
-library <library_2> \
-output "./bin/$1.$2.xcframework"
To create a .xcframework from .dylib
library you will have to create .framework
from .dylib
and then run:
xcodebuild -create-xcframework \
-framework <framework_1> \
...
-framework <framework_2> \
-output "./bin/$1.$2.xcframework"
Alternatively you can use xcframework_build.sh
script, but it might require tweaks in Xcode project.
bash ./xcframework_build.sh <project_name> <scheme_name> <product_name>
Example:
bash ./xcframework_build.sh gdnative_ios.xcodeproj library gdexample