Skip to content

Commit 2d66988

Browse files
committed
[GDExtension] Improve macOS library loading/export.
1 parent 1bffd6c commit 2d66988

File tree

3 files changed

+52
-8
lines changed

3 files changed

+52
-8
lines changed

core/os/os.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,11 @@ bool OS::has_feature(const String &p_feature) {
439439
}
440440
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64__) || defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(_M_X64)
441441
#if defined(__x86_64) || defined(__x86_64__) || defined(__amd64__) || defined(_M_X64)
442+
#if defined(MACOS_ENABLED)
443+
if (p_feature == "universal") {
444+
return true;
445+
}
446+
#endif
442447
if (p_feature == "x86_64") {
443448
return true;
444449
}
@@ -452,6 +457,11 @@ bool OS::has_feature(const String &p_feature) {
452457
}
453458
#elif defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64)
454459
#if defined(__aarch64__) || defined(_M_ARM64)
460+
#if defined(MACOS_ENABLED)
461+
if (p_feature == "universal") {
462+
return true;
463+
}
464+
#endif
455465
if (p_feature == "arm64") {
456466
return true;
457467
}

editor/plugins/gdextension_export_plugin.h

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,24 +77,37 @@ void GDExtensionExportPlugin::_export_file(const String &p_path, const String &p
7777

7878
HashSet<String> archs;
7979
HashSet<String> features_wo_arch;
80+
Vector<String> features_vector;
8081
for (const String &tag : p_features) {
8182
if (all_archs.has(tag)) {
8283
archs.insert(tag);
8384
} else {
8485
features_wo_arch.insert(tag);
8586
}
87+
features_vector.append(tag);
8688
}
8789

8890
if (archs.is_empty()) {
8991
archs.insert("unknown_arch"); // Not archs specified, still try to match.
9092
}
9193

9294
HashSet<String> libs_added;
95+
struct FoundLibInfo {
96+
int count = 0;
97+
Vector<String> libs;
98+
};
99+
HashMap<String, FoundLibInfo> libs_found;
100+
for (const String &arch_tag : archs) {
101+
if (arch_tag != "universal") {
102+
libs_found[arch_tag] = FoundLibInfo();
103+
}
104+
}
93105

94106
for (const String &arch_tag : archs) {
95107
PackedStringArray tags;
96108
String library_path = GDExtensionLibraryLoader::find_extension_library(
97109
p_path, config, [features_wo_arch, arch_tag](const String &p_feature) { return features_wo_arch.has(p_feature) || (p_feature == arch_tag); }, &tags);
110+
98111
if (libs_added.has(library_path)) {
99112
continue; // Universal library, already added for another arch, do not duplicate.
100113
}
@@ -122,22 +135,38 @@ void GDExtensionExportPlugin::_export_file(const String &p_path, const String &p
122135
String linker_flags = "-Wl,-U,_" + entry_symbol;
123136
add_ios_linker_flags(linker_flags);
124137
}
125-
} else {
126-
Vector<String> features_vector;
127-
for (const String &E : p_features) {
128-
features_vector.append(E);
129-
}
130-
if (get_export_platform().is_valid()) {
131-
get_export_platform()->add_message(EditorExportPlatform::EXPORT_MESSAGE_WARNING, TTR("GDExtension"), vformat(TTR("No suitable library found for GDExtension: \"%s\". Possible feature flags for your platform: %s"), p_path, String(", ").join(features_vector)));
138+
139+
// Update found library info.
140+
if (arch_tag == "universal") {
141+
for (const String &sub_arch_tag : archs) {
142+
if (sub_arch_tag != "universal") {
143+
libs_found[sub_arch_tag].count++;
144+
libs_found[sub_arch_tag].libs.push_back(library_path);
145+
}
146+
}
147+
} else {
148+
libs_found[arch_tag].count++;
149+
libs_found[arch_tag].libs.push_back(library_path);
132150
}
133-
return;
134151
}
135152

136153
Vector<SharedObject> dependencies_shared_objects = GDExtensionLibraryLoader::find_extension_dependencies(p_path, config, [p_features](String p_feature) { return p_features.has(p_feature); });
137154
for (const SharedObject &shared_object : dependencies_shared_objects) {
138155
_add_shared_object(shared_object);
139156
}
140157
}
158+
159+
for (const KeyValue<String, FoundLibInfo> &E : libs_found) {
160+
if (E.value.count == 0) {
161+
if (get_export_platform().is_valid()) {
162+
get_export_platform()->add_message(EditorExportPlatform::EXPORT_MESSAGE_WARNING, TTR("GDExtension"), vformat(TTR("No \"%s\" library found for GDExtension: \"%s\". Possible feature flags for your platform: %s"), E.key, p_path, String(", ").join(features_vector)));
163+
}
164+
} else if (E.value.count > 1) {
165+
if (get_export_platform().is_valid()) {
166+
get_export_platform()->add_message(EditorExportPlatform::EXPORT_MESSAGE_WARNING, TTR("GDExtension"), vformat(TTR("Multiple \"%s\" libraries found for GDExtension: \"%s\": \"%s\"."), E.key, p_path, String(", ").join(E.value.libs)));
167+
}
168+
}
169+
}
141170
}
142171

143172
#endif // GDEXTENSION_EXPORT_PLUGIN_H

platform/macos/export/export_plugin.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ void EditorExportPlatformMacOS::get_preset_features(const Ref<EditorExportPreset
6565
} else {
6666
ERR_PRINT("Invalid architecture");
6767
}
68+
69+
if (architecture == "universal") {
70+
r_features->push_back("x86_64");
71+
r_features->push_back("arm64");
72+
}
6873
}
6974

7075
String EditorExportPlatformMacOS::get_export_option_warning(const EditorExportPreset *p_preset, const StringName &p_name) const {

0 commit comments

Comments
 (0)