Skip to content

Commit 30704d8

Browse files
committed
[iOS] Fix building as static library or xcframework, add iOS config and xcframework build script to the test project.
1 parent 2dfe792 commit 30704d8

File tree

9 files changed

+52
-17
lines changed

9 files changed

+52
-17
lines changed

include/godot_cpp/classes/wrapped.hpp

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

include/godot_cpp/core/memory.hpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@
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+
void *operator new(size_t p_size, const char *p_dummy, const char *p_description); ///< operator new that takes a description and uses MemoryStaticPool
48+
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
49+
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
5050

51-
_ALWAYS_INLINE_ void *operator new(size_t p_size, void *p_pointer, size_t check, const char *p_description) {
51+
_ALWAYS_INLINE_ void *operator new(size_t p_size, const char *p_dummy, void *p_pointer, size_t check, const char *p_description) {
5252
return p_pointer;
5353
}
5454

5555
#ifdef _MSC_VER
5656
// When compiling with VC++ 2017, the above declarations of placement new generate many irrelevant warnings (C4291).
5757
// 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);
58+
void operator delete(void *p_mem, const char *p_dummy, const char *p_description);
59+
void operator delete(void *p_mem, const char *p_dummy, void *(*p_allocfunc)(size_t p_size));
60+
void operator delete(void *p_mem, const char *p_dummy, void *p_pointer, size_t check, const char *p_description);
6161
#endif
6262

6363
namespace godot {
@@ -85,10 +85,10 @@ _ALWAYS_INLINE_ T *_post_initialize(T *p_obj) {
8585
#define memrealloc(m_mem, m_size) ::godot::Memory::realloc_static(m_mem, m_size)
8686
#define memfree(m_mem) ::godot::Memory::free_static(m_mem)
8787

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

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)
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)
9292

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

155155
/* call operator new */
156156
for (size_t i = 0; i < p_elements; i++) {
157-
new (&elems[i], sizeof(T), p_descr) T;
157+
new ("", &elems[i], sizeof(T), p_descr) T;
158158
}
159159
}
160160

src/core/memory.cpp

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

104104
} // namespace godot
105105

106-
void *operator new(size_t p_size, const char *p_description) {
106+
void *operator new(size_t p_size, const char *p_dummy, const char *p_description) {
107107
return godot::Memory::alloc_static(p_size);
108108
}
109109

110-
void *operator new(size_t p_size, void *(*p_allocfunc)(size_t p_size)) {
110+
void *operator new(size_t p_size, const char *p_dummy, void *(*p_allocfunc)(size_t p_size)) {
111111
return p_allocfunc(p_size);
112112
}
113113

114114
using namespace godot;
115115

116116
#ifdef _MSC_VER
117-
void operator delete(void *p_mem, const char *p_description) {
117+
void operator delete(void *p_mem, const char *p_dummy, const char *p_description) {
118118
ERR_PRINT("Call to placement delete should not happen.");
119119
CRASH_NOW();
120120
}
121121

122-
void operator delete(void *p_mem, void *(*p_allocfunc)(size_t p_size)) {
122+
void operator delete(void *p_mem, const char *p_dummy, void *(*p_allocfunc)(size_t p_size)) {
123123
ERR_PRINT("Call to placement delete should not happen.");
124124
CRASH_NOW();
125125
}
126126

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

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
@@ -5,14 +5,22 @@ compatibility_minimum = "4.1"
55

66
[libraries]
77

8+
ios.debug = "res://bin/libgdexample.ios.template_debug.xcframework"
9+
ios.release = "res://bin/libgdexample.ios.template_release.xcframework"
810
macos.debug = "res://bin/libgdexample.macos.template_debug.framework"
911
macos.release = "res://bin/libgdexample.macos.template_release.framework"
1012
windows.debug.x86_32 = "res://bin/libgdexample.windows.template_debug.x86_32.dll"
1113
windows.release.x86_32 = "res://bin/libgdexample.windows.template_release.x86_32.dll"
1214
windows.debug.x86_64 = "res://bin/libgdexample.windows.template_debug.x86_64.dll"
1315
windows.release.x86_64 = "res://bin/libgdexample.windows.template_release.x86_64.dll"
16+
windows.debug.arm64 = "res://bin/libgdexample.windows.template_debug.arm64.dll"
17+
windows.release.arm64 = "res://bin/libgdexample.windows.template_release.arm64.dll"
18+
linux.debug.x86_32 = "res://bin/libgdexample.linux.template_debug.x86_32.so"
19+
linux.release.x86_32 = "res://bin/libgdexample.linux.template_release.x86_32.so"
1420
linux.debug.x86_64 = "res://bin/libgdexample.linux.template_debug.x86_64.so"
1521
linux.release.x86_64 = "res://bin/libgdexample.linux.template_release.x86_64.so"
22+
linux.debug.arm32 = "res://bin/libgdexample.linux.template_debug.arm32.so"
23+
linux.release.arm32 = "res://bin/libgdexample.linux.template_release.arm32.so"
1624
linux.debug.arm64 = "res://bin/libgdexample.linux.template_debug.arm64.so"
1725
linux.release.arm64 = "res://bin/libgdexample.linux.template_release.arm64.so"
1826
linux.debug.rv64 = "res://bin/libgdexample.linux.template_debug.rv64.so"
@@ -23,3 +31,11 @@ android.debug.arm64 = "res://bin/libgdexample.android.template_debug.arm64.so"
2331
android.release.arm64 = "res://bin/libgdexample.android.template_release.arm64.so"
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)