-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Support loading ICU data from managed Interop #49406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
61de8be
Support loading ICU data from managed Interop
1fc8cde
Address feedback and move LoadICUData to iOS only
a3dbbe1
More feedback
32dd00d
Merge remote-tracking branch 'upstream/main' into ios-load-icu-managed
88a99b0
Address additional good feedback
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| internal static partial class Interop | ||
| { | ||
| internal static partial class Globalization | ||
| { | ||
| [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_LoadICUData")] | ||
| internal static extern int LoadICUData(string path); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...braries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.LoadICU.Unix.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Globalization | ||
| { | ||
| internal static partial class GlobalizationMode | ||
| { | ||
| private static int LoadICU() => Interop.Globalization.LoadICU(); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
...ibraries/System.Private.CoreLib/src/System/Globalization/GlobalizationMode.LoadICU.iOS.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Globalization | ||
| { | ||
| internal static partial class GlobalizationMode | ||
| { | ||
| private static int LoadICU() | ||
| { | ||
| object? datPath = AppContext.GetData("ICU_DAT_FILE_PATH"); | ||
| return (datPath != null) ? Interop.Globalization.LoadICUData(datPath!.ToString()!) : Interop.Globalization.LoadICU(); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,8 @@ | |
| #define MONO_ENTER_GC_UNSAFE | ||
| #define MONO_EXIT_GC_UNSAFE | ||
|
|
||
| #define APPLE_RUNTIME_IDENTIFIER "//%APPLE_RUNTIME_IDENTIFIER%" | ||
|
|
||
| const char * | ||
| get_bundle_path (void) | ||
| { | ||
|
|
@@ -203,23 +205,6 @@ | |
| //%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); | ||
|
|
@@ -237,16 +222,6 @@ static int32_t load_icu_data () | |
| 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); | ||
| const char *managed_argv [128]; | ||
|
|
@@ -261,8 +236,29 @@ static int32_t load_icu_data () | |
| const char* bundle = get_bundle_path (); | ||
| chdir (bundle); | ||
|
|
||
| char icu_dat_path [1024]; | ||
| int res; | ||
|
|
||
| res = snprintf (icu_dat_path, sizeof (icu_dat_path) - 1, "%s/%s", bundle, "icudt.dat"); | ||
| assert (res > 0); | ||
|
|
||
| // TODO: set TRUSTED_PLATFORM_ASSEMBLIES, APP_PATHS and NATIVE_DLL_SEARCH_DIRECTORIES | ||
| monovm_initialize(0, NULL, NULL); | ||
| const char *appctx_keys [] = { | ||
| "RUNTIME_IDENTIFIER", | ||
safern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "APP_CONTEXT_BASE_DIRECTORY", | ||
| #ifndef INVARIANT_GLOBALIZATION | ||
safern marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "ICU_DAT_FILE_PATH" | ||
| #endif | ||
| }; | ||
| const char *appctx_values [] = { | ||
| APPLE_RUNTIME_IDENTIFIER, | ||
| bundle, | ||
| #ifndef INVARIANT_GLOBALIZATION | ||
| icu_dat_path | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: trailing commas are not an error. (and they play nicer with git history when someone adds the next array entry) |
||
| #endif | ||
| }; | ||
|
|
||
| monovm_initialize (sizeof (appctx_keys) / sizeof (appctx_keys [0]), appctx_keys, appctx_values); | ||
|
|
||
| #if FORCE_INTERPRETER | ||
| os_log_info (OS_LOG_DEFAULT, "INTERP Enabled"); | ||
|
|
@@ -300,7 +296,7 @@ static int32_t load_icu_data () | |
| assert (assembly); | ||
| os_log_info (OS_LOG_DEFAULT, "Executable: %{public}s", executable); | ||
|
|
||
| int res = mono_jit_exec (mono_domain_get (), assembly, argi, managed_argv); | ||
| res = mono_jit_exec (mono_domain_get (), assembly, argi, managed_argv); | ||
| // Print this so apps parsing logs can detect when we exited | ||
| os_log_info (OS_LOG_DEFAULT, "Exit code: %d.", res); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.