Skip to content

Commit bf0d491

Browse files
committed
Add a gdextension configuration for the Android / XR Editor
The previous logic only uses `ANDROID_ENABLED` to gate the Platform SDK logic, which causes it to be active when the addon is loaded in the Android / XR editor. The updated logic adds an editor specific build for the Android / XR editor which disables the Platform SDK logic.
1 parent bf42b28 commit bf0d491

File tree

7 files changed

+84
-49
lines changed

7 files changed

+84
-49
lines changed

.github/workflows/build-addon-on-push.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ jobs:
101101
scons platform=${{ matrix.platform }} target=template_debug ${{ matrix.flags }} custom_api_file=thirdparty/godot_cpp_gdextension_api/extension_api.json build_profile=thirdparty/godot_cpp_build_profile/build_profile.json
102102
scons platform=${{ matrix.platform }} target=template_release ${{ matrix.flags }} custom_api_file=thirdparty/godot_cpp_gdextension_api/extension_api.json build_profile=thirdparty/godot_cpp_build_profile/build_profile.json
103103
cd ..
104+
- name: Create Android editor extension library
105+
run: |
106+
cd godot_meta_toolkit
107+
scons platform=${{ matrix.platform }} target=editor ${{ matrix.flags }} custom_api_file=thirdparty/godot_cpp_gdextension_api/extension_api.json build_profile=thirdparty/godot_cpp_build_profile/build_profile.json
108+
cd ..
109+
if: matrix.platform == 'android'
104110
- name: Save Godot build cache
105111
uses: ./godot_meta_toolkit/thirdparty/godot-cpp/.github/actions/godot-cache-save
106112
with:

SConstruct

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ binary_path = '#demo/addons/godot_meta_toolkit/.bin'
4040
android_src_path = '#toolkit/src'
4141
project_name = 'godot_meta_toolkit'
4242

43-
if env['platform'] == "android":
43+
if env['platform'] == "android" and env["target"] != "editor":
4444
env.Append(LIBPATH=['thirdparty/ovr_platform_sdk/Android/libs/arm64-v8a'])
4545
env.Append(LIBS=['ovrplatformloader'])
4646

@@ -70,7 +70,18 @@ else:
7070

7171
Default(library)
7272

73-
if env["platform"] == "android":
73+
if env["platform"] == "android" and env["target"] != "editor":
74+
# Copy the libovrplatformloader.so files to the addon
75+
ovrplatformloader_copy_path = "#thirdparty/ovr_platform_sdk/Android/libs/arm64-v8a/libovrplatformloader.so"
76+
ovrplatformloader_copy_dest = "{}/{}/{}/{}/libovrplatformloader.so".format(
77+
binary_path,
78+
env["platform"],
79+
env["target"],
80+
env["arch"])
81+
ovrplatformloader_copy = env.Command(ovrplatformloader_copy_dest, ovrplatformloader_copy_path, Copy('$TARGET', '$SOURCE'))
82+
Default(ovrplatformloader_copy)
83+
84+
# Copy the libgodot_meta_toolkit.so files to the project libs directory
7485
android_target = "release" if env["target"] == "template_release" else "debug"
7586
android_arch = ""
7687
if env["arch"] == "arm64":

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ def createSconsTasks(File sconsExecutableFile, boolean clean) {
121121
executable sconsExecutableFile.absolutePath
122122
args defaultArgs + ["platform=android", "target=template_release", "arch=arm64"]
123123
}
124+
tasks.create(name: "${taskPrefix}GodotMetaToolkitAndroidArm64Editor", type: Exec) {
125+
executable sconsExecutableFile.absolutePath
126+
args defaultArgs + ["platform=android", "target=editor", "arch=arm64"]
127+
}
124128

125129
// Desktop.
126130
tasks.create(name: "${taskPrefix}GodotMetaToolkitDesktopDebug", type: Exec) {
@@ -154,6 +158,7 @@ task buildSconsArtifacts {
154158
// Android.
155159
dependsOn 'buildGodotMetaToolkitAndroidArm64Debug'
156160
dependsOn 'buildGodotMetaToolkitAndroidArm64Release'
161+
dependsOn 'buildGodotMetaToolkitAndroidArm64Editor'
157162

158163
// Desktop.
159164
dependsOn 'buildGodotMetaToolkitDesktopDebug'
@@ -182,6 +187,7 @@ task cleanScons {
182187
// Android.
183188
dependsOn 'cleanGodotMetaToolkitAndroidArm64Debug'
184189
dependsOn 'cleanGodotMetaToolkitAndroidArm64Release'
190+
dependsOn 'cleanGodotMetaToolkitAndroidArm64Editor'
185191

186192
// Desktop.
187193
dependsOn 'cleanGodotMetaToolkitDesktopDebug'

demo/addons/godot_meta_toolkit/toolkit.gdextension

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,23 @@ android_aar_plugin = true
66

77
[libraries]
88

9-
android.debug.arm64 = "res://addons/godot_meta_toolkit/.bin/android/template_debug/arm64/libgodot_meta_toolkit.so"
10-
android.release.arm64 = "res://addons/godot_meta_toolkit/.bin/android/template_release/arm64/libgodot_meta_toolkit.so"
9+
android.debug.template.arm64 = "res://addons/godot_meta_toolkit/.bin/android/template_debug/arm64/libgodot_meta_toolkit.so"
10+
android.release.template.arm64 = "res://addons/godot_meta_toolkit/.bin/android/template_release/arm64/libgodot_meta_toolkit.so"
11+
android.editor_runtime.arm64 = "res://addons/godot_meta_toolkit/.bin/android/template_debug/arm64/libgodot_meta_toolkit.so"
12+
android.editor_hint.arm64 = "res://addons/godot_meta_toolkit/.bin/android/editor/arm64/libgodot_meta_toolkit.so"
1113
macos.debug = "res://addons/godot_meta_toolkit/.bin/macos/template_debug/libgodot_meta_toolkit.macos.framework"
1214
macos.release = "res://addons/godot_meta_toolkit/.bin/macos/template_release/libgodot_meta_toolkit.macos.framework"
1315
windows.debug.x86_64 = "res://addons/godot_meta_toolkit/.bin/windows/template_debug/x86_64/libgodot_meta_toolkit.dll"
1416
windows.release.x86_64 = "res://addons/godot_meta_toolkit/.bin/windows/template_release/x86_64/libgodot_meta_toolkit.dll"
1517
linux.debug.x86_64 = "res://addons/godot_meta_toolkit/.bin/linux/template_debug/x86_64/libgodot_meta_toolkit.so"
1618
linux.release.x86_64 = "res://addons/godot_meta_toolkit/.bin/linux/template_release/x86_64/libgodot_meta_toolkit.so"
19+
20+
[dependencies]
21+
22+
android.debug.arm64 = {
23+
"res://addons/godot_meta_toolkit/.bin/android/template_debug/arm64/libovrplatformloader.so" : ""
24+
}
25+
26+
android.release.arm64 = {
27+
"res://addons/godot_meta_toolkit/.bin/android/template_release/arm64/libovrplatformloader.so" : ""
28+
}

generate_platform_sdk_bindings.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,17 +1042,17 @@ def generate_header(class_name, class_def, plan):
10421042
if class_name != 'MetaPlatformSDK':
10431043
lines.append('#include "platform_sdk/meta_platform_sdk.h"')
10441044
lines.append('')
1045-
lines.append('#ifdef ANDROID_ENABLED')
1045+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
10461046
for ovr_header in class_def['ovr_headers']:
10471047
lines.append(f'#include <{ovr_header}>')
1048-
lines.append('#endif // ANDROID_ENABLED')
1048+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
10491049
else:
10501050
lines.append('#include <godot_cpp/classes/ref.hpp>')
10511051
lines.append('#include <godot_cpp/templates/hash_map.hpp>')
10521052
lines.append('')
1053-
lines.append('#ifdef ANDROID_ENABLED')
1053+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
10541054
lines.append('#include <OVR_Types.h>')
1055-
lines.append('#endif // ANDROID_ENABLED')
1055+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
10561056
lines.append('')
10571057
lines.append('#include "platform_sdk/meta_platform_sdk_request.h"')
10581058
lines.append('')
@@ -1083,15 +1083,15 @@ def generate_header(class_name, class_def, plan):
10831083
if class_def['type'] == 'singleton':
10841084
lines.append(f'\tstatic {class_name} *singleton;')
10851085
lines.append('')
1086-
lines.append('#ifdef ANDROID_ENABLED')
1086+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
10871087
lines.append('\tbool _platform_initialized = false;')
10881088
lines.append('\tHashMap<ovrRequest, Ref<MetaPlatformSDK_Request>> requests;')
1089-
lines.append('#endif // ANDROID_ENABLED')
1089+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
10901090
lines.append('')
10911091
else:
1092-
lines.append('#ifdef ANDROID_ENABLED')
1092+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
10931093
lines.append(f'\t{class_def["ovr_handle"]} handle = nullptr;')
1094-
lines.append('#endif // ANDROID_ENABLED')
1094+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
10951095
lines.append('')
10961096
if class_name == 'MetaPlatformSDK_Message':
10971097
lines.append('\tMetaPlatformSDK::MessageType type = MetaPlatformSDK::MESSAGE_UNKNOWN;')
@@ -1129,20 +1129,20 @@ def generate_header(class_name, class_def, plan):
11291129
if class_name == 'MetaPlatformSDK':
11301130
lines.append(f'\tstatic void _register_generated_classes();')
11311131
lines.append('')
1132-
lines.append('#ifdef ANDROID_ENABLED')
1132+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
11331133
lines.append(f'\tvoid _initialize_platform();')
11341134
lines.append(f'\tvoid _initialize_platform_async(const Ref<MetaPlatformSDK_Message> &p_message);')
11351135
lines.append(f'\tRef<MetaPlatformSDK_Request> _create_request(ovrRequest p_request);')
11361136
lines.append(f'\tvoid _process_messages();')
1137-
lines.append('#endif // ANDROID_ENABLED')
1137+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
11381138
lines.append('')
11391139
lines.append(f'\tPlatformInitializeResult initialize_platform(const String &p_app_id, const Dictionary &p_options);')
11401140
lines.append(f'\tRef<MetaPlatformSDK_Request> initialize_platform_async(const String &p_app_id);')
11411141
else:
1142-
lines.append('#ifdef ANDROID_ENABLED')
1142+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
11431143
lines.append(f'\tstatic Ref<{class_name}> _create_with_ovr_handle({class_def["ovr_handle"]} p_handle);')
11441144
lines.append(f'\tinline {class_def["ovr_handle"]} _get_ovr_handle() {{ return handle; }}')
1145-
lines.append('#endif // ANDROID_ENABLED')
1145+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
11461146
lines.append('')
11471147
if class_name == 'MetaPlatformSDK_Message':
11481148
lines.append('\tinline MetaPlatformSDK::MessageType get_type() const { return type; }')
@@ -1203,10 +1203,10 @@ def generate_source(class_name, class_def, plan):
12031203

12041204
if class_name == 'MetaPlatformSDK':
12051205
lines.append('')
1206-
lines.append('#ifdef ANDROID_ENABLED')
1206+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
12071207
for ovr_header in class_def['ovr_headers']:
12081208
lines.append(f'#include <{ovr_header}>')
1209-
lines.append('#endif // ANDROID_ENABLED')
1209+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
12101210
lines.append('')
12111211

12121212
# Include all the other classes so we can register them.
@@ -1215,10 +1215,10 @@ def generate_source(class_name, class_def, plan):
12151215
continue
12161216
lines.append(f'#include "platform_sdk/{camel_to_snake_case(other_class_name)}.h"')
12171217
elif class_name == 'MetaPlatformSDK_Message':
1218-
lines.append('#ifdef ANDROID_ENABLED')
1218+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
12191219
# Needed for ovr_FreeMessage().
12201220
lines.append(f'#include <OVR_Platform.h>')
1221-
lines.append('#endif // ANDROID_ENABLED')
1221+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
12221222

12231223
lines.append('')
12241224

@@ -1338,7 +1338,7 @@ def generate_source(class_name, class_def, plan):
13381338
null_return_value = make_null_value(function['return'], plan)
13391339

13401340
lines.append(make_function_decl(function_name, function, class_name) + ' {')
1341-
lines.append('#ifdef ANDROID_ENABLED')
1341+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
13421342

13431343
# Check that we are initialized.
13441344
if class_def['ovr_handle']:
@@ -1405,7 +1405,7 @@ def generate_source(class_name, class_def, plan):
14051405
lines.append('#else')
14061406
lines.append(f'\treturn {null_return_value};')
14071407

1408-
lines.append('#endif // ANDROID_ENABLED')
1408+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14091409
lines.append('}')
14101410
lines.append('')
14111411

@@ -1416,15 +1416,15 @@ def generate_source(class_name, class_def, plan):
14161416
lines.append('');
14171417
lines.append('\tsingleton = this;')
14181418
elif class_def['type'] == 'model':
1419-
lines.append('#ifdef ANDROID_ENABLED')
1419+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14201420
lines.append(f"\thandle = {class_def['create_func']['name']}();")
1421-
lines.append('#endif // ANDROID_ENABLED')
1421+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14221422
lines.append('}')
14231423
lines.append('')
14241424

14251425
# Creation from handle.
14261426
if class_def['type'] == 'result':
1427-
lines.append('#ifdef ANDROID_ENABLED')
1427+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14281428
lines.append(f'Ref<{class_name}> {class_name}::_create_with_ovr_handle({class_def["ovr_handle"]} p_handle) {{')
14291429
lines.append(f'\tRef<{class_name}> inst;')
14301430
lines.append('\tif (p_handle != nullptr) {')
@@ -1435,23 +1435,23 @@ def generate_source(class_name, class_def, plan):
14351435
lines.append('\t}')
14361436
lines.append('\treturn inst;')
14371437
lines.append('}')
1438-
lines.append('#endif // ANDROID_ENABLED')
1438+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14391439
lines.append('')
14401440

14411441
# Destructor.
14421442
lines.append(f'{class_name}::~{class_name}() {{')
14431443
if class_def['type'] == 'singleton':
14441444
lines.append('\tsingleton = nullptr;')
14451445
elif class_def['type'] == 'model':
1446-
lines.append('#ifdef ANDROID_ENABLED')
1446+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14471447
lines.append(f"\t{class_def['destroy_func']['name']}(handle);")
1448-
lines.append('#endif // ANDROID_ENABLED')
1448+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14491449
elif class_def['type'] == 'result' and 'free_func' in class_def:
1450-
lines.append('#ifdef ANDROID_ENABLED')
1450+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14511451
lines.append('\tif (handle) {')
14521452
lines.append(f"\t\t{class_def['free_func']['name']}(handle);")
14531453
lines.append('\t}')
1454-
lines.append('#endif // ANDROID_ENABLED')
1454+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14551455
lines.append('}')
14561456
lines.append('')
14571457

@@ -1472,7 +1472,7 @@ def generate_source(class_name, class_def, plan):
14721472
#
14731473

14741474
lines.append('Variant MetaPlatformSDK_Message::get_data() const {')
1475-
lines.append('#ifdef ANDROID_ENABLED')
1475+
lines.append('#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
14761476
lines.append('\tERR_FAIL_COND_V(type == MetaPlatformSDK::MessageType::MESSAGE_UNKNOWN, Variant());')
14771477
lines.append('')
14781478
lines.append('\tif (data.get_type() != Variant::NIL) {')
@@ -1503,7 +1503,7 @@ def generate_source(class_name, class_def, plan):
15031503
lines.append('\treturn data;')
15041504
lines.append('#else')
15051505
lines.append('\treturn Variant();')
1506-
lines.append('#endif // ANDROID_ENABLED')
1506+
lines.append('#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)')
15071507
lines.append('}')
15081508
lines.append('')
15091509

toolkit/src/main/cpp/include/platform_sdk/meta_platform_sdk_request.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
#pragma once
44

5-
#ifdef ANDROID_ENABLED
5+
#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)
66
#include <OVR_Types.h>
7-
#endif // ANDROID_ENABLED
7+
#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)
88

99
#include <godot_cpp/classes/ref.hpp>
1010

@@ -15,20 +15,20 @@ class MetaPlatformSDK_Request : public RefCounted {
1515

1616
friend class MetaPlatformSDK;
1717

18-
#ifdef ANDROID_ENABLED
18+
#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)
1919
ovrRequest id = 0;
20-
#endif // ANDROID_ENABLED
20+
#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)
2121

2222
protected:
2323
static void _bind_methods();
2424

2525
public:
2626
inline uint64_t get_id() {
27-
#ifdef ANDROID_ENABLED
27+
#if defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)
2828
return id;
2929
#else
3030
return 0;
31-
#endif // ANDROID_ENABLED
31+
#endif // defined(ANDROID_ENABLED) && !defined(TOOLS_ENABLED)
3232
}
3333

3434
MetaPlatformSDK_Request();

0 commit comments

Comments
 (0)