Skip to content

Commit

Permalink
Allow for cross platform exporting of jre's
Browse files Browse the repository at this point in the history
  • Loading branch information
chippmann committed May 26, 2024
1 parent f956172 commit d51d4b9
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 37 deletions.
18 changes: 9 additions & 9 deletions harness/tests/export_presets.cfg
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[preset.0]

name="Windows Desktop"
name="Windows"
platform="Windows Desktop"
runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="*.txt, *.cfg"
exclude_filter=""
export_path="../tests-win64-export/Godot Kotlin Tests.exe"
export_path="./export/windows_export.exe"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false

[preset.0.options]

custom_template/debug=""
custom_template/release=""
custom_template/debug="../../../../bin/godot.windows.template_debug.x86_64.exe"
custom_template/release="../../../../bin/godot.windows.template_release.x86_64.exe"
debug/export_console_wrapper=1
binary_format/embed_pck=false
texture_format/bptc=false
Expand Down Expand Up @@ -270,15 +270,15 @@ xr_features/passthrough=0

[preset.2]

name="Linux/X11"
name="Linux"
platform="Linux/X11"
runnable=true
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter="*.txt, *.cfg"
exclude_filter=",res://godot_kotlin_configuration.json"
export_path="./Godot Kotlin Tests.x86_64"
exclude_filter=""
export_path="./export/linux_export.x86_64"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
Expand All @@ -287,7 +287,7 @@ encrypt_directory=false
[preset.2.options]

custom_template/debug="../../../../bin/godot.linuxbsd.template_debug.x86_64"
custom_template/release=""
custom_template/release="../../../../bin/godot.linuxbsd.template_release.x86_64"
debug/export_console_wrapper=1
binary_format/embed_pck=false
texture_format/bptc=false
Expand Down Expand Up @@ -393,7 +393,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=",res://godot_kotlin_configuration.json,res://godot_kotlin_configuration.json,res://godot_kotlin_configuration.json,res://godot_kotlin_configuration.json,res://godot_kotlin_configuration.json,res://godot_kotlin_configuration.json,res://godot_kotlin_configuration.json"
export_path="../../../../../../godot-kotlin-tests-macos-export/ios-export-java17.dmg"
export_path="./export/macos_export.dmg"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
Expand Down
4 changes: 2 additions & 2 deletions src/gd_kotlin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ bool GDKotlin::load_dynamic_lib() {

#ifdef TOOLS_ENABLED
String GDKotlin::get_path_to_embedded_jvm() {
String godot_path {String(RES_DIRECTORY).path_join(EMBEDDED_JRE_DIRECTORY).path_join(RELATIVE_JVM_LIB_PATH)};
String godot_path {String(RES_DIRECTORY).path_join(HOST_EMBEDDED_JRE_DIRECTORY).path_join(RELATIVE_JVM_LIB_PATH)};
return ProjectSettings::get_singleton()->globalize_path(godot_path);
}

Expand All @@ -347,7 +347,7 @@ String GDKotlin::get_path_to_embedded_jvm() {
#if defined(MACOS_ENABLED)
.path_join("../PlugIns/")
#endif
.path_join(EMBEDDED_JRE_DIRECTORY)
.path_join(HOST_EMBEDDED_JRE_DIRECTORY)
.path_join(RELATIVE_JVM_LIB_PATH);
}

Expand Down
46 changes: 40 additions & 6 deletions src/kotlin_editor_export_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,55 @@ void KotlinEditorExportPlugin::_export_begin(const HashSet<String>& p_features,
bool is_x64 {p_features.has("x86_64")};

if (!is_arm64 && !is_x64) {
add_macos_plugin_file(String(RES_DIRECTORY).path_join(EMBEDDED_JRE_DIRECTORY));
add_macos_plugin_file(String(RES_DIRECTORY).path_join(HOST_EMBEDDED_JRE_DIRECTORY));
} else {
if (is_arm64) { add_macos_plugin_file(String(RES_DIRECTORY).path_join(EMBEDDED_JRE_ARM_DIRECTORY)); }
if (is_x64) { add_macos_plugin_file(String(RES_DIRECTORY).path_join(EMBEDDED_JRE_AMD_DIRECTORY)); }
if (is_arm64) { add_macos_plugin_file(String(RES_DIRECTORY).path_join(MACOS_EMBEDDED_JRE_ARM_DIRECTORY)); }
if (is_x64) { add_macos_plugin_file(String(RES_DIRECTORY).path_join(MACOS_EMBEDDED_JRE_AMD_DIRECTORY)); }
}
} else {
String jre_dir {String(RES_DIRECTORY).path_join(EMBEDDED_JRE_AMD_DIRECTORY)};
String target_dir {ProjectSettings::get_singleton()->globalize_path(RES_DIRECTORY).path_join(p_path).get_base_dir().path_join(EMBEDDED_JRE_AMD_DIRECTORY)};
bool is_arm64 {p_features.has("arm64")};
bool is_x64 {p_features.has("x86_64")};

String jre_dir;
String target_dir;

if (!is_arm64 && !is_x64) {
jre_dir = String(RES_DIRECTORY).path_join(HOST_EMBEDDED_JRE_DIRECTORY);
target_dir = ProjectSettings::get_singleton()->globalize_path(RES_DIRECTORY).path_join(p_path).get_base_dir().path_join(HOST_EMBEDDED_JRE_DIRECTORY);
} else {
if (is_arm64) {
if (is_linux_export) {
jre_dir = String(RES_DIRECTORY).path_join(LINUX_EMBEDDED_JRE_ARM_DIRECTORY);
target_dir = ProjectSettings::get_singleton()->globalize_path(RES_DIRECTORY).path_join(p_path).get_base_dir().path_join(LINUX_EMBEDDED_JRE_ARM_DIRECTORY);
}
if (is_windows_export) {
jre_dir = String(RES_DIRECTORY).path_join(WINDOWS_EMBEDDED_JRE_ARM_DIRECTORY);
target_dir = ProjectSettings::get_singleton()->globalize_path(RES_DIRECTORY).path_join(p_path).get_base_dir().path_join(WINDOWS_EMBEDDED_JRE_ARM_DIRECTORY);
}
}
if (is_x64) {
if (is_linux_export) {
jre_dir = String(RES_DIRECTORY).path_join(LINUX_EMBEDDED_JRE_AMD_DIRECTORY);
target_dir = ProjectSettings::get_singleton()->globalize_path(RES_DIRECTORY).path_join(p_path).get_base_dir().path_join(LINUX_EMBEDDED_JRE_AMD_DIRECTORY);
}
if (is_windows_export) {
jre_dir = String(RES_DIRECTORY).path_join(WINDOWS_EMBEDDED_JRE_AMD_DIRECTORY);
target_dir = ProjectSettings::get_singleton()->globalize_path(RES_DIRECTORY).path_join(p_path).get_base_dir().path_join(WINDOWS_EMBEDDED_JRE_AMD_DIRECTORY);
}
}
}

if(jre_dir.is_empty() || target_dir.is_empty()) {
LOG_ERROR("Could not find a jre directory for the current export configuration");
}

Error error;
Ref<DirAccess> dir_access {DirAccess::open(jre_dir, &error)};
if (error != OK) {
LOG_ERROR(vformat("Cannot open directory %s", jre_dir));
}
if (dir_access->copy_dir(jre_dir, target_dir) != OK) {
LOG_ERROR(vformat("Cannot copy %s folder to export folder, please make sure you created a JRE directory at the root of your project using jlink.", EMBEDDED_JRE_AMD_DIRECTORY)
LOG_ERROR(vformat("Cannot copy %s folder to export folder, please make sure you created a JRE directory at the root of your project using jlink for the platform you want to export.", jre_dir)
);
}
}
Expand Down
51 changes: 31 additions & 20 deletions src/lifecycle/paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,37 @@ static constexpr const char* IOS_BOOTSTRAP_FILE {""};
static constexpr const char* IOS_USER_CODE_FILE {""};
static constexpr const char* IOS_GRAAL_NATIVE_IMAGE_FILE {"usercode.a"};

static constexpr const char* LINUX_EMBEDDED_JRE_ARM_DIRECTORY {"jre-arm64-linux"};
static constexpr const char* LINUX_EMBEDDED_JRE_AMD_DIRECTORY {"jre-amd64-linux"};

static constexpr const char* WINDOWS_EMBEDDED_JRE_ARM_DIRECTORY {"jre-arm64-windows"};
static constexpr const char* WINDOWS_EMBEDDED_JRE_AMD_DIRECTORY {"jre-amd64-windows"};

static constexpr const char* MACOS_EMBEDDED_JRE_ARM_DIRECTORY {"jre-arm64-macos"};
static constexpr const char* MACOS_EMBEDDED_JRE_AMD_DIRECTORY {"jre-amd64-macos"};

#ifdef X11_ENABLED
#ifdef __arm64__
static constexpr const char* HOST_EMBEDDED_JRE_DIRECTORY {LINUX_EMBEDDED_JRE_ARM_DIRECTORY};
#else
static constexpr const char* HOST_EMBEDDED_JRE_DIRECTORY {LINUX_EMBEDDED_JRE_AMD_DIRECTORY};
#endif

#elif WINDOWS_ENABLED
#ifdef __arm64__
static constexpr const char* HOST_EMBEDDED_JRE_DIRECTORY {WINDOWS_EMBEDDED_JRE_ARM_DIRECTORY};
#else
static constexpr const char* HOST_EMBEDDED_JRE_DIRECTORY {WINDOWS_EMBEDDED_JRE_AMD_DIRECTORY};
#endif

#elif MACOS_ENABLED
#ifdef __arm64__
static constexpr const char* HOST_EMBEDDED_JRE_DIRECTORY {MACOS_EMBEDDED_JRE_ARM_DIRECTORY};
#else
static constexpr const char* HOST_EMBEDDED_JRE_DIRECTORY {MACOS_EMBEDDED_JRE_AMD_DIRECTORY};
#endif
#endif

#ifdef X11_ENABLED

static constexpr const char* RELATIVE_JVM_LIB_PATH {LINUX_RELATIVE_JVM_LIB_PATH};
Expand Down Expand Up @@ -65,26 +96,6 @@ static constexpr const char* GRAAL_NATIVE_IMAGE_FILE {IOS_GRAAL_NATIVE_IMAGE_FIL

#endif

#ifdef X11_ENABLED
static constexpr const char* EMBEDDED_JRE_ARM_DIRECTORY {"jre-arm64-linux"};
static constexpr const char* EMBEDDED_JRE_AMD_DIRECTORY {"jre-amd64-linux"};
#elif WINDOWS_ENABLED
static constexpr const char* EMBEDDED_JRE_ARM_DIRECTORY {"jre-arm64-windows"};
static constexpr const char* EMBEDDED_JRE_AMD_DIRECTORY {"jre-amd64-windows"};
#elif OSX_ENABLED
static constexpr const char* EMBEDDED_JRE_ARM_DIRECTORY {"jre-arm64-macos"};
static constexpr const char* EMBEDDED_JRE_AMD_DIRECTORY {"jre-amd64-macos"};
#else
static constexpr const char* EMBEDDED_JRE_ARM_DIRECTORY {"jre-arm64"};
static constexpr const char* EMBEDDED_JRE_AMD_DIRECTORY {"jre-amd64"};
#endif

#ifdef __arm64__
static constexpr const char* EMBEDDED_JRE_DIRECTORY {EMBEDDED_JRE_ARM_DIRECTORY};
#else
static constexpr const char* EMBEDDED_JRE_DIRECTORY {EMBEDDED_JRE_AMD_DIRECTORY};
#endif

static constexpr const char* ENTRY_DIRECTORY {"res://build/generated/ksp"};
static constexpr const char* BUILD_DIRECTORY {"res://build/libs/"};
static constexpr const char* USER_DIRECTORY {"user://"};
Expand Down

0 comments on commit d51d4b9

Please sign in to comment.