Skip to content

Commit 29b34d9

Browse files
committed
[iOS] Fix building as static library or xcframework, add iOS config and xcframework build script to the test project.
1 parent cc89bd2 commit 29b34d9

File tree

9 files changed

+54
-17
lines changed

9 files changed

+54
-17
lines changed

include/godot_cpp/classes/wrapped.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ public:
450450
\
451451
static void *_gde_binding_create_callback(void *p_token, void *p_instance) { \
452452
/* Do not call memnew here, we don't want the post-initializer to be called */ \
453-
return new ("") m_class((GodotObject *)p_instance); \
453+
return new ("", "") m_class((GodotObject *)p_instance); \
454454
} \
455455
static void _gde_binding_free_callback(void *p_token, void *p_instance, void *p_binding) { \
456456
/* Explicitly call the deconstructor to ensure proper lifecycle for non-trivial members */ \

include/godot_cpp/core/memory.hpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,21 @@
4444
#define PAD_ALIGN 16 //must always be greater than this at much
4545
#endif
4646

47-
void *operator new(size_t p_size, const char *p_description); ///< operator new that takes a description and uses MemoryStaticPool
48-
void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)); ///< operator new that takes a description and uses MemoryStaticPool
49-
void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description); ///< operator new that takes a description and uses a pointer to the preallocated memory
47+
// p_dummy argument is added to avoid conflicts with the engine functions when both engine and GDExtension are built as a static library on iOS.
48+
void *operator new(size_t p_size, const char *p_dummy, const char *p_description); ///< operator new that takes a description and uses MemoryStaticPool
49+
void *operator new(size_t p_size, const char *p_dummy, void *(*p_allocfunc)(size_t p_size)); ///< operator new that takes a description and uses MemoryStaticPool
50+
void *operator new(size_t p_size, const char *p_dummy, void *p_pointer, size_t check, const char *p_description); ///< operator new that takes a description and uses a pointer to the preallocated memory
5051

51-
_ALWAYS_INLINE_ void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description) {
52+
_ALWAYS_INLINE_ void *operator new(size_t p_size, const char *p_dummy, void *p_pointer, size_t check, const char *p_description) {
5253
return p_pointer;
5354
}
5455

5556
#ifdef _MSC_VER
5657
// When compiling with VC++ 2017, the above declarations of placement new generate many irrelevant warnings (C4291).
5758
// The purpose of the following definitions is to muffle these warnings, not to provide a usable implementation of placement delete.
58-
void operator delete(void *p_mem, const char *p_description);
59-
void operator delete(void *p_mem, void *(*p_allocfunc)(size_t p_size));
60-
void operator delete(void *p_mem, void *p_pointer, size_t check, const char *p_description);
59+
void operator delete(void *p_mem, const char *p_dummy, const char *p_description);
60+
void operator delete(void *p_mem, const char *p_dummy, void *(*p_allocfunc)(size_t p_size));
61+
void operator delete(void *p_mem, const char *p_dummy, void *p_pointer, size_t check, const char *p_description);
6162
#endif
6263

6364
namespace godot {
@@ -85,10 +86,10 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
8586
#define memrealloc(m_mem, m_size) ::godot::Memory::realloc_static(m_mem, m_size)
8687
#define memfree(m_mem) ::godot::Memory::free_static(m_mem)
8788

88-
#define memnew(m_class) ::godot::_post_initialize(new ("") m_class)
89+
#define memnew(m_class) ::godot::_post_initialize(new ("", "") m_class)
8990

90-
#define memnew_allocator(m_class, m_allocator) ::godot::_post_initialize(new (m_allocator::alloc) m_class)
91-
#define memnew_placement(m_placement, m_class) ::godot::_post_initialize(new (m_placement, sizeof(m_class), "") m_class)
91+
#define memnew_allocator(m_class, m_allocator) ::godot::_post_initialize(new ("", m_allocator::alloc) m_class)
92+
#define memnew_placement(m_placement, m_class) ::godot::_post_initialize(new ("", m_placement, sizeof(m_class), "") m_class)
9293

9394
// Generic comparator used in Map, List, etc.
9495
template <class T>
@@ -154,7 +155,7 @@ T *memnew_arr_template(size_t p_elements, const char *p_descr = "") {
154155

155156
/* call operator new */
156157
for (size_t i = 0; i < p_elements; i++) {
157-
new (&elems[i], sizeof(T), p_descr) T;
158+
new ("", &elems[i], sizeof(T), p_descr) T;
158159
}
159160
}
160161

src/core/memory.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,28 +103,29 @@ _GlobalNil _GlobalNilClass::_nil;
103103

104104
} // namespace godot
105105

106-
void *operator new(size_t p_size, const char *p_description) {
106+
// p_dummy argument is added to avoid conflicts with the engine functions when both engine and GDExtension are built as a static library on iOS.
107+
void *operator new(size_t p_size, const char *p_dummy, const char *p_description) {
107108
return godot::Memory::alloc_static(p_size);
108109
}
109110

110-
void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) {
111+
void *operator new(size_t p_size, const char *p_dummy, void *(*p_allocfunc)(size_t p_size)) {
111112
return p_allocfunc(p_size);
112113
}
113114

114115
using namespace godot;
115116

116117
#ifdef _MSC_VER
117-
void operator delete(void *p_mem, const char *p_description) {
118+
void operator delete(void *p_mem, const char *p_dummy, const char *p_description) {
118119
ERR_PRINT("Call to placement delete should not happen.");
119120
CRASH_NOW();
120121
}
121122

122-
void operator delete(void *p_mem, void *(*p_allocfunc)(size_t p_size)) {
123+
void operator delete(void *p_mem, const char *p_dummy, void *(*p_allocfunc)(size_t p_size)) {
123124
ERR_PRINT("Call to placement delete should not happen.");
124125
CRASH_NOW();
125126
}
126127

127-
void operator delete(void *p_mem, void *p_pointer, size_t check, const char *p_description) {
128+
void operator delete(void *p_mem, const char *p_dummy, void *p_pointer, size_t check, const char *p_description) {
128129
ERR_PRINT("Call to placement delete should not happen.");
129130
CRASH_NOW();
130131
}

test/SConstruct

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ if env["platform"] == "macos":
2323
),
2424
source=sources,
2525
)
26+
elif env["platform"] == "ios":
27+
if env["ios_simulator"]:
28+
library = env.StaticLibrary(
29+
"project/bin/libgdexample.{}.{}.simulator.a".format(env["platform"], env["target"]),
30+
source=sources,
31+
)
32+
else:
33+
library = env.StaticLibrary(
34+
"project/bin/libgdexample.{}.{}.a".format(env["platform"], env["target"]),
35+
source=sources,
36+
)
2637
else:
2738
library = env.SharedLibrary(
2839
"project/bin/libgdexample{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),

test/generate_xcframework.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
scons arch=universal ios_simulator=yes platform=ios target=$1 $2
4+
scons arch=arm64 ios_simulator=no platform=ios target=$1 $2
5+
6+
xcodebuild -create-xcframework -library ./project/bin/libgdexample.ios.$1.a -library ./project/bin/libgdexample.ios.$1.simulator.a -output ./project/bin/libgdexample.ios.$1.xcframework
7+
xcodebuild -create-xcframework -library ../bin/libgodot-cpp.ios.$1.arm64.a -library ../bin/libgodot-cpp.ios.$1.universal.simulator.a -output ./project/bin/libgodot-cpp.ios.$1.xcframework

test/project/example.gdextension

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ windows.debug.x86_32 = "res://bin/libgdexample.windows.template_debug.x86_32.dll
1111
windows.release.x86_32 = "res://bin/libgdexample.windows.template_release.x86_32.dll"
1212
windows.debug.x86_64 = "res://bin/libgdexample.windows.template_debug.x86_64.dll"
1313
windows.release.x86_64 = "res://bin/libgdexample.windows.template_release.x86_64.dll"
14+
windows.debug.arm64 = "res://bin/libgdexample.windows.template_debug.arm64.dll"
15+
windows.release.arm64 = "res://bin/libgdexample.windows.template_release.arm64.dll"
16+
linux.debug.x86_32 = "res://bin/libgdexample.linux.template_debug.x86_32.so"
17+
linux.release.x86_32 = "res://bin/libgdexample.linux.template_release.x86_32.so"
1418
linux.debug.x86_64 = "res://bin/libgdexample.linux.template_debug.x86_64.so"
1519
linux.release.x86_64 = "res://bin/libgdexample.linux.template_release.x86_64.so"
20+
linux.debug.arm32 = "res://bin/libgdexample.linux.template_debug.arm32.so"
21+
linux.release.arm32 = "res://bin/libgdexample.linux.template_release.arm32.so"
1622
linux.debug.arm64 = "res://bin/libgdexample.linux.template_debug.arm64.so"
1723
linux.release.arm64 = "res://bin/libgdexample.linux.template_release.arm64.so"
1824
linux.debug.rv64 = "res://bin/libgdexample.linux.template_debug.rv64.so"
@@ -21,5 +27,15 @@ android.debug.x86_64 = "res://bin/libgdexample.android.template_debug.x86_64.so"
2127
android.release.x86_64 = "res://bin/libgdexample.android.template_release.x86_64.so"
2228
android.debug.arm64 = "res://bin/libgdexample.android.template_debug.arm64.so"
2329
android.release.arm64 = "res://bin/libgdexample.android.template_release.arm64.so"
30+
ios.debug = "res://bin/libgdexample.ios.template_debug.xcframework"
31+
ios.release = "res://bin/libgdexample.ios.template_release.xcframework"
2432
web.debug.wasm32 = "res://bin/libgdexample.web.template_debug.wasm32.wasm"
2533
web.release.wasm32 = "res://bin/libgdexample.web.template_release.wasm32.wasm"
34+
35+
[dependencies]
36+
ios.debug = {
37+
"res://bin/libgodot-cpp.ios.template_debug.xcframework": ""
38+
}
39+
ios.release = {
40+
"res://bin/libgodot-cpp.ios.template_release.xcframework": ""
41+
}

test/project/project.godot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ paths=["res://example.gdextension"]
2121

2222
[rendering]
2323

24+
textures/vram_compression/import_etc2_astc=true
2425
environment/defaults/default_environment="res://default_env.tres"

0 commit comments

Comments
 (0)