diff options
author | Steve Pfister <steveisok@users.noreply.github.com> | 2021-03-09 20:17:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-09 20:17:52 +0300 |
commit | 7767d461af0f2cc69cca6f7ae667d913a200feee (patch) | |
tree | 53b7dae5278f5db36ec0a5f4f89abd73a02f926f /src/tasks/AppleAppBuilder | |
parent | 3fc3a2226e4373f055f98f799785b8c88262fb32 (diff) |
Enable ICU on iOS (#48606)
Diffstat (limited to 'src/tasks/AppleAppBuilder')
-rw-r--r-- | src/tasks/AppleAppBuilder/AppleAppBuilder.cs | 42 | ||||
-rw-r--r-- | src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template | 1 | ||||
-rw-r--r-- | src/tasks/AppleAppBuilder/Templates/runtime.m | 41 | ||||
-rw-r--r-- | src/tasks/AppleAppBuilder/Xcode.cs | 24 |
4 files changed, 84 insertions, 24 deletions
diff --git a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs index a35fc966087..fc688ba2395 100644 --- a/src/tasks/AppleAppBuilder/AppleAppBuilder.cs +++ b/src/tasks/AppleAppBuilder/AppleAppBuilder.cs @@ -49,6 +49,24 @@ public class AppleAppBuilderTask : Task public ITaskItem[] Assemblies { get; set; } = Array.Empty<ITaskItem>(); /// <summary> + /// Target arch, can be "arm64" (device) or "x64" (simulator) at the moment + /// </summary> + [Required] + public string Arch { get; set; } = ""!; + + /// <summary> + /// Path to *.app bundle + /// </summary> + [Output] + public string AppBundlePath { get; set; } = ""!; + + /// <summary> + /// Path to xcode project + /// </summary> + [Output] + public string XcodeProjectPath { get; set; } = ""!; + + /// <summary> /// Path to store build artifacts /// </summary> public string? OutputDirectory { get; set; } @@ -59,12 +77,6 @@ public class AppleAppBuilderTask : Task public bool Optimized { get; set; } /// <summary> - /// Target arch, can be "arm64" (device) or "x64" (simulator) at the moment - /// </summary> - [Required] - public string Arch { get; set; } = ""!; - - /// <summary> /// DEVELOPER_TEAM provisioning, needed for arm64 builds. /// </summary> public string? DevTeamProvisioning { get; set; } @@ -97,15 +109,14 @@ public class AppleAppBuilderTask : Task public bool UseConsoleUITemplate { get; set; } /// <summary> - /// Path to *.app bundle + /// Prefer FullAOT mode for Simulator over JIT /// </summary> - [Output] - public string AppBundlePath { get; set; } = ""!; + public bool ForceAOT { get; set; } /// <summary> - /// Prefer FullAOT mode for Simulator over JIT + /// Forces the runtime to use the invariant mode /// </summary> - public bool ForceAOT { get; set; } + public bool InvariantGlobalization { get; set; } /// <summary> /// Forces the runtime to use the interpreter @@ -113,10 +124,9 @@ public class AppleAppBuilderTask : Task public bool ForceInterpreter { get; set; } /// <summary> - /// Path to xcode project + /// Enables detailed runtime logging /// </summary> - [Output] - public string XcodeProjectPath { get; set; } = ""!; + public bool EnableRuntimeLogging { get; set; } public override bool Execute() { @@ -173,8 +183,10 @@ public class AppleAppBuilderTask : Task if (GenerateXcodeProject) { Xcode generator = new Xcode(TargetOS); + generator.EnableRuntimeLogging = EnableRuntimeLogging; + XcodeProjectPath = generator.GenerateXCode(ProjectName, MainLibraryFileName, assemblerFiles, - AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, Optimized, NativeMainSource); + AppDir, binDir, MonoRuntimeHeaders, !isDevice, UseConsoleUITemplate, ForceAOT, ForceInterpreter, InvariantGlobalization, Optimized, NativeMainSource); if (BuildAppBundle) { diff --git a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template index 4b3d40bda6a..7fea422c6b4 100644 --- a/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template +++ b/src/tasks/AppleAppBuilder/Templates/CMakeLists.txt.template @@ -40,6 +40,7 @@ target_link_libraries( "-framework UIKit" %FrameworksToLink% "-lz" + "-lc++" "-liconv" %NativeLibrariesToLink% ) diff --git a/src/tasks/AppleAppBuilder/Templates/runtime.m b/src/tasks/AppleAppBuilder/Templates/runtime.m index 1a27d785f3b..fe2845a10ad 100644 --- a/src/tasks/AppleAppBuilder/Templates/runtime.m +++ b/src/tasks/AppleAppBuilder/Templates/runtime.m @@ -14,6 +14,8 @@ #import <os/log.h> #include <sys/stat.h> #include <sys/mman.h> +#include <stdlib.h> +#include <stdio.h> static char *bundle_path; @@ -201,6 +203,23 @@ register_dllmap (void) //%DllMap% } +int32_t GlobalizationNative_LoadICUData(char *path); + +static int32_t load_icu_data () +{ + char path [1024]; + int res; + + const char *dname = "icudt.dat"; + const char *bundle = get_bundle_path (); + + os_log_info (OS_LOG_DEFAULT, "Loading ICU data file '%s'.", dname); + res = snprintf (path, sizeof (path) - 1, "%s/%s", bundle, dname); + assert (res > 0); + + return GlobalizationNative_LoadICUData(path); +} + #if FORCE_INTERPRETER || FORCE_AOT || (!TARGET_OS_SIMULATOR && !TARGET_OS_MACCATALYST) void mono_jit_set_aot_mode (MonoAotMode mode); void register_aot_modules (void); @@ -209,12 +228,24 @@ void register_aot_modules (void); void mono_ios_runtime_init (void) { - // for now, only Invariant Mode is supported (FIXME: integrate ICU) +#if INVARIANT_GLOBALIZATION setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", TRUE); - // uncomment for debug output: - // - // setenv ("MONO_LOG_LEVEL", "debug", TRUE); - // setenv ("MONO_LOG_MASK", "all", TRUE); +#endif + +#if ENABLE_RUNTIME_LOGGING + setenv ("MONO_LOG_LEVEL", "debug", TRUE); + setenv ("MONO_LOG_MASK", "all", TRUE); +#endif + +#if !INVARIANT_GLOBALIZATION + int32_t ret = load_icu_data (); + + if (ret == 0) { + os_log_info (OS_LOG_DEFAULT, "ICU BAD EXIT %d.", ret); + exit (ret); + return; + } +#endif id args_array = [[NSProcessInfo processInfo] arguments]; assert ([args_array count] <= 128); diff --git a/src/tasks/AppleAppBuilder/Xcode.cs b/src/tasks/AppleAppBuilder/Xcode.cs index ddf7dee5f8d..96fab4b7035 100644 --- a/src/tasks/AppleAppBuilder/Xcode.cs +++ b/src/tasks/AppleAppBuilder/Xcode.cs @@ -29,6 +29,8 @@ internal class Xcode } } + public bool EnableRuntimeLogging { get; set; } + public string GenerateXCode( string projectName, string entryPointLib, @@ -40,6 +42,7 @@ internal class Xcode bool useConsoleUiTemplate, bool forceAOT, bool forceInterpreter, + bool invariantGlobalization, bool stripDebugSymbols, string? nativeMainSource = null) { @@ -114,16 +117,27 @@ internal class Xcode cmakeLists = cmakeLists.Replace("%AotSources%", aotSources); cmakeLists = cmakeLists.Replace("%AotModulesSource%", string.IsNullOrEmpty(aotSources) ? "" : "modules.m"); - string defines = ""; + var defines = new StringBuilder(); if (forceInterpreter) { - defines = "add_definitions(-DFORCE_INTERPRETER=1)"; + defines.Append("add_definitions(-DFORCE_INTERPRETER=1)"); } else if (forceAOT) { - defines = "add_definitions(-DFORCE_AOT=1)"; + defines.Append("add_definitions(-DFORCE_AOT=1)"); } - cmakeLists = cmakeLists.Replace("%Defines%", defines); + + if (invariantGlobalization) + { + defines.Append("add_definitions(-DINVARIANT_GLOBALIZATION=1)"); + } + + if (EnableRuntimeLogging) + { + defines.Append("add_definitions(-DENABLE_RUNTIME_LOGGING=1)"); + } + + cmakeLists = cmakeLists.Replace("%Defines%", defines.ToString()); string plist = Utils.GetEmbeddedResource("Info.plist.template") .Replace("%BundleIdentifier%", projectName); @@ -156,6 +170,8 @@ internal class Xcode dllMap.AppendLine($" mono_dllmap_insert (NULL, \"{aFileName}\", NULL, \"__Internal\", NULL);"); } + dllMap.AppendLine($" mono_dllmap_insert (NULL, \"System.Globalization.Native\", NULL, \"__Internal\", NULL);"); + File.WriteAllText(Path.Combine(binDir, "runtime.m"), Utils.GetEmbeddedResource("runtime.m") .Replace("//%DllMap%", dllMap.ToString()) |