diff options
Diffstat (limited to 'modules/mono/mono_gd')
| -rw-r--r-- | modules/mono/mono_gd/gd_mono.cpp | 26 | ||||
| -rw-r--r-- | modules/mono/mono_gd/support/ios_support.h | 50 | ||||
| -rw-r--r-- | modules/mono/mono_gd/support/ios_support.mm | 150 |
3 files changed, 12 insertions, 214 deletions
diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp index 247968e251..23f2f2ff13 100644 --- a/modules/mono/mono_gd/gd_mono.cpp +++ b/modules/mono/mono_gd/gd_mono.cpp @@ -322,7 +322,7 @@ godot_plugins_initialize_fn try_load_native_aot_library(void *&r_aot_dll_handle) #if defined(WINDOWS_ENABLED) String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().path_join(assembly_name + ".dll"); -#elif defined(MACOS_ENABLED) +#elif defined(MACOS_ENABLED) || defined(IOS_ENABLED) String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().path_join(assembly_name + ".dylib"); #elif defined(UNIX_ENABLED) String native_aot_so_path = GodotSharpDirs::get_api_assemblies_dir().path_join(assembly_name + ".so"); @@ -330,23 +330,19 @@ godot_plugins_initialize_fn try_load_native_aot_library(void *&r_aot_dll_handle) #error "Platform not supported (yet?)" #endif - if (FileAccess::exists(native_aot_so_path)) { - Error err = OS::get_singleton()->open_dynamic_library(native_aot_so_path, r_aot_dll_handle); - - if (err != OK) { - return nullptr; - } + Error err = OS::get_singleton()->open_dynamic_library(native_aot_so_path, r_aot_dll_handle); - void *lib = r_aot_dll_handle; + if (err != OK) { + return nullptr; + } - void *symbol = nullptr; + void *lib = r_aot_dll_handle; - err = OS::get_singleton()->get_dynamic_library_symbol_handle(lib, "godotsharp_game_main_init", symbol); - ERR_FAIL_COND_V(err != OK, nullptr); - return (godot_plugins_initialize_fn)symbol; - } + void *symbol = nullptr; - return nullptr; + err = OS::get_singleton()->get_dynamic_library_symbol_handle(lib, "godotsharp_game_main_init", symbol); + ERR_FAIL_COND_V(err != OK, nullptr); + return (godot_plugins_initialize_fn)symbol; } #endif @@ -376,11 +372,13 @@ void GDMono::initialize() { godot_plugins_initialize_fn godot_plugins_initialize = nullptr; +#if !defined(IOS_ENABLED) // Check that the .NET assemblies directory exists before trying to use it. if (!DirAccess::exists(GodotSharpDirs::get_api_assemblies_dir())) { OS::get_singleton()->alert(vformat(RTR("Unable to find the .NET assemblies directory.\nMake sure the '%s' directory exists and contains the .NET assemblies."), GodotSharpDirs::get_api_assemblies_dir()), RTR(".NET assemblies not found")); ERR_FAIL_MSG(".NET: Assemblies not found"); } +#endif if (!load_hostfxr(hostfxr_dll_handle)) { #if !defined(TOOLS_ENABLED) diff --git a/modules/mono/mono_gd/support/ios_support.h b/modules/mono/mono_gd/support/ios_support.h deleted file mode 100644 index cb397c8b46..0000000000 --- a/modules/mono/mono_gd/support/ios_support.h +++ /dev/null @@ -1,50 +0,0 @@ -/**************************************************************************/ -/* ios_support.h */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -#ifndef IOS_SUPPORT_H -#define IOS_SUPPORT_H - -#if defined(IOS_ENABLED) - -#include "core/string/ustring.h" - -namespace gdmono { -namespace ios { -namespace support { - -void initialize(); -void cleanup(); -} // namespace support -} // namespace ios -} // namespace gdmono - -#endif // IOS_ENABLED - -#endif // IOS_SUPPORT_H diff --git a/modules/mono/mono_gd/support/ios_support.mm b/modules/mono/mono_gd/support/ios_support.mm deleted file mode 100644 index df8b3e2626..0000000000 --- a/modules/mono/mono_gd/support/ios_support.mm +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************/ -/* ios_support.mm */ -/**************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/**************************************************************************/ -/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ -/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ -/* */ -/* Permission is hereby granted, free of charge, to any person obtaining */ -/* a copy of this software and associated documentation files (the */ -/* "Software"), to deal in the Software without restriction, including */ -/* without limitation the rights to use, copy, modify, merge, publish, */ -/* distribute, sublicense, and/or sell copies of the Software, and to */ -/* permit persons to whom the Software is furnished to do so, subject to */ -/* the following conditions: */ -/* */ -/* The above copyright notice and this permission notice shall be */ -/* included in all copies or substantial portions of the Software. */ -/* */ -/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ -/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ -/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ -/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ -/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ -/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ -/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/**************************************************************************/ - -#include "ios_support.h" - -#if defined(IOS_ENABLED) - -#include "../gd_mono_marshal.h" - -#include "core/ustring.h" - -#import <Foundation/Foundation.h> -#include <os/log.h> - -// Implemented mostly following: https://github.com/mono/mono/blob/master/sdks/ios/app/runtime.m - -// Definition generated by the Godot exporter -extern "C" void gd_mono_setup_aot(); - -namespace gdmono { -namespace ios { -namespace support { - -void ios_mono_log_callback(const char *log_domain, const char *log_level, const char *message, mono_bool fatal, void *user_data) { - os_log_info(OS_LOG_DEFAULT, "(%s %s) %s", log_domain, log_level, message); - if (fatal) { - os_log_info(OS_LOG_DEFAULT, "Exit code: %d.", 1); - exit(1); - } -} - -void initialize() { - mono_dllmap_insert(nullptr, "System.Native", nullptr, "__Internal", nullptr); - mono_dllmap_insert(nullptr, "System.IO.Compression.Native", nullptr, "__Internal", nullptr); - mono_dllmap_insert(nullptr, "System.Security.Cryptography.Native.Apple", nullptr, "__Internal", nullptr); - -#ifdef IOS_DEVICE - // This function is defined in an auto-generated source file - gd_mono_setup_aot(); -#endif - - mono_set_signal_chaining(true); - mono_set_crash_chaining(true); -} - -void cleanup() { -} -} // namespace support -} // namespace ios -} // namespace gdmono - -// The following are P/Invoke functions required by the monotouch profile of the BCL. -// These are P/Invoke functions and not internal calls, hence why they use -// 'mono_bool' and 'const char*' instead of 'MonoBoolean' and 'MonoString*'. - -#define GD_PINVOKE_EXPORT extern "C" __attribute__((visibility("default"))) - -GD_PINVOKE_EXPORT const char *xamarin_get_locale_country_code() { - NSLocale *locale = [NSLocale currentLocale]; - NSString *countryCode = [locale objectForKey:NSLocaleCountryCode]; - if (countryCode == nullptr) { - return strdup("US"); - } - return strdup([countryCode UTF8String]); -} - -GD_PINVOKE_EXPORT void xamarin_log(const uint16_t *p_unicode_message) { - int length = 0; - const uint16_t *ptr = p_unicode_message; - while (*ptr++) { - length += sizeof(uint16_t); - } - NSString *msg = [[NSString alloc] initWithBytes:p_unicode_message length:length encoding:NSUTF16LittleEndianStringEncoding]; - - os_log_info(OS_LOG_DEFAULT, "%{public}@", msg); -} - -GD_PINVOKE_EXPORT const char *xamarin_GetFolderPath(int p_folder) { - NSSearchPathDirectory dd = (NSSearchPathDirectory)p_folder; - NSURL *url = [[[NSFileManager defaultManager] URLsForDirectory:dd inDomains:NSUserDomainMask] lastObject]; - NSString *path = [url path]; - return strdup([path UTF8String]); -} - -GD_PINVOKE_EXPORT char *xamarin_timezone_get_local_name() { - NSTimeZone *tz = nil; - tz = [NSTimeZone localTimeZone]; - NSString *name = [tz name]; - return (name != nil) ? strdup([name UTF8String]) : strdup("Local"); -} - -GD_PINVOKE_EXPORT char **xamarin_timezone_get_names(uint32_t *p_count) { - NSArray *array = [NSTimeZone knownTimeZoneNames]; - *p_count = array.count; - char **result = (char **)malloc(sizeof(char *) * (*p_count)); - for (uint32_t i = 0; i < *p_count; i++) { - NSString *s = [array objectAtIndex:i]; - result[i] = strdup(s.UTF8String); - } - return result; -} - -GD_PINVOKE_EXPORT void *xamarin_timezone_get_data(const char *p_name, uint32_t *p_size) { // FIXME: uint32_t since Dec 2019, unsigned long before - NSTimeZone *tz = nil; - if (p_name) { - NSString *n = [[NSString alloc] initWithUTF8String:p_name]; - tz = [[NSTimeZone alloc] initWithName:n]; - } else { - tz = [NSTimeZone localTimeZone]; - } - NSData *data = [tz data]; - *p_size = [data length]; - void *result = malloc(*p_size); - memcpy(result, data.bytes, *p_size); - return result; -} - -GD_PINVOKE_EXPORT void xamarin_start_wwan(const char *p_uri) { - // FIXME: What's this for? No idea how to implement. - os_log_error(OS_LOG_DEFAULT, "Not implemented: 'xamarin_start_wwan'"); -} - -#endif // IOS_ENABLED |
