Skip to content

Commit eafc21f

Browse files
committed
Merge pull request godotengine#112784 from migueldeicaza/fix_dynamic_xcframework_loading
iOS: Fix loading of xcframework dynamic libraries.
2 parents 8cb98cc + b1465d6 commit eafc21f

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

core/extension/gdextension_library_loader.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,13 @@ Error GDExtensionLibraryLoader::open_library(const String &p_path) {
195195
&abs_dependencies_paths, // library_dependencies
196196
};
197197

198-
err = OS::get_singleton()->open_dynamic_library(is_static_library ? String() : abs_path, library, &data);
198+
// Apple has a complex lookup system which goes beyond looking up the filename, so we try that first.
199+
err = OS::get_singleton()->open_dynamic_library(abs_path, library, &data);
199200
if (err != OK) {
200-
return err;
201+
err = OS::get_singleton()->open_dynamic_library(String(), library, &data);
202+
if (err != OK) {
203+
return err;
204+
}
201205
}
202206

203207
return OK;
@@ -361,8 +365,6 @@ Error GDExtensionLibraryLoader::parse_gdextension_file(const String &p_path) {
361365
return ERR_FILE_NOT_FOUND;
362366
}
363367

364-
is_static_library = library_path.ends_with(".a") || library_path.ends_with(".xcframework");
365-
366368
if (!library_path.is_resource_file() && !library_path.is_absolute_path()) {
367369
library_path = p_path.get_base_dir().path_join(library_path);
368370
}

core/extension/gdextension_library_loader.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ class GDExtensionLibraryLoader : public GDExtensionLoader {
4949
String library_path;
5050
String entry_symbol;
5151

52-
bool is_static_library = false;
53-
5452
#ifdef TOOLS_ENABLED
5553
bool is_reloadable = false;
5654
#endif

drivers/apple_embedded/os_apple_embedded.mm

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ Rect2 fit_keep_aspect_covered(const Vector2 &p_container, const Vector2 &p_rect)
279279
path = get_framework_executable(get_executable_path().get_base_dir().path_join(p_path.get_file().get_basename() + ".framework"));
280280
}
281281

282+
if (!FileAccess::exists(path)) {
283+
// Load .dylib from within the executable path.
284+
path = get_framework_executable(get_executable_path().get_base_dir().path_join(p_path.get_file().get_basename() + ".dylib"));
285+
}
286+
282287
if (!FileAccess::exists(path)) {
283288
// Load .dylib or framework from a standard iOS location.
284289
path = get_framework_executable(get_executable_path().get_base_dir().path_join("Frameworks").path_join(p_path.get_file()));
@@ -289,8 +294,16 @@ Rect2 fit_keep_aspect_covered(const Vector2 &p_container, const Vector2 &p_rect)
289294
path = get_framework_executable(get_executable_path().get_base_dir().path_join("Frameworks").path_join(p_path.get_file().get_basename() + ".framework"));
290295
}
291296

292-
ERR_FAIL_COND_V(!FileAccess::exists(path), ERR_FILE_NOT_FOUND);
297+
if (!FileAccess::exists(path)) {
298+
// Load .dylib from a standard iOS location.
299+
path = get_framework_executable(get_executable_path().get_base_dir().path_join("Frameworks").path_join(p_path.get_file().get_basename() + ".dylib"));
300+
}
293301

302+
if (!FileAccess::exists(path) && (p_path.ends_with(".a") || p_path.ends_with(".xcframework"))) {
303+
path = String(); // Try loading static library.
304+
} else {
305+
ERR_FAIL_COND_V(!FileAccess::exists(path), ERR_FILE_NOT_FOUND);
306+
}
294307
p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW);
295308
ERR_FAIL_NULL_V_MSG(p_library_handle, ERR_CANT_OPEN, vformat("Can't open dynamic library: %s. Error: %s.", p_path, dlerror()));
296309

0 commit comments

Comments
 (0)