diff options
Diffstat (limited to 'platform/ios')
| -rw-r--r-- | platform/ios/detect.py | 2 | ||||
| -rw-r--r-- | platform/ios/display_server_ios.h | 14 | ||||
| -rw-r--r-- | platform/ios/display_server_ios.mm | 88 | ||||
| -rw-r--r-- | platform/ios/export/export_plugin.cpp | 345 | ||||
| -rw-r--r-- | platform/ios/export/export_plugin.h | 4 | ||||
| -rw-r--r-- | platform/ios/os_ios.h | 6 | ||||
| -rw-r--r-- | platform/ios/os_ios.mm | 17 | ||||
| -rw-r--r-- | platform/ios/vulkan_context_ios.h | 7 | ||||
| -rw-r--r-- | platform/ios/vulkan_context_ios.mm | 15 |
9 files changed, 345 insertions, 153 deletions
diff --git a/platform/ios/detect.py b/platform/ios/detect.py index 26d81c8ed6..23f688501b 100644 --- a/platform/ios/detect.py +++ b/platform/ios/detect.py @@ -152,7 +152,7 @@ def configure(env: "Environment"): env.Append(CPPDEFINES=["IOS_ENABLED", "UNIX_ENABLED", "COREAUDIO_ENABLED"]) if env["vulkan"]: - env.Append(CPPDEFINES=["VULKAN_ENABLED"]) + env.Append(CPPDEFINES=["VULKAN_ENABLED", "RD_ENABLED"]) if env["opengl3"]: env.Append(CPPDEFINES=["GLES3_ENABLED", "GLES_SILENCE_DEPRECATION"]) diff --git a/platform/ios/display_server_ios.h b/platform/ios/display_server_ios.h index be4ea1e6ab..3d19222fa8 100644 --- a/platform/ios/display_server_ios.h +++ b/platform/ios/display_server_ios.h @@ -34,18 +34,20 @@ #include "core/input/input.h" #include "servers/display_server.h" +#if defined(RD_ENABLED) +#include "servers/rendering/renderer_rd/renderer_compositor_rd.h" +#include "servers/rendering/rendering_device.h" + #if defined(VULKAN_ENABLED) #import "vulkan_context_ios.h" -#include "drivers/vulkan/rendering_device_vulkan.h" -#include "servers/rendering/renderer_rd/renderer_compositor_rd.h" - #ifdef USE_VOLK #include <volk.h> #else #include <vulkan/vulkan.h> #endif #endif // VULKAN_ENABLED +#endif // RD_ENABLED #if defined(GLES3_ENABLED) #include "drivers/gles3/rasterizer_gles3.h" @@ -59,9 +61,9 @@ class DisplayServerIOS : public DisplayServer { _THREAD_SAFE_CLASS_ -#if defined(VULKAN_ENABLED) - VulkanContextIOS *context_vulkan = nullptr; - RenderingDeviceVulkan *rendering_device_vulkan = nullptr; +#if defined(RD_ENABLED) + ApiContextRD *context_rd = nullptr; + RenderingDevice *rendering_device = nullptr; #endif id tts = nullptr; diff --git a/platform/ios/display_server_ios.mm b/platform/ios/display_server_ios.mm index 2561c1c095..c31f503605 100644 --- a/platform/ios/display_server_ios.mm +++ b/platform/ios/display_server_ios.mm @@ -62,34 +62,46 @@ DisplayServerIOS::DisplayServerIOS(const String &p_rendering_driver, WindowMode tts = [[TTS_IOS alloc] init]; } -#if defined(VULKAN_ENABLED) - context_vulkan = nullptr; - rendering_device_vulkan = nullptr; +#if defined(RD_ENABLED) + context_rd = nullptr; + rendering_device = nullptr; - if (rendering_driver == "vulkan") { - context_vulkan = memnew(VulkanContextIOS); - if (context_vulkan->initialize() != OK) { - memdelete(context_vulkan); - context_vulkan = nullptr; - ERR_FAIL_MSG("Failed to initialize Vulkan context"); - } + CALayer *layer = nullptr; - CALayer *layer = [AppDelegate.viewController.godotView initializeRenderingForDriver:@"vulkan"]; + union { +#ifdef VULKAN_ENABLED + VulkanContextIOS::WindowPlatformData vulkan; +#endif + } wpd; +#if defined(VULKAN_ENABLED) + if (rendering_driver == "vulkan") { + layer = [AppDelegate.viewController.godotView initializeRenderingForDriver:@"vulkan"]; if (!layer) { ERR_FAIL_MSG("Failed to create iOS Vulkan rendering layer."); } + wpd.vulkan.layer_ptr = &layer; + context_rd = memnew(VulkanContextIOS); + } +#endif + + if (context_rd) { + if (context_rd->initialize() != OK) { + memdelete(context_rd); + context_rd = nullptr; + ERR_FAIL_MSG(vformat("Failed to initialize %s context", context_rd->get_api_name())); + } Size2i size = Size2i(layer.bounds.size.width, layer.bounds.size.height) * screen_get_max_scale(); - if (context_vulkan->window_create(MAIN_WINDOW_ID, p_vsync_mode, layer, size.width, size.height) != OK) { - memdelete(context_vulkan); - context_vulkan = nullptr; + if (context_rd->window_create(MAIN_WINDOW_ID, p_vsync_mode, size.width, size.height, &wpd) != OK) { + memdelete(context_rd); + context_rd = nullptr; r_error = ERR_UNAVAILABLE; - ERR_FAIL_MSG("Failed to create Vulkan window."); + ERR_FAIL_MSG(vformat("Failed to create %s window.", context_rd->get_api_name())); } - rendering_device_vulkan = memnew(RenderingDeviceVulkan); - rendering_device_vulkan->initialize(context_vulkan); + rendering_device = memnew(RenderingDevice); + rendering_device->initialize(context_rd); RendererCompositorRD::make_current(); } @@ -116,17 +128,17 @@ DisplayServerIOS::DisplayServerIOS(const String &p_rendering_driver, WindowMode } DisplayServerIOS::~DisplayServerIOS() { -#if defined(VULKAN_ENABLED) - if (rendering_device_vulkan) { - rendering_device_vulkan->finalize(); - memdelete(rendering_device_vulkan); - rendering_device_vulkan = nullptr; +#if defined(RD_ENABLED) + if (rendering_device) { + rendering_device->finalize(); + memdelete(rendering_device); + rendering_device = nullptr; } - if (context_vulkan) { - context_vulkan->window_destroy(MAIN_WINDOW_ID); - memdelete(context_vulkan); - context_vulkan = nullptr; + if (context_rd) { + context_rd->window_destroy(MAIN_WINDOW_ID); + memdelete(context_rd); + context_rd = nullptr; } #endif } @@ -443,7 +455,11 @@ int DisplayServerIOS::screen_get_dpi(int p_screen) const { } float DisplayServerIOS::screen_get_refresh_rate(int p_screen) const { - return [UIScreen mainScreen].maximumFramesPerSecond; + float fps = [UIScreen mainScreen].maximumFramesPerSecond; + if ([NSProcessInfo processInfo].lowPowerModeEnabled) { + fps = 60; + } + return fps; } float DisplayServerIOS::screen_get_scale(int p_screen) const { @@ -693,9 +709,9 @@ bool DisplayServerIOS::screen_is_kept_on() const { void DisplayServerIOS::resize_window(CGSize viewSize) { Size2i size = Size2i(viewSize.width, viewSize.height) * screen_get_max_scale(); -#if defined(VULKAN_ENABLED) - if (context_vulkan) { - context_vulkan->window_resize(MAIN_WINDOW_ID, size.x, size.y); +#if defined(RD_ENABLED) + if (context_rd) { + context_rd->window_resize(MAIN_WINDOW_ID, size.x, size.y); } #endif @@ -705,18 +721,18 @@ void DisplayServerIOS::resize_window(CGSize viewSize) { void DisplayServerIOS::window_set_vsync_mode(DisplayServer::VSyncMode p_vsync_mode, WindowID p_window) { _THREAD_SAFE_METHOD_ -#if defined(VULKAN_ENABLED) - if (context_vulkan) { - context_vulkan->set_vsync_mode(p_window, p_vsync_mode); +#if defined(RD_ENABLED) + if (context_rd) { + context_rd->set_vsync_mode(p_window, p_vsync_mode); } #endif } DisplayServer::VSyncMode DisplayServerIOS::window_get_vsync_mode(WindowID p_window) const { _THREAD_SAFE_METHOD_ -#if defined(VULKAN_ENABLED) - if (context_vulkan) { - return context_vulkan->get_vsync_mode(p_window); +#if defined(RD_ENABLED) + if (context_rd) { + return context_rd->get_vsync_mode(p_window); } #endif return DisplayServer::VSYNC_ENABLED; diff --git a/platform/ios/export/export_plugin.cpp b/platform/ios/export/export_plugin.cpp index 3cae85ea55..b478759e45 100644 --- a/platform/ios/export/export_plugin.cpp +++ b/platform/ios/export/export_plugin.cpp @@ -620,7 +620,10 @@ Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_pr String sizes; Ref<DirAccess> da = DirAccess::open(p_iconset_dir); - ERR_FAIL_COND_V_MSG(da.is_null(), ERR_CANT_OPEN, "Cannot open directory '" + p_iconset_dir + "'."); + if (da.is_null()) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not open a directory at path \"%s\"."), p_iconset_dir)); + return ERR_CANT_OPEN; + } Color boot_bg_color = GLOBAL_GET("application/boot_splash/bg_color"); @@ -692,12 +695,20 @@ Error EditorExportPlatformIOS::_export_icons(const Ref<EditorExportPreset> &p_pr json_description += "]}"; Ref<FileAccess> json_file = FileAccess::open(p_iconset_dir + "Contents.json", FileAccess::WRITE); - ERR_FAIL_COND_V(json_file.is_null(), ERR_CANT_CREATE); + if (json_file.is_null()) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "Contents.json")); + return ERR_CANT_CREATE; + } + CharString json_utf8 = json_description.utf8(); json_file->store_buffer((const uint8_t *)json_utf8.get_data(), json_utf8.length()); Ref<FileAccess> sizes_file = FileAccess::open(p_iconset_dir + "sizes", FileAccess::WRITE); - ERR_FAIL_COND_V(sizes_file.is_null(), ERR_CANT_CREATE); + if (sizes_file.is_null()) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Export Icons"), vformat(TTR("Could not write to a file at path \"%s\"."), p_iconset_dir + "sizes")); + return ERR_CANT_CREATE; + } + CharString sizes_utf8 = sizes.utf8(); sizes_file->store_buffer((const uint8_t *)sizes_utf8.get_data(), sizes_utf8.length()); @@ -882,8 +893,7 @@ Error EditorExportPlatformIOS::_walk_dir_recursive(Ref<DirAccess> &p_da, FileHan p_da->list_dir_end(); for (int i = 0; i < dirs.size(); ++i) { - String dir = dirs[i]; - p_da->change_dir(dir); + p_da->change_dir(dirs[i]); Error err = _walk_dir_recursive(p_da, p_handler, p_userdata); p_da->change_dir(".."); if (err) { @@ -1077,14 +1087,15 @@ Error EditorExportPlatformIOS::_copy_asset(const String &p_out_dir, const String return ERR_FILE_NOT_FOUND; } - String base_dir = p_asset.get_base_dir().replace("res://", ""); + String base_dir = p_asset.get_base_dir().replace("res://", "").replace(".godot/mono/temp/bin/", ""); + String asset = p_asset.ends_with("/") ? p_asset.left(p_asset.length() - 1) : p_asset; String destination_dir; String destination; String asset_path; bool create_framework = false; - if (p_is_framework && p_asset.ends_with(".dylib")) { + if (p_is_framework && asset.ends_with(".dylib")) { // For iOS we need to turn .dylib into .framework // to be able to send application to AppStore asset_path = String("dylibs").path_join(base_dir); @@ -1103,7 +1114,7 @@ Error EditorExportPlatformIOS::_copy_asset(const String &p_out_dir, const String destination_dir = p_out_dir.path_join(asset_path); destination = destination_dir.path_join(file_name); create_framework = true; - } else if (p_is_framework && (p_asset.ends_with(".framework") || p_asset.ends_with(".xcframework"))) { + } else if (p_is_framework && (asset.ends_with(".framework") || asset.ends_with(".xcframework"))) { asset_path = String("dylibs").path_join(base_dir); String file_name; @@ -1147,6 +1158,9 @@ Error EditorExportPlatformIOS::_copy_asset(const String &p_out_dir, const String if (err) { return err; } + if (asset_path.ends_with("/")) { + asset_path = asset_path.left(asset_path.length() - 1); + } IOSExportAsset exported_asset = { binary_name.path_join(asset_path), p_is_framework, p_should_embed }; r_exported_assets.push_back(exported_asset); @@ -1213,13 +1227,16 @@ Error EditorExportPlatformIOS::_copy_asset(const String &p_out_dir, const String Error EditorExportPlatformIOS::_export_additional_assets(const String &p_out_dir, const Vector<String> &p_assets, bool p_is_framework, bool p_should_embed, Vector<IOSExportAsset> &r_exported_assets) { for (int f_idx = 0; f_idx < p_assets.size(); ++f_idx) { String asset = p_assets[f_idx]; - if (!asset.begins_with("res://")) { + if (asset.begins_with("res://")) { + Error err = _copy_asset(p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets); + ERR_FAIL_COND_V(err != OK, err); + } else if (ProjectSettings::get_singleton()->localize_path(asset).begins_with("res://")) { + Error err = _copy_asset(p_out_dir, ProjectSettings::get_singleton()->localize_path(asset), nullptr, p_is_framework, p_should_embed, r_exported_assets); + ERR_FAIL_COND_V(err != OK, err); + } else { // either SDK-builtin or already a part of the export template IOSExportAsset exported_asset = { asset, p_is_framework, p_should_embed }; r_exported_assets.push_back(exported_asset); - } else { - Error err = _copy_asset(p_out_dir, asset, nullptr, p_is_framework, p_should_embed, r_exported_assets); - ERR_FAIL_COND_V(err, err); } } @@ -1299,8 +1316,7 @@ Error EditorExportPlatformIOS::_export_ios_plugins(const Ref<EditorExportPreset> // We shouldn't embed .xcframework that contains static libraries. // Static libraries are not embedded anyway. err = _copy_asset(dest_dir, plugin_main_binary, &plugin_binary_result_file, true, false, r_exported_assets); - - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V(err != OK, err); // Adding dependencies. // Use separate container for names to check for duplicates. @@ -1425,15 +1441,15 @@ Error EditorExportPlatformIOS::_export_ios_plugins(const Ref<EditorExportPreset> { // Export linked plugin dependency err = _export_additional_assets(dest_dir, plugin_linked_dependencies, true, false, r_exported_assets); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V(err != OK, err); // Export embedded plugin dependency err = _export_additional_assets(dest_dir, plugin_embedded_dependencies, true, true, r_exported_assets); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V(err != OK, err); // Export plugin files err = _export_additional_assets(dest_dir, plugin_files, false, false, r_exported_assets); - ERR_FAIL_COND_V(err, err); + ERR_FAIL_COND_V(err != OK, err); } // Update CPP @@ -1486,20 +1502,29 @@ Error EditorExportPlatformIOS::export_project(const Ref<EditorExportPreset> &p_p return _export_project_helper(p_preset, p_debug, p_path, p_flags, false, false); } -Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags, bool p_simulator, bool p_skip_ipa) { +Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags, bool p_simulator, bool p_oneclick) { ExportNotifier notifier(*this, p_preset, p_debug, p_path, p_flags); - String src_pkg_name; - String dest_dir = p_path.get_base_dir() + "/"; - String binary_name = p_path.get_file().get_basename(); + const String dest_dir = p_path.get_base_dir() + "/"; + const String binary_name = p_path.get_file().get_basename(); + const String binary_dir = dest_dir + binary_name; + + if (!DirAccess::exists(dest_dir)) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Target folder does not exist or is inaccessible: \"%s\""), dest_dir)); + return ERR_FILE_BAD_PATH; + } bool export_project_only = p_preset->get("application/export_project_only"); + if (p_oneclick) { + export_project_only = false; // Skip for one-click deploy. + } EditorProgress ep("export", export_project_only ? TTR("Exporting for iOS (Project Files Only)") : TTR("Exporting for iOS"), export_project_only ? 2 : 5, true); String team_id = p_preset->get("application/app_store_team_id"); ERR_FAIL_COND_V_MSG(team_id.length() == 0, ERR_CANT_OPEN, "App Store Team ID not specified - cannot configure the project."); + String src_pkg_name; if (p_debug) { src_pkg_name = p_preset->get("custom_template/debug"); } else { @@ -1515,10 +1540,6 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres } } - if (!DirAccess::exists(dest_dir)) { - return ERR_FILE_BAD_PATH; - } - { Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); if (da.is_valid()) { @@ -1526,18 +1547,19 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres // remove leftovers from last export so they don't interfere // in case some files are no longer needed - if (da->change_dir(dest_dir + binary_name + ".xcodeproj") == OK) { + if (da->change_dir(binary_dir + ".xcodeproj") == OK) { da->erase_contents_recursive(); } - if (da->change_dir(dest_dir + binary_name) == OK) { + if (da->change_dir(binary_dir) == OK) { da->erase_contents_recursive(); } da->change_dir(current_dir); - if (!da->dir_exists(dest_dir + binary_name)) { - Error err = da->make_dir(dest_dir + binary_name); - if (err) { + if (!da->dir_exists(binary_dir)) { + Error err = da->make_dir(binary_dir); + if (err != OK) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Failed to create the directory: \"%s\""), binary_dir)); return err; } } @@ -1547,10 +1569,11 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres if (ep.step("Making .pck", 0)) { return ERR_SKIP; } - String pack_path = dest_dir + binary_name + ".pck"; + String pack_path = binary_dir + ".pck"; Vector<SharedObject> libraries; Error err = save_pack(p_preset, p_debug, pack_path, &libraries); if (err) { + // Message is supplied by the subroutine method. return err; } @@ -1599,7 +1622,10 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres Vector<IOSExportAsset> assets; Ref<DirAccess> tmp_app_path = DirAccess::create_for_path(dest_dir); - ERR_FAIL_COND_V(tmp_app_path.is_null(), ERR_CANT_CREATE); + if (tmp_app_path.is_null()) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Prepare Templates"), vformat(TTR("Could not create and open the directory: \"%s\""), dest_dir)); + return ERR_CANT_CREATE; + } print_line("Unzipping..."); Ref<FileAccess> io_fa; @@ -1610,8 +1636,14 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres return ERR_CANT_OPEN; } - err = _export_ios_plugins(p_preset, config_data, dest_dir + binary_name, assets, p_debug); - ERR_FAIL_COND_V(err, err); + err = _export_ios_plugins(p_preset, config_data, binary_dir, assets, p_debug); + if (err != OK) { + // TODO: Improve error reporting by using `add_message` throughout all methods called via `_export_ios_plugins`. + // For now a generic top level message would be fine, but we're ought to use proper reporting here instead of + // just fail macros and non-descriptive error return values. + add_message(EXPORT_MESSAGE_ERROR, TTR("iOS Plugins"), vformat(TTR("Failed to export iOS plugins with code %d. Please check the output log."), err)); + return err; + } //export rest of the files int ret = unzGoToFirstFile(src_pkg_zip); @@ -1676,8 +1708,8 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres print_line("Creating " + dir_name); Error dir_err = tmp_app_path->make_dir_recursive(dir_name); if (dir_err) { - ERR_PRINT("Can't create '" + dir_name + "'."); unzClose(src_pkg_zip); + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create a directory at path \"%s\"."), dir_name)); return ERR_CANT_CREATE; } } @@ -1686,8 +1718,8 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres { Ref<FileAccess> f = FileAccess::open(file, FileAccess::WRITE); if (f.is_null()) { - ERR_PRINT("Can't write '" + file + "'."); unzClose(src_pkg_zip); + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write to a file at path \"%s\"."), file)); return ERR_CANT_CREATE; }; f->store_buffer(data.ptr(), data.size()); @@ -1708,7 +1740,7 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres unzClose(src_pkg_zip); if (!found_library) { - ERR_PRINT("Requested template library '" + library_to_use + "' not found. It might be missing from your template archive."); + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Requested template library '%s' not found. It might be missing from your template archive."), library_to_use)); return ERR_FILE_NOT_FOUND; } @@ -1720,7 +1752,7 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres Vector<String> translations = GLOBAL_GET("internationalization/locale/translations"); if (translations.size() > 0) { { - String fname = dest_dir + binary_name + "/en.lproj"; + String fname = binary_dir + "/en.lproj"; tmp_app_path->make_dir_recursive(fname); Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE); f->store_line("/* Localized versions of Info.plist keys */"); @@ -1740,7 +1772,7 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres } for (const String &lang : languages) { - String fname = dest_dir + binary_name + "/" + lang + ".lproj"; + String fname = binary_dir + "/" + lang + ".lproj"; tmp_app_path->make_dir_recursive(fname); Ref<FileAccess> f = FileAccess::open(fname + "/InfoPlist.strings", FileAccess::WRITE); f->store_line("/* Localized versions of Info.plist keys */"); @@ -1769,34 +1801,37 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres String dest_lib_file_path = dest_dir + static_lib_path.get_file(); Error lib_copy_err = tmp_app_path->copy(static_lib_path, dest_lib_file_path); if (lib_copy_err != OK) { - ERR_PRINT("Can't copy '" + static_lib_path + "'."); + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not copy a file at path \"%s\" to \"%s\"."), static_lib_path, dest_lib_file_path)); return lib_copy_err; } } } - String iconset_dir = dest_dir + binary_name + "/Images.xcassets/AppIcon.appiconset/"; + String iconset_dir = binary_dir + "/Images.xcassets/AppIcon.appiconset/"; err = OK; if (!tmp_app_path->dir_exists(iconset_dir)) { err = tmp_app_path->make_dir_recursive(iconset_dir); } - if (err) { + if (err != OK) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not create a directory at path \"%s\"."), iconset_dir)); return err; } err = _export_icons(p_preset, iconset_dir); - if (err) { + if (err != OK) { + // Message is supplied by the subroutine method. return err; } { bool use_storyboard = p_preset->get("storyboard/use_launch_screen_storyboard"); - String launch_image_path = dest_dir + binary_name + "/Images.xcassets/LaunchImage.launchimage/"; - String splash_image_path = dest_dir + binary_name + "/Images.xcassets/SplashImage.imageset/"; + String launch_image_path = binary_dir + "/Images.xcassets/LaunchImage.launchimage/"; + String splash_image_path = binary_dir + "/Images.xcassets/SplashImage.imageset/"; Ref<DirAccess> launch_screen_da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); if (launch_screen_da.is_null()) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), TTR("Could not access the filesystem.")); return ERR_CANT_CREATE; } @@ -1809,10 +1844,11 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres } err = _export_loading_screen_file(p_preset, splash_image_path); + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Failed to create a file at path \"%s\" with code %d."), splash_image_path, err)); } else { print_line("Using Launch Images"); - const String launch_screen_path = dest_dir + binary_name + "/Launch Screen.storyboard"; + const String launch_screen_path = binary_dir + "/Launch Screen.storyboard"; launch_screen_da->remove(launch_screen_path); @@ -1822,21 +1858,22 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres } err = _export_loading_screen_images(p_preset, launch_image_path); + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Failed to create a file at path \"%s\" with code %d."), launch_image_path, err)); } } - if (err) { + if (err != OK) { return err; } print_line("Exporting additional assets"); - _export_additional_assets(dest_dir + binary_name, libraries, assets); + _export_additional_assets(binary_dir, libraries, assets); _add_assets_to_project(p_preset, project_file_data, assets); - String project_file_name = dest_dir + binary_name + ".xcodeproj/project.pbxproj"; + String project_file_name = binary_dir + ".xcodeproj/project.pbxproj"; { Ref<FileAccess> f = FileAccess::open(project_file_name, FileAccess::WRITE); if (f.is_null()) { - ERR_PRINT("Can't write '" + project_file_name + "'."); + add_message(EXPORT_MESSAGE_ERROR, TTR("Export"), vformat(TTR("Could not write to a file at path \"%s\"."), project_file_name)); return ERR_CANT_CREATE; }; f->store_buffer(project_file_data.ptr(), project_file_data.size()); @@ -1847,7 +1884,7 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres if (ep.step("Code-signing dylibs", 2)) { return ERR_SKIP; } - Ref<DirAccess> dylibs_dir = DirAccess::open(dest_dir + binary_name + "/dylibs"); + Ref<DirAccess> dylibs_dir = DirAccess::open(binary_dir + "/dylibs"); ERR_FAIL_COND_V(dylibs_dir.is_null(), ERR_CANT_OPEN); CodesignData codesign_data(p_preset, p_debug); err = _walk_dir_recursive(dylibs_dir, _codesign, &codesign_data); @@ -1864,10 +1901,11 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres if (ep.step("Making .xcarchive", 3)) { return ERR_SKIP; } + String archive_path = p_path.get_basename() + ".xcarchive"; List<String> archive_args; archive_args.push_back("-project"); - archive_args.push_back(dest_dir + binary_name + ".xcodeproj"); + archive_args.push_back(binary_dir + ".xcodeproj"); archive_args.push_back("-scheme"); archive_args.push_back(binary_name); archive_args.push_back("-sdk"); @@ -1888,31 +1926,42 @@ Error EditorExportPlatformIOS::_export_project_helper(const Ref<EditorExportPres archive_args.push_back("-allowProvisioningUpdates"); archive_args.push_back("-archivePath"); archive_args.push_back(archive_path); + String archive_str; err = OS::get_singleton()->execute("xcodebuild", archive_args, &archive_str, nullptr, true); - ERR_FAIL_COND_V(err, err); + if (err != OK) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), vformat(TTR("Failed to run xcodebuild with code %d"), err)); + return err; + } + print_line("xcodebuild (.xcarchive):\n" + archive_str); if (!archive_str.contains("** ARCHIVE SUCCEEDED **")) { add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR("Xcode project build failed, see editor log for details.")); return FAILED; } - if (!p_skip_ipa) { + if (!p_oneclick) { if (ep.step("Making .ipa", 4)) { return ERR_SKIP; } + List<String> export_args; export_args.push_back("-exportArchive"); export_args.push_back("-archivePath"); export_args.push_back(archive_path); export_args.push_back("-exportOptionsPlist"); - export_args.push_back(dest_dir + binary_name + "/export_options.plist"); + export_args.push_back(binary_dir + "/export_options.plist"); export_args.push_back("-allowProvisioningUpdates"); export_args.push_back("-exportPath"); export_args.push_back(dest_dir); + String export_str; err = OS::get_singleton()->execute("xcodebuild", export_args, &export_str, nullptr, true); - ERR_FAIL_COND_V(err, err); + if (err != OK) { + add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), vformat(TTR("Failed to run xcodebuild with code %d"), err)); + return err; + } + print_line("xcodebuild (.ipa):\n" + export_str); if (!export_str.contains("** EXPORT SUCCEEDED **")) { add_message(EXPORT_MESSAGE_ERROR, TTR("Xcode Build"), TTR(".ipa export failed, see editor log for details.")); @@ -2064,6 +2113,28 @@ bool EditorExportPlatformIOS::is_package_name_valid(const String &p_package, Str } #ifdef MACOS_ENABLED +bool EditorExportPlatformIOS::_check_xcode_install() { + static bool xcode_found = false; + if (!xcode_found) { + Vector<String> mdfind_paths; + List<String> mdfind_args; + mdfind_args.push_back("kMDItemCFBundleIdentifier=com.apple.dt.Xcode"); + + String output; + Error err = OS::get_singleton()->execute("mdfind", mdfind_args, &output); + if (err == OK) { + mdfind_paths = output.split("\n"); + } + for (const String &found_path : mdfind_paths) { + xcode_found = !found_path.is_empty() && DirAccess::dir_exists_absolute(found_path.strip_edges()); + if (xcode_found) { + break; + } + } + } + return xcode_found; +} + void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) { EditorExportPlatformIOS *ea = static_cast<EditorExportPlatformIOS *>(ud); @@ -2089,12 +2160,9 @@ void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) { // Check for devices updates. Vector<Device> ldevices; - // Enum real devices. + // Enum real devices (via ios_deploy, pre Xcode 15). String idepl = EDITOR_GET("export/ios/ios_deploy"); - if (idepl.is_empty()) { - idepl = "ios-deploy"; - } - { + if (!idepl.is_empty()) { String devices; List<String> args; args.push_back("-c"); @@ -2120,8 +2188,9 @@ void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) { Dictionary device_info = device_event["Device"]; Device nd; nd.id = device_info["DeviceIdentifier"]; - nd.name = device_info["DeviceName"].operator String() + " (connected through " + device_event["Interface"].operator String() + ")"; + nd.name = device_info["DeviceName"].operator String() + " (ios_deploy, " + ((device_event["Interface"] == "WIFI") ? "network" : "wired") + ")"; nd.wifi = device_event["Interface"] == "WIFI"; + nd.use_ios_deploy = true; nd.simulator = false; ldevices.push_back(nd); } @@ -2130,39 +2199,78 @@ void EditorExportPlatformIOS::_check_for_changes_poll_thread(void *ud) { } } - // Enum simulators - if (FileAccess::exists("/usr/bin/xcrun") || FileAccess::exists("/bin/xcrun")) { - String devices; - List<String> args; - args.push_back("simctl"); - args.push_back("list"); - args.push_back("devices"); - args.push_back("-j"); - - int ec = 0; - Error err = OS::get_singleton()->execute("xcrun", args, &devices, &ec, true); - if (err == OK && ec == 0) { - Ref<JSON> json; - json.instantiate(); - err = json->parse(devices); - if (err == OK) { - Dictionary data = json->get_data(); - Dictionary devices = data["devices"]; - for (const Variant *key = devices.next(nullptr); key; key = devices.next(key)) { - Array os_devices = devices[*key]; - for (int i = 0; i < os_devices.size(); i++) { - Dictionary device_info = os_devices[i]; - if (device_info["isAvailable"].operator bool() && device_info["state"] == "Booted") { + // Enum simulators. + if (_check_xcode_install() && (FileAccess::exists("/usr/bin/xcrun") || FileAccess::exists("/bin/xcrun"))) { + { + String devices; + List<String> args; + args.push_back("devicectl"); + args.push_back("list"); + args.push_back("devices"); + args.push_back("-j"); + args.push_back("-"); + args.push_back("-q"); + int ec = 0; + Error err = OS::get_singleton()->execute("xcrun", args, &devices, &ec, true); + if (err == OK && ec == 0) { + Ref<JSON> json; + json.instantiate(); + err = json->parse(devices); + if (err == OK) { + const Dictionary &data = json->get_data(); + const Dictionary &result = data["result"]; + const Array &devices = result["devices"]; + for (int i = 0; i < devices.size(); i++) { + const Dictionary &device_info = devices[i]; + const Dictionary &conn_props = device_info["connectionProperties"]; + const Dictionary &dev_props = device_info["deviceProperties"]; + if (conn_props["pairingState"] == "paired" && dev_props["developerModeStatus"] == "enabled") { Device nd; - nd.id = device_info["udid"]; - nd.name = device_info["name"].operator String() + " (simulator)"; - nd.simulator = true; + nd.id = device_info["identifier"]; + nd.name = dev_props["name"].operator String() + " (devicectl, " + ((conn_props["transportType"] == "localNetwork") ? "network" : "wired") + ")"; + nd.wifi = conn_props["transportType"] == "localNetwork"; + nd.simulator = false; ldevices.push_back(nd); } } } } } + + // Enum simulators. + { + String devices; + List<String> args; + args.push_back("simctl"); + args.push_back("list"); + args.push_back("devices"); + args.push_back("-j"); + + int ec = 0; + Error err = OS::get_singleton()->execute("xcrun", args, &devices, &ec, true); + if (err == OK && ec == 0) { + Ref<JSON> json; + json.instantiate(); + err = json->parse(devices); + if (err == OK) { + const Dictionary &data = json->get_data(); + const Dictionary &devices = data["devices"]; + for (const Variant *key = devices.next(nullptr); key; key = devices.next(key)) { + const Array &os_devices = devices[*key]; + for (int i = 0; i < os_devices.size(); i++) { + const Dictionary &device_info = os_devices[i]; + if (device_info["isAvailable"].operator bool() && device_info["state"] == "Booted") { + Device nd; + nd.id = device_info["udid"]; + nd.name = device_info["name"].operator String() + " (simulator)"; + nd.simulator = true; + ldevices.push_back(nd); + } + } + } + } + } + } } // Update device list. @@ -2323,6 +2431,7 @@ Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int List<String> args; args.push_back("simctl"); args.push_back("launch"); + args.push_back("--terminate-running-process"); args.push_back(dev.id); args.push_back(p_preset->get("application/bundle_identifier")); for (const String &E : cmd_args_list) { @@ -2341,8 +2450,8 @@ Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Running failed, see editor log for details.")); } } - } else { - // Deploy and run on real device. + } else if (dev.use_ios_deploy) { + // Deploy and run on real device (via ios-deploy). if (ep.step("Installing and running on device...", 4)) { CLEANUP_AND_RETURN(ERR_SKIP); } else { @@ -2380,6 +2489,62 @@ Error EditorExportPlatformIOS::run(const Ref<EditorExportPreset> &p_preset, int CLEANUP_AND_RETURN(ERR_UNCONFIGURED); } } + } else { + // Deploy and run on real device. + if (ep.step("Installing to device...", 3)) { + CLEANUP_AND_RETURN(ERR_SKIP); + } else { + List<String> args; + args.push_back("devicectl"); + args.push_back("device"); + args.push_back("install"); + args.push_back("app"); + args.push_back("-d"); + args.push_back(dev.id); + args.push_back(EditorPaths::get_singleton()->get_cache_dir().path_join(id).path_join("export.xcarchive/Products/Applications/export.app")); + + String log; + int ec; + err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true); + if (err != OK) { + add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start device executable.")); + CLEANUP_AND_RETURN(err); + } + if (ec != 0) { + print_line("device install:\n" + log); + add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Installation failed, see editor log for details.")); + CLEANUP_AND_RETURN(ERR_UNCONFIGURED); + } + } + + if (ep.step("Running on device...", 4)) { + CLEANUP_AND_RETURN(ERR_SKIP); + } else { + List<String> args; + args.push_back("devicectl"); + args.push_back("device"); + args.push_back("process"); + args.push_back("launch"); + args.push_back("--terminate-existing"); + args.push_back("-d"); + args.push_back(dev.id); + args.push_back(p_preset->get("application/bundle_identifier")); + for (const String &E : cmd_args_list) { + args.push_back(E); + } + + String log; + int ec; + err = OS::get_singleton()->execute("xcrun", args, &log, &ec, true); + if (err != OK) { + add_message(EXPORT_MESSAGE_WARNING, TTR("Run"), TTR("Could not start devicectl executable.")); + CLEANUP_AND_RETURN(err); + } + if (ec != 0) { + print_line("devicectl launch:\n" + log); + add_message(EXPORT_MESSAGE_ERROR, TTR("Run"), TTR("Running failed, see editor log for details.")); + } + } } CLEANUP_AND_RETURN(OK); diff --git a/platform/ios/export/export_plugin.h b/platform/ios/export/export_plugin.h index 27a4d73fcd..fd2243bcda 100644 --- a/platform/ios/export/export_plugin.h +++ b/platform/ios/export/export_plugin.h @@ -70,6 +70,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform { String name; bool simulator = false; bool wifi = false; + bool use_ios_deploy = false; }; Vector<Device> devices; @@ -81,6 +82,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform { Thread check_for_changes_thread; SafeFlag quit_request; + static bool _check_xcode_install(); static void _check_for_changes_poll_thread(void *ud); #endif @@ -138,7 +140,7 @@ class EditorExportPlatformIOS : public EditorExportPlatform { Error _export_additional_assets(const String &p_out_dir, const Vector<SharedObject> &p_libraries, Vector<IOSExportAsset> &r_exported_assets); Error _export_ios_plugins(const Ref<EditorExportPreset> &p_preset, IOSConfigData &p_config_data, const String &dest_dir, Vector<IOSExportAsset> &r_exported_assets, bool p_debug); - Error _export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags, bool p_simulator, bool p_skip_ipa); + Error _export_project_helper(const Ref<EditorExportPreset> &p_preset, bool p_debug, const String &p_path, int p_flags, bool p_simulator, bool p_oneclick); bool is_package_name_valid(const String &p_package, String *r_error = nullptr) const; diff --git a/platform/ios/os_ios.h b/platform/ios/os_ios.h index 9dc5e11497..06724d763f 100644 --- a/platform/ios/os_ios.h +++ b/platform/ios/os_ios.h @@ -41,10 +41,12 @@ #include "servers/audio_server.h" #include "servers/rendering/renderer_compositor.h" +#if defined(RD_ENABLED) +#include "servers/rendering/rendering_device.h" + #if defined(VULKAN_ENABLED) #import "vulkan_context_ios.h" - -#include "drivers/vulkan/rendering_device_vulkan.h" +#endif #endif class OS_IOS : public OS_Unix { diff --git a/platform/ios/os_ios.mm b/platform/ios/os_ios.mm index 68e6d4c934..80f1f4a5c2 100644 --- a/platform/ios/os_ios.mm +++ b/platform/ios/os_ios.mm @@ -50,15 +50,17 @@ #import <dlfcn.h> #include <sys/sysctl.h> -#if defined(VULKAN_ENABLED) +#if defined(RD_ENABLED) #include "servers/rendering/renderer_rd/renderer_compositor_rd.h" - #import <QuartzCore/CAMetalLayer.h> + +#if defined(VULKAN_ENABLED) #ifdef USE_VOLK #include <volk.h> #else #include <vulkan/vulkan.h> #endif +#endif // VULKAN_ENABLED #endif // Initialization order between compilation units is not guaranteed, @@ -72,16 +74,15 @@ HashMap<String, void *> OS_IOS::dynamic_symbol_lookup_table; void add_ios_init_callback(init_callback cb) { if (ios_init_callbacks_count == ios_init_callbacks_capacity) { - void *new_ptr = realloc(ios_init_callbacks, sizeof(cb) * 32); + void *new_ptr = realloc(ios_init_callbacks, sizeof(cb) * (ios_init_callbacks_capacity + 32)); if (new_ptr) { ios_init_callbacks = (init_callback *)(new_ptr); ios_init_callbacks_capacity += 32; + } else { + ERR_FAIL_MSG("Unable to allocate memory for extension callbacks."); } } - if (ios_init_callbacks_capacity > ios_init_callbacks_count) { - ios_init_callbacks[ios_init_callbacks_count] = cb; - ++ios_init_callbacks_count; - } + ios_init_callbacks[ios_init_callbacks_count++] = cb; } void register_dynamic_symbol(char *name, void *address) { @@ -256,6 +257,8 @@ Error OS_IOS::open_dynamic_library(const String p_path, void *&p_library_handle, path = get_framework_executable(get_executable_path().get_base_dir().path_join("Frameworks").path_join(p_path.get_file().get_basename() + ".framework")); } + ERR_FAIL_COND_V(!FileAccess::exists(path), ERR_FILE_NOT_FOUND); + p_library_handle = dlopen(path.utf8().get_data(), RTLD_NOW); ERR_FAIL_NULL_V_MSG(p_library_handle, ERR_CANT_OPEN, vformat("Can't open dynamic library: %s. Error: %s.", p_path, dlerror())); diff --git a/platform/ios/vulkan_context_ios.h b/platform/ios/vulkan_context_ios.h index 58dad4aad6..cdc8b618af 100644 --- a/platform/ios/vulkan_context_ios.h +++ b/platform/ios/vulkan_context_ios.h @@ -38,10 +38,13 @@ #import <UIKit/UIKit.h> class VulkanContextIOS : public VulkanContext { - virtual const char *_get_platform_surface_extension() const; + virtual const char *_get_platform_surface_extension() const override final; public: - Error window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, CALayer *p_metal_layer, int p_width, int p_height); + struct WindowPlatformData { + CALayer *const *layer_ptr; + }; + virtual Error window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, int p_width, int p_height, const void *p_platform_data) override final; VulkanContextIOS(); ~VulkanContextIOS(); diff --git a/platform/ios/vulkan_context_ios.mm b/platform/ios/vulkan_context_ios.mm index 56f1894e06..014e05f2e6 100644 --- a/platform/ios/vulkan_context_ios.mm +++ b/platform/ios/vulkan_context_ios.mm @@ -42,16 +42,15 @@ const char *VulkanContextIOS::_get_platform_surface_extension() const { return VK_MVK_IOS_SURFACE_EXTENSION_NAME; } -Error VulkanContextIOS::window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, CALayer *p_metal_layer, int p_width, int p_height) { - VkIOSSurfaceCreateInfoMVK createInfo; +Error VulkanContextIOS::window_create(DisplayServer::WindowID p_window_id, DisplayServer::VSyncMode p_vsync_mode, int p_width, int p_height, const void *p_platform_data) { + const WindowPlatformData *wpd = (const WindowPlatformData *)p_platform_data; + + VkIOSSurfaceCreateInfoMVK createInfo = {}; createInfo.sType = VK_STRUCTURE_TYPE_IOS_SURFACE_CREATE_INFO_MVK; - createInfo.pNext = nullptr; - createInfo.flags = 0; - createInfo.pView = (__bridge const void *)p_metal_layer; + createInfo.pView = (__bridge const void *)(*wpd->layer_ptr); - VkSurfaceKHR surface; - VkResult err = - vkCreateIOSSurfaceMVK(get_instance(), &createInfo, nullptr, &surface); + VkSurfaceKHR surface = VK_NULL_HANDLE; + VkResult err = vkCreateIOSSurfaceMVK(get_instance(), &createInfo, nullptr, &surface); ERR_FAIL_COND_V(err, ERR_CANT_CREATE); return _window_create(p_window_id, p_vsync_mode, surface, p_width, p_height); |
