From cbae5e5effa95a31dadcae482ffd00318297d9e7 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 18 Jun 2020 01:48:41 +0300 Subject: [PATCH 01/62] initial static ICU implementation for wasm --- .../pal_icushim_internal.h | 3 ++ .../pal_icushim_static.c | 35 +++++++++++++++++++ src/mono/cmake/config.h.in | 3 ++ src/mono/configure.ac | 12 ++++++- src/mono/mono.proj | 1 + src/mono/mono/metadata/Makefile.am | 12 ++++++- src/mono/mono/metadata/native-library.c | 6 +++- src/mono/wasm/Makefile | 10 +++++- src/mono/wasm/runtime/driver.c | 3 +- src/mono/wasm/wasm.targets | 1 + 10 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h index 929b737a472355..96293240a11124 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h @@ -55,6 +55,7 @@ #include "pal_compiler.h" +#if !defined(STATIC_ICU) // List of all functions from the ICU libraries that are used in the System.Globalization.Native.so #define FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \ PER_FUNCTION_BLOCK(u_charsToUChars, libicuuc) \ @@ -279,3 +280,5 @@ FOR_ALL_ICU_FUNCTIONS #define usearch_getMatchedLength(...) usearch_getMatchedLength_ptr(__VA_ARGS__) #define usearch_last(...) usearch_last_ptr(__VA_ARGS__) #define usearch_openFromCollator(...) usearch_openFromCollator_ptr(__VA_ARGS__) + +#endif // !defined(ICU_STATIC_LINKING) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c new file mode 100644 index 00000000000000..8f3a8cebf1639e --- /dev/null +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// + +#include +#include "pal_icushim_internal.h" +#include "pal_icushim.h" +#include +#include + +int32_t GlobalizationNative_LoadICU(void) +{ + const char* icudir = getenv("DOTNET_ICU_DIR"); + if (!icudir) + return 0; + + // path to a directory with icudt___.dat (e.g. icudt67l.dat) + // we can also use `udata_setCommonData(const void *data, UErrorCode *err)` API here + u_setDataDirectory(icudir); + return 1; +} + +void GlobalizationNative_InitICUFunctions(void* icuuc, void* icuin, const char* version, const char* suffix) +{ + // no-op for static +} + +int32_t GlobalizationNative_GetICUVersion(void) +{ + UVersionInfo versionInfo; + u_getVersion(versionInfo); + + return (versionInfo[0] << 24) + (versionInfo[1] << 16) + (versionInfo[2] << 8) + versionInfo[3]; +} diff --git a/src/mono/cmake/config.h.in b/src/mono/cmake/config.h.in index e89b59c5f71009..8f013c5f0c6774 100644 --- a/src/mono/cmake/config.h.in +++ b/src/mono/cmake/config.h.in @@ -210,6 +210,9 @@ /* Use static zlib */ #cmakedefine HAVE_STATIC_ZLIB 1 +/* Use static ICU */ +#cmakedefine STATIC_ICU 1 + /* Use OS-provided zlib */ #cmakedefine HAVE_SYS_ZLIB 1 diff --git a/src/mono/configure.ac b/src/mono/configure.ac index bab7614ef1748c..44a5c4483f1515 100644 --- a/src/mono/configure.ac +++ b/src/mono/configure.ac @@ -1312,6 +1312,12 @@ AC_ARG_WITH(spectre-mitigation, [ --with-spectre-mitigation=yes,no AC_ARG_WITH(spectre-indirect-branch-choice, [ --with-spectre-indirect-branch-choice=keep,thunk,inline,extern Convert indirect branches to the specified kind of thunk (defaults to inline)], [], [with_spectre_indirect_branch_choice=inline]) AC_ARG_WITH(spectre-function-return-choice, [ --with-spectre-function-return-choice=keep,thunk,inline,extern Convert function return instructions to the specified kind of thunk (defaults to inline)], [], [with_spectre_function_return_choice=inline]) +AC_ARG_WITH(static_icu, [ --with-static-icu=yes|no Integrate ICU statically into the runtime (defaults to no)],[ + if test x$with_static_icu = xyes ; then + AC_DEFINE(STATIC_ICU,1,[Integrate ICU statically into the runtime.]) + fi +], [with_static_icu=no]) + dnl dnl Spectre compiler mitigation flag checks dnl @@ -1699,6 +1705,7 @@ AM_CONDITIONAL(INSTALL_MONOTOUCH, [test "x$with_monotouch" != "xno"]) AM_CONDITIONAL(INSTALL_MONOTOUCH_WATCH, [test "x$with_monotouch_watch" != "xno"]) AM_CONDITIONAL(INSTALL_MONOTOUCH_TV, [test "x$with_monotouch_tv" != "xno"]) AM_CONDITIONAL(BITCODE, test "x$with_bitcode" = "xyes") +AM_CONDITIONAL(STATIC_ICU, test "x$with_static_icu" = "xyes") AM_CONDITIONAL(INSTALL_XAMMAC, [test "x$with_xammac" != "xno"]) AM_CONDITIONAL(INSTALL_TESTING_AOT_FULL_INTERP, [test "x$with_testing_aot_full_interp" != "xno"]) AM_CONDITIONAL(INSTALL_TESTING_AOT_HYBRID, [test "x$with_testing_aot_hybrid" != "xno"]) @@ -6839,7 +6846,10 @@ if test x$with_core = xonly; then fi if test x$have_shim_globalization = xyes || test x$cross_compiling = xyes; then ICU_SHIM_PATH=../../../libraries/Native/Unix/System.Globalization.Native - if test x$target_osx = xyes; then + if test x$target_wasm = xyes; then + ICU_CFLAGS="-DTARGET_UNIX -DU_DISABLE_RENAMING" + have_sys_icu=yes + elif test x$target_osx = xyes; then ORIG_CPPFLAGS=$CPPFLAGS # adding icu path to pkg_config_path PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/local/opt/icu4c/lib/pkgconfig diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 4fef8515831197..ed3794bc690e11 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -635,6 +635,7 @@ <_MonoConfigureParams Include="--disable-icall-tables"/> <_MonoConfigureParams Include="--disable-crash-reporting"/> <_MonoConfigureParams Include="--with-bitcode=yes"/> + <_MonoConfigureParams Condition="'$(ICU_REPO)' != ''" Include="--with-static-icu=yes"/> <_MonoConfigureParams Include="--enable-minimal=ssa,com,jit,reflection_emit_save,portability,assembly_remapping,attach,verifier,full_messages,appdomains,shadowcopy,security,sgen_marksweep_conc,sgen_split_nursery,sgen_gc_bridge,logging,remoting,shared_perfcounters,sgen_debug_helpers,soft_debug,interpreter,assert_messages,cleanup,mdb,gac,threads,$(_MonoEnableMinimal)"/> <_MonoCFLAGS Include="-fexceptions" /> <_MonoCFLAGS Include="-I$(NuGetPackageRoot)/microsoft.netcore.runtime.icu.transport/$(MicrosoftNETCoreRuntimeICUTransportVersion)/runtimes/browser-wasm/native/include" /> diff --git a/src/mono/mono/metadata/Makefile.am b/src/mono/mono/metadata/Makefile.am index 8e6f520077dfe8..5d3f35245c1d7e 100644 --- a/src/mono/mono/metadata/Makefile.am +++ b/src/mono/mono/metadata/Makefile.am @@ -158,6 +158,16 @@ nodist_libmonoruntime_shimglobalization_la_SOURCES = \ @ICU_SHIM_PATH@/entrypoints.c libmonoruntime_shimglobalization_la_CFLAGS = @ICU_CFLAGS@ -I$(top_srcdir)/../libraries/Native/Unix/System.Globalization.Native/ -I$(top_srcdir)/../libraries/Native/Unix/Common/ + +if STATIC_ICU +nodist_libmonoruntime_shimglobalization_la_SOURCES += @ICU_SHIM_PATH@/pal_icushim_static.c +libmonoruntime_shimglobalization_la_CFLAGS += -I$(ICU_REPO)/icu4c/source/wasm-usr/include/ \ +-L$(ICU_REPO)/icu4c/source/wasm-build/lib/ -licui18n -licuuc -licutu -licuio \ +-L$(ICU_REPO)/icu4c/source/wasm-build/stubdata -licudata +else +nodist_libmonoruntime_shimglobalization_la_SOURCES += @ICU_SHIM_PATH@/pal_icushim.c +endif + endif endif @@ -498,7 +508,7 @@ libmonoruntimeinclude_HEADERS = \ sgen-bridge.h \ threads.h \ tokentype.h \ - verify.h + verify.h if !ENABLE_MSVC_ONLY diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index b2d5712c813c13..8f266a6381d9f8 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -747,6 +747,7 @@ netcore_lookup_native_library (MonoAssemblyLoadContext *alc, MonoImage *image, c mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "DllImport attempting to load: '%s'.", scope); +#if !TARGET_WASM // We allow a special name to dlopen from the running process namespace, which is not present in CoreCLR if (strcmp (scope, "__Internal") == 0) { if (!internal_module) @@ -760,6 +761,7 @@ netcore_lookup_native_library (MonoAssemblyLoadContext *alc, MonoImage *image, c return module; } +#endif /* * Try these until one of them succeeds: @@ -1057,6 +1059,7 @@ legacy_probe_for_module (MonoImage *image, const char *new_scope) mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "DllImport attempting to load: '%s'.", new_scope); +#if !defined(TARGET_WASM) /* we allow a special name to dlopen from the running process namespace */ if (strcmp (new_scope, "__Internal") == 0) { if (!internal_module) @@ -1070,6 +1073,7 @@ legacy_probe_for_module (MonoImage *image, const char *new_scope) return module; } +#endif /* * Try loading the module using a variety of names @@ -1262,7 +1266,7 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou addr = pinvoke_probe_for_symbol (module, piinfo, new_import, &error_msg); if (!addr) { -#if defined(ENABLE_NETCORE) && !defined(HOST_WIN32) +#if !defined(TARGET_WASM) && defined(ENABLE_NETCORE) && !defined(HOST_WIN32) if (strcmp (new_scope, "__Internal") == 0) { g_free ((char *)new_scope); new_scope = g_strdup (MONO_LOADER_LIBRARY_NAME); diff --git a/src/mono/wasm/Makefile b/src/mono/wasm/Makefile index 6fd32038f7282b..63c8c7ef88bc42 100644 --- a/src/mono/wasm/Makefile +++ b/src/mono/wasm/Makefile @@ -56,7 +56,15 @@ MONO_LIBS = \ $(ICU_LIBDIR)/libicuuc.a \ $(ICU_LIBDIR)/libicui18n.a -EMCC_FLAGS=--profiling-funcs -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s ALIASING_FUNCTION_POINTERS=0 -s NO_EXIT_RUNTIME=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString', 'UTF8ArrayToString', 'addFunction']" -s "EXPORTED_FUNCTIONS=['_putchar']" --source-map-base http://example.com -emit-llvm -s FORCE_FILESYSTEM=1 -s USE_ZLIB=1 +ifeq ($(ICU_REPO),) + @echo "ICU_REPO is not set." +else + MONO_LIBS := $(MONO_LIBS) $(ICU_REPO)/icu4c/source/wasm-build/lib/{libicui18n.a,libicuio.a,libicuuc.a,libicutu.a} \ + $(ICU_REPO)/icu4c/source/wasm-build/stubdata/libicudata.a +endif + + +EMCC_FLAGS=--profiling-funcs -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s ALIASING_FUNCTION_POINTERS=0 -s NO_EXIT_RUNTIME=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString', 'UTF8ArrayToString', 'addFunction']" -s "EXPORTED_FUNCTIONS=['_putchar']" --source-map-base http://example.com -emit-llvm -s WASM_OBJECT_FILES=0 -s FORCE_FILESYSTEM=1 -s USE_ZLIB=1 EMCC_DEBUG_FLAGS =-g -Os -s ASSERTIONS=1 -DENABLE_NETCORE=1 -DDEBUG=1 EMCC_RELEASE_FLAGS=-Oz --llvm-opts 2 -DENABLE_NETCORE=1 diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c index cafc0328c9db61..8a3cd96c5f0cb8 100644 --- a/src/mono/wasm/runtime/driver.c +++ b/src/mono/wasm/runtime/driver.c @@ -322,7 +322,8 @@ mono_wasm_load_runtime (const char *managed_path, int enable_debugging) monoeg_g_setenv ("COMPlus_DebugWriteToStdErr", "1", 0); #endif #ifdef ENABLE_NETCORE - monoeg_g_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", 0); + if (!getenv("DOTNET_ICU_DIR")) + monoeg_g_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", 0); #endif mini_parse_debug_option ("top-runtime-invoke-unhandled"); diff --git a/src/mono/wasm/wasm.targets b/src/mono/wasm/wasm.targets index b3aa4c15b2bee3..e380953b0f7eb5 100644 --- a/src/mono/wasm/wasm.targets +++ b/src/mono/wasm/wasm.targets @@ -11,6 +11,7 @@ + From f9fc4e31953b5c34d48b5d0594b0e7d645f204fa Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Thu, 18 Jun 2020 01:57:13 +0300 Subject: [PATCH 02/62] Update pal_icushim_internal.h --- .../Unix/System.Globalization.Native/pal_icushim_internal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h index 96293240a11124..16e85f8bda0de8 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h @@ -281,4 +281,4 @@ FOR_ALL_ICU_FUNCTIONS #define usearch_last(...) usearch_last_ptr(__VA_ARGS__) #define usearch_openFromCollator(...) usearch_openFromCollator_ptr(__VA_ARGS__) -#endif // !defined(ICU_STATIC_LINKING) +#endif // !defined(STATIC_ICU) From bdc89552769de98e59b34ea2ac4925f845a8c939 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Fri, 12 Jun 2020 13:57:03 -0700 Subject: [PATCH 03/62] Checkpoint Checkpoint Checkpoint Checkpoint Checkpoint Maybe fix whitespace damage Fix missing line endings in mono-config.js Maybe fix whitespace damage Add verification and fail-fast errors if ICU build data is missing or in the wrong place Checkpoint Checkpoint Checkpoint Checkpoint Checkpoint Checkpoint Checkpoint Fix whitespace damage Add editorconfig file for the wasm files Checkpoint Fix typo Checkpoint Checkpoint Cleanup Cleanup Reverse accidental removal of invariant default Checkpoint Sensible error when ICU_REPO is not set Checkpoint: Reset changes for mangled files Manually repair rebase damage These changes are no longer needed Repair rebase damage Fix mode damage Address PR feedback Fix icushim being built in static mode Remove broken wildcard dependency Fix sample startup --- .../pal_icushim_internal.h | 6 + .../pal_icushim_static.c | 41 ++- src/mono/configure.ac | 2 +- src/mono/mono/metadata/Makefile.am | 36 ++- src/mono/mono/metadata/native-library.c | 6 +- src/mono/netcore/sample/wasm/Program.cs | 2 + .../netcore/sample/wasm/WasmSample.csproj | 14 +- src/mono/wasm/.editorconfig | 13 + src/mono/wasm/Makefile | 12 +- src/mono/wasm/runtime-test.js | 81 ++--- src/mono/wasm/runtime/driver.c | 4 - src/mono/wasm/runtime/library_mono.js | 283 ++++++++++++++---- .../WasmAppBuilder/WasmAppBuilder.cs | 18 +- 13 files changed, 391 insertions(+), 127 deletions(-) create mode 100755 src/mono/wasm/.editorconfig diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h index 16e85f8bda0de8..0908eb8a4ab8fb 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h @@ -19,11 +19,13 @@ // All ICU headers need to be included here so that all function prototypes are // available before the function pointers are declared below. +#include #include #include #include #include #include +#include #include #include #include @@ -58,12 +60,14 @@ #if !defined(STATIC_ICU) // List of all functions from the ICU libraries that are used in the System.Globalization.Native.so #define FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \ + PER_FUNCTION_BLOCK(u_init, libicuuc) \ PER_FUNCTION_BLOCK(u_charsToUChars, libicuuc) \ PER_FUNCTION_BLOCK(u_getVersion, libicuuc) \ PER_FUNCTION_BLOCK(u_strlen, libicuuc) \ PER_FUNCTION_BLOCK(u_strncpy, libicuuc) \ PER_FUNCTION_BLOCK(u_tolower, libicuuc) \ PER_FUNCTION_BLOCK(u_toupper, libicuuc) \ + PER_FUNCTION_BLOCK(udata_setCommonData, libicuuc) \ PER_FUNCTION_BLOCK(ucal_add, libicui18n) \ PER_FUNCTION_BLOCK(ucal_close, libicui18n) \ PER_FUNCTION_BLOCK(ucal_get, libicui18n) \ @@ -184,12 +188,14 @@ FOR_ALL_ICU_FUNCTIONS // Redefine all calls to ICU functions as calls through pointers that are set // to the functions of the selected version of ICU in the initialization. +#define u_init(...) u_init_ptr(__VA_ARGS__) #define u_charsToUChars(...) u_charsToUChars_ptr(__VA_ARGS__) #define u_getVersion(...) u_getVersion_ptr(__VA_ARGS__) #define u_strlen(...) u_strlen_ptr(__VA_ARGS__) #define u_strncpy(...) u_strncpy_ptr(__VA_ARGS__) #define u_tolower(...) u_tolower_ptr(__VA_ARGS__) #define u_toupper(...) u_toupper_ptr(__VA_ARGS__) +#define udata_setCommonData(...) udata_setCommonData_ptr(__VA_ARGS__) #define ucal_add(...) ucal_add_ptr(__VA_ARGS__) #define ucal_close(...) ucal_close_ptr(__VA_ARGS__) #define ucal_get(...) ucal_get_ptr(__VA_ARGS__) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c index 8f3a8cebf1639e..69f3723883a59f 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c @@ -4,20 +4,53 @@ // #include +#include #include "pal_icushim_internal.h" #include "pal_icushim.h" #include #include +static void log_icu_error (const char * name, UErrorCode status) { + const char * statusText = u_errorName(status); + fprintf(stderr, "ICU call %s failed with error #%d '%s'.\n", name, status, statusText); +} + +#ifdef __EMSCRIPTEN__ +#include + +EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data (void * pData); + +EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data (void * pData) { + UErrorCode status = 0; + udata_setCommonData (pData, &status); + + if (U_FAILURE(status)) { + log_icu_error("udata_setCommonData", status); + return 0; + } else { + return 1; + } +} +#endif + int32_t GlobalizationNative_LoadICU(void) { const char* icudir = getenv("DOTNET_ICU_DIR"); - if (!icudir) + if (icudir) + u_setDataDirectory(icudir); + else + ; // default ICU search path behavior will be used, see http://userguide.icu-project.org/icudata + + UErrorCode status = 0; + // Invoking u_init will probe to see if ICU common data is already available and if it is missing, + // attempt to load it from the local filesystem. + u_init(&status); + + if (U_FAILURE(status)) { + log_icu_error("u_init", status); return 0; + } - // path to a directory with icudt___.dat (e.g. icudt67l.dat) - // we can also use `udata_setCommonData(const void *data, UErrorCode *err)` API here - u_setDataDirectory(icudir); return 1; } diff --git a/src/mono/configure.ac b/src/mono/configure.ac index 44a5c4483f1515..a99e6840b18094 100644 --- a/src/mono/configure.ac +++ b/src/mono/configure.ac @@ -6846,7 +6846,7 @@ if test x$with_core = xonly; then fi if test x$have_shim_globalization = xyes || test x$cross_compiling = xyes; then ICU_SHIM_PATH=../../../libraries/Native/Unix/System.Globalization.Native - if test x$target_wasm = xyes; then + if test x$target_wasm = xyes && test x$with_static_icu = xyes; then ICU_CFLAGS="-DTARGET_UNIX -DU_DISABLE_RENAMING" have_sys_icu=yes elif test x$target_osx = xyes; then diff --git a/src/mono/mono/metadata/Makefile.am b/src/mono/mono/metadata/Makefile.am index 5d3f35245c1d7e..9716b153d85f99 100644 --- a/src/mono/mono/metadata/Makefile.am +++ b/src/mono/mono/metadata/Makefile.am @@ -154,22 +154,44 @@ nodist_libmonoruntime_shimglobalization_la_SOURCES = \ @ICU_SHIM_PATH@/pal_localeStringData.c \ @ICU_SHIM_PATH@/pal_normalization.c \ @ICU_SHIM_PATH@/pal_timeZoneInfo.c \ - @ICU_SHIM_PATH@/pal_icushim.c \ @ICU_SHIM_PATH@/entrypoints.c libmonoruntime_shimglobalization_la_CFLAGS = @ICU_CFLAGS@ -I$(top_srcdir)/../libraries/Native/Unix/System.Globalization.Native/ -I$(top_srcdir)/../libraries/Native/Unix/Common/ if STATIC_ICU + +ICU_INCLUDE_DIRECTORY = $(ICU_REPO)/icu4c/source/wasm-usr/include/ +ICU_LIB_DIRECTORY = $(ICU_REPO)/icu4c/source/wasm-build/lib/ +ICU_STUBDATA_DIRECTORY = $(ICU_REPO)/icu4c/source/wasm-build/stubdata + +# Check for the existence of the include and lib directories. +# If they are missing we will get confusing errors later, so fail-fast is best. + +# The conditionals need a space before them to bypass automake's broken parser +# and reach gnu make to be evaluated. see https://patchwork.kernel.org/patch/6709921/ + ifeq (,$(wildcard $(ICU_INCLUDE_DIRECTORY))) +$(error ICU include directory $(ICU_INCLUDE_DIRECTORY) does not exist) + endif + ifeq (,$(wildcard $(ICU_LIB_DIRECTORY))) +$(error ICU lib directory $(ICU_LIB_DIRECTORY) does not exist) + endif + ifeq (,$(wildcard $(ICU_STUBDATA_DIRECTORY))) +$(error ICU lib directory $(ICU_STUBDATA_DIRECTORY) does not exist) + endif + nodist_libmonoruntime_shimglobalization_la_SOURCES += @ICU_SHIM_PATH@/pal_icushim_static.c -libmonoruntime_shimglobalization_la_CFLAGS += -I$(ICU_REPO)/icu4c/source/wasm-usr/include/ \ --L$(ICU_REPO)/icu4c/source/wasm-build/lib/ -licui18n -licuuc -licutu -licuio \ --L$(ICU_REPO)/icu4c/source/wasm-build/stubdata -licudata +libmonoruntime_shimglobalization_la_CFLAGS += -I$(ICU_INCLUDE_DIRECTORY) \ +-L$(ICU_LIB_DIRECTORY) -licui18n -licuuc -licutu -licuio \ +-L$(ICU_STUBDATA_DIRECTORY) -licudata + else + nodist_libmonoruntime_shimglobalization_la_SOURCES += @ICU_SHIM_PATH@/pal_icushim.c -endif -endif -endif +endif # STATIC_ICU + +endif # HAVE_SYS_ICU +endif # ENABLE_NETCORE if !ENABLE_NETCORE culture_libraries = ../culture/libmono-culture.la diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c index 8f266a6381d9f8..b2d5712c813c13 100644 --- a/src/mono/mono/metadata/native-library.c +++ b/src/mono/mono/metadata/native-library.c @@ -747,7 +747,6 @@ netcore_lookup_native_library (MonoAssemblyLoadContext *alc, MonoImage *image, c mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "DllImport attempting to load: '%s'.", scope); -#if !TARGET_WASM // We allow a special name to dlopen from the running process namespace, which is not present in CoreCLR if (strcmp (scope, "__Internal") == 0) { if (!internal_module) @@ -761,7 +760,6 @@ netcore_lookup_native_library (MonoAssemblyLoadContext *alc, MonoImage *image, c return module; } -#endif /* * Try these until one of them succeeds: @@ -1059,7 +1057,6 @@ legacy_probe_for_module (MonoImage *image, const char *new_scope) mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_DLLIMPORT, "DllImport attempting to load: '%s'.", new_scope); -#if !defined(TARGET_WASM) /* we allow a special name to dlopen from the running process namespace */ if (strcmp (new_scope, "__Internal") == 0) { if (!internal_module) @@ -1073,7 +1070,6 @@ legacy_probe_for_module (MonoImage *image, const char *new_scope) return module; } -#endif /* * Try loading the module using a variety of names @@ -1266,7 +1262,7 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou addr = pinvoke_probe_for_symbol (module, piinfo, new_import, &error_msg); if (!addr) { -#if !defined(TARGET_WASM) && defined(ENABLE_NETCORE) && !defined(HOST_WIN32) +#if defined(ENABLE_NETCORE) && !defined(HOST_WIN32) if (strcmp (new_scope, "__Internal") == 0) { g_free ((char *)new_scope); new_scope = g_strdup (MONO_LOADER_LIBRARY_NAME); diff --git a/src/mono/netcore/sample/wasm/Program.cs b/src/mono/netcore/sample/wasm/Program.cs index 85a347fe3371fe..7579811aff3031 100644 --- a/src/mono/netcore/sample/wasm/Program.cs +++ b/src/mono/netcore/sample/wasm/Program.cs @@ -8,5 +8,7 @@ public class Test { public static void Main (String[] args) { Console.WriteLine ("Hello, World!"); + var now = DateTime.Now; + Console.WriteLine ("Now: {0}", now); } } diff --git a/src/mono/netcore/sample/wasm/WasmSample.csproj b/src/mono/netcore/sample/wasm/WasmSample.csproj index c84daac2e9f92b..2508e7f1a79745 100644 --- a/src/mono/netcore/sample/wasm/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/WasmSample.csproj @@ -25,7 +25,7 @@ Targets="Build;Publish"/> - @@ -34,12 +34,22 @@ + + + + + + + + + AssemblySearchPaths="@(AssemblySearchPaths)" + AssetSources="@(AssetSources)" + Assets="@(Assets)" /> diff --git a/src/mono/wasm/.editorconfig b/src/mono/wasm/.editorconfig new file mode 100755 index 00000000000000..82b51b609cd8c5 --- /dev/null +++ b/src/mono/wasm/.editorconfig @@ -0,0 +1,13 @@ +# editorconfig.org + +# top-most EditorConfig file +root = false + +# Default settings: +# A newline ending every file +# Use 4 spaces as indentation +[*] +insert_final_newline = true +indent_style = tabs +indent_size = 4 +trim_trailing_whitespace = true \ No newline at end of file diff --git a/src/mono/wasm/Makefile b/src/mono/wasm/Makefile index 63c8c7ef88bc42..df04617812c817 100644 --- a/src/mono/wasm/Makefile +++ b/src/mono/wasm/Makefile @@ -57,10 +57,16 @@ MONO_LIBS = \ $(ICU_LIBDIR)/libicui18n.a ifeq ($(ICU_REPO),) - @echo "ICU_REPO is not set." +$(error ICU_REPO not set!) else - MONO_LIBS := $(MONO_LIBS) $(ICU_REPO)/icu4c/source/wasm-build/lib/{libicui18n.a,libicuio.a,libicuuc.a,libicutu.a} \ - $(ICU_REPO)/icu4c/source/wasm-build/stubdata/libicudata.a +ICU_LIB_DIRECTORY = $(ICU_REPO)/icu4c/source/wasm-build/lib +ICU_STUBDATA_DIRECTORY = $(ICU_REPO)/icu4c/source/wasm-build/stubdata + +MONO_LIBS := $(MONO_LIBS) $(ICU_LIB_DIRECTORY)/libicui18n.a \ +$(ICU_LIB_DIRECTORY)/libicuio.a \ +$(ICU_LIB_DIRECTORY)/libicuuc.a \ +$(ICU_LIB_DIRECTORY)/libicutu.a \ +$(ICU_STUBDATA_DIRECTORY)/libicudata.a endif diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index dfbd2bca32b0db..777bb807a8ab53 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -224,44 +224,49 @@ var Module = { MONO.mono_wasm_load_data (zonedata, "/usr/share/zoneinfo"); } - MONO.mono_load_runtime_and_bcl ( - config.vfs_prefix, - config.deploy_prefix, - config.enable_debugging, - config.assembly_list, - function () { - App.init (); - }, - function (asset) - { - // for testing purposes add BCL assets to VFS until we special case File.Open - // to identify when an assembly from the BCL is being open and resolve it correctly. - var content = new Uint8Array (read (asset, 'binary')); - var path = asset.substr(config.deploy_prefix.length); - writeContentToFile(content, path); - - if (typeof window != 'undefined') { - return fetch (asset, { credentials: 'same-origin' }); - } else { - // The default mono_load_runtime_and_bcl defaults to using - // fetch to load the assets. It also provides a way to set a - // fetch promise callback. - // Here we wrap the file read in a promise and fake a fetch response - // structure. - return new Promise((resolve, reject) => { - var response = { ok: true, url: asset, - arrayBuffer: function() { - return new Promise((resolve2, reject2) => { - resolve2(content); - } - )} - } - resolve(response) - }) - } - } - ); - }, + + config.loaded_cb = function () { + App.init (); + }; + config.fetch_file_cb = function (asset) { + // for testing purposes add BCL assets to VFS until we special case File.Open + // to identify when an assembly from the BCL is being open and resolve it correctly. + var content = new Uint8Array (read (asset, 'binary')); + var path = asset.substr(config.deploy_prefix.length); + writeContentToFile(content, path); + + if (typeof window != 'undefined') { + return fetch (asset, { credentials: 'same-origin' }); + } else { + // The default mono_load_runtime_and_bcl defaults to using + // fetch to load the assets. It also provides a way to set a + // fetch promise callback. + // Here we wrap the file read in a promise and fake a fetch response + // structure. + return new Promise ((resolve, reject) => { + var bytes = null, error = null; + try { + bytes = read (asset, 'binary'); + } catch (exc) { + error = exc; + } + var response = { ok: (bytes && !error), url: asset, + arrayBuffer: function () { + return new Promise ((resolve2, reject2) => { + if (error) + reject2 (error); + else + resolve2 (new Uint8Array (bytes)); + } + )} + } + resolve (response); + }) + } + }; + + MONO.mono_load_runtime_and_bcl_args (config); + }, }; if (typeof window == "undefined") diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c index 8a3cd96c5f0cb8..e8a167b966223a 100644 --- a/src/mono/wasm/runtime/driver.c +++ b/src/mono/wasm/runtime/driver.c @@ -321,10 +321,6 @@ mono_wasm_load_runtime (const char *managed_path, int enable_debugging) // corlib assemblies. monoeg_g_setenv ("COMPlus_DebugWriteToStdErr", "1", 0); #endif -#ifdef ENABLE_NETCORE - if (!getenv("DOTNET_ICU_DIR")) - monoeg_g_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1", 0); -#endif mini_parse_debug_option ("top-runtime-invoke-unhandled"); diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 672eeffed1d8cb..d164bdd5820dea 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -44,11 +44,11 @@ var MonoSupportLib = { decode: function (start, end, save) { if (!MONO.mono_text_decoder) { MONO.mono_text_decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-16le') : undefined; - } + } var str = ""; if (MONO.mono_text_decoder) { - // When threading is enabled, TextDecoder does not accept a view of a + // When threading is enabled, TextDecoder does not accept a view of a // SharedArrayBuffer, we must make a copy of the array first. var subArray = typeof SharedArrayBuffer !== 'undefined' && Module.HEAPU8.buffer instanceof SharedArrayBuffer ? Module.HEAPU8.slice(start, end) @@ -337,12 +337,12 @@ var MonoSupportLib = { var real_obj = this._call_function_res_cache [objectId]; if (args.accessorPropertiesOnly) { // var val_accessors = JSON.stringify ([ - // { - // name: "__proto__", - // get: { type: "function", className: "Function", description: "function get __proto__ () {}", objectId: "dotnet:cfo_res:9999" }, - // set: { type: "function", className: "Function", description: "function set __proto__ () {}", objectId: "dotnet:cfo_res:8888" }, - // isOwn: false - // }], undefined, 4); + // { + // name: "__proto__", + // get: { type: "function", className: "Function", description: "function get __proto__ () {}", objectId: "dotnet:cfo_res:9999" }, + // set: { type: "function", className: "Function", description: "function set __proto__ () {}", objectId: "dotnet:cfo_res:8888" }, + // isOwn: false + // }], undefined, 4); return { __value_as_json_string__: "[]" }; } @@ -480,7 +480,7 @@ var MonoSupportLib = { }, // Set environment variable NAME to VALUE - // Should be called before mono_load_runtime_and_bcl () in most cases + // Should be called before mono_load_runtime_and_bcl () in most cases mono_wasm_setenv: function (name, value) { if (!this.wasm_setenv) this.wasm_setenv = Module.cwrap ('mono_wasm_setenv', null, ['string', 'string']); @@ -536,109 +536,268 @@ var MonoSupportLib = { Module.ccall ('mono_wasm_load_profiler_coverage', null, ['string'], [arg]); }, - mono_load_runtime_and_bcl: function (vfs_prefix, deploy_prefix, enable_debugging, file_list, loaded_cb, fetch_file_cb) { - var pending = file_list.length; + // Initializes the runtime and loads assemblies, debug information, and other files. + // @args is a dictionary-style Object with the following properties: + // vfs_prefix: (required) + // deploy_prefix: (required) + // enable_debugging: (required) + // assembly_list: (required) a list of assemblies and related files to load along + // with the runtime. .pdb files in this list will be treated as optional. + // loaded_cb: (required) a function () invoked when loading has completed. + // fetch_file_cb: (optional) a function (string) invoked to fetch a given file. + // If no callback is provided a default implementation appropriate for the current + // environment will be selected (readFileSync in node, fetch elsewhere). + // If no default implementation is available this call will fail. + // runtime_assets: (optional) a list of asset filenames to load along with the runtime. + // runtime assets are loaded into wasm memory and MONO.loaded_runtime_assets is populated + // with [offset, length] tuples for each asset + // runtime_asset_sources: (optional) additional search locations for runtime assets. + // if no runtime asset sources are provided the default will be ["./"]. + // sources will be checked in sequential order until the asset is found. + // the string "./" indicates to load from the application directory (as with the + // files in assembly_list), and a fully-qualified URL like "https://example.com/" indicates + // that asset loads can be attempted from a remote server. Sources must end with a /. + // environment_variables: (optional) dictionary-style Object containing environment variables + // runtime_options: (optional) array of runtime options as strings + // aot_profiler_options: (optional) dictionary-style Object. see the comments for + // mono_wasm_init_aot_profiler. If omitted, aot profiler will not be initialized. + // coverage_profiler_options: (optional) dictionary-style Object. see the comments for + // mono_wasm_init_coverage_profiler. If omitted, coverage profiler will not be initialized. + // globalization_mode: (optional) configures the runtime's globalization mode: + // "icu": load ICU globalization data from the runtime asset "icudt.dat" + // "invariant": operate in invariant globalization mode. + // "auto" (default): if icudt.dat is present, use ICU, otherwise invariant. + + mono_load_runtime_and_bcl_args: function (args) { + var deploy_prefix = args.deploy_prefix; + var assembly_list = args.assembly_list; + var loaded_cb = args.loaded_cb; + var fetch_file_cb = args.fetch_file_cb; + var runtime_assets = (args.runtime_assets || []); + + if (!assembly_list) + throw new Error ("assembly_list not provided"); + if (!loaded_cb) + throw new Error ("loaded_cb not provided"); + + console.log ("mono_wasm_load_runtime_with_args", JSON.stringify(args)); + + var pending = assembly_list.length + runtime_assets.length; var loaded_files = []; + var loaded_runtime_assets = {}; var mono_wasm_add_assembly = Module.cwrap ('mono_wasm_add_assembly', null, ['string', 'number', 'number']); + for (var k in (args.environment_variables || {})) + this.mono_wasm_setenv (k, args.environment_variables[k]); + + if (args.runtime_options) + this.mono_wasm_set_runtime_options (args.runtime_options); + + if (args.aot_profiler_options) + this.mono_wasm_init_aot_profiler (args.aot_profiler_options); + + if (args.coverage_profiler_options) + this.mono_wasm_init_coverage_profiler (args.coverage_profiler_options); + if (!fetch_file_cb) { if (ENVIRONMENT_IS_NODE) { var fs = require('fs'); fetch_file_cb = function (asset) { - console.log("MONO_WASM: Loading... " + asset); + console.log ("MONO_WASM: Loading... " + asset); var binary = fs.readFileSync (asset); - var resolve_func2 = function(resolve, reject) { - resolve(new Uint8Array (binary)); + var resolve_func2 = function (resolve, reject) { + resolve (new Uint8Array (binary)); }; - var resolve_func1 = function(resolve, reject) { + var resolve_func1 = function (resolve, reject) { var response = { ok: true, url: asset, - arrayBuffer: function() { - return new Promise(resolve_func2); + arrayBuffer: function () { + return new Promise (resolve_func2); } }; - resolve(response); + resolve (response); }; - return new Promise(resolve_func1); + return new Promise (resolve_func1); }; - } else { + } else if (typeof (fetch) === "function") { fetch_file_cb = function (asset) { return fetch (asset, { credentials: 'same-origin' }); } + } else { + throw new Error ("No fetch_file_cb was provided and this environment does not expose 'fetch'."); } } - file_list.forEach (function(file_name) { - - var fetch_promise = fetch_file_cb (locateFile(deploy_prefix + "/" + file_name)); + var onPendingRequestComplete = function () { + --pending; + + if (pending == 0) { + MONO.loaded_files = loaded_files; + MONO.loaded_runtime_assets = loaded_runtime_assets; + + MONO._globalization_init (args, loaded_runtime_assets); + + var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string', 'number']); + + console.log ("MONO_WASM: Initializing mono runtime"); + if (ENVIRONMENT_IS_SHELL || ENVIRONMENT_IS_NODE) { + try { + load_runtime (args.vfs_prefix, args.enable_debugging); + } catch (ex) { + print ("MONO_WASM: load_runtime () failed: " + ex); + var err = new Error(); + print ("MONO_WASM: Stacktrace: \n"); + print (err.stack); + + var wasm_exit = Module.cwrap ('mono_wasm_exit', null, ['number']); + wasm_exit (1); + } + } else { + load_runtime (args.vfs_prefix, args.enable_debugging); + } + MONO.mono_wasm_runtime_ready (); + loaded_cb (); + } + }; + + var runtime_asset_sources = args.runtime_asset_sources || [""]; + + var processFetchResponseBuffer = function (file_name, is_runtime_asset, blob) { + try { + var asm = new Uint8Array (blob); + console.log ("MONO_WASM: Loaded:", file_name, asm.length); + + var memoryOffset = Module._malloc (asm.length); + var heapBytes = new Uint8Array (Module.HEAPU8.buffer, memoryOffset, asm.length); + heapBytes.set (asm); - fetch_promise.then (function (response) { + if (is_runtime_asset) { + loaded_runtime_assets [file_name] = [memoryOffset, asm.length]; + } else { + if (/(\.pdb|\.exe|\.dll)$/.test (file_name)) { + mono_wasm_add_assembly (file_name, memoryOffset, asm.length); + } else { + console.log ("MONO_WASM: Skipping add_assembly for", file_name); + } + } + + onPendingRequestComplete (); + } catch (exc) { + console.log ("Unhandled exception", exc); + } + }; + + runtime_assets.forEach (function (file_name) { + var sourceIndex = 0; + var attemptNextSource; + + var handleFetchResponse = function (file_name, response) { + if (!response.ok) { + attemptNextSource (file_name); + } else { + loaded_files.push (response.url); + var bufferPromise = response ['arrayBuffer'] (); + bufferPromise.then ( + processFetchResponseBuffer.bind (this, file_name, true) + ); + } + }; + + attemptNextSource = function (file_name) { + if (sourceIndex >= runtime_asset_sources.length) { + console.error ("MONO_WASM: Failed to load " + file_name); + --pending; + return; + } + + var sourcePrefix = runtime_asset_sources[sourceIndex]; + sourceIndex++; + + // HACK: Special-case because MSBuild doesn't allow "" as an attribute + if (sourcePrefix === "./") + sourcePrefix = ""; + + var attemptUrl = sourcePrefix + file_name; + + try { + var fetch_promise = fetch_file_cb (attemptUrl); + fetch_promise.then (handleFetchResponse.bind (this, file_name)); + } catch (exc) { + console.error ("MONO_WASM: Error fetching " + attemptUrl, exc); + attemptNextSource (file_name); + } + }; + + attemptNextSource (file_name); + }); + + assembly_list.forEach (function (file_name) { + var handleFetchResponse = function (response) { if (!response.ok) { // If it's a 404 on a .pdb, we don't want to block the app from starting up. // We'll just skip that file and continue (though the 404 is logged in the console). - if (response.status === 404 && file_name.match(/\.pdb$/) && MONO.mono_wasm_ignore_pdb_load_errors) { + if (response.status === 404 && file_name.match (/\.pdb$/) && MONO.mono_wasm_ignore_pdb_load_errors) { --pending; - throw "MONO-WASM: Skipping failed load for .pdb file: '" + file_name + "'"; + throw new Error ("MONO-WASM: Skipping failed load for .pdb file: '" + file_name + "'"); } else { - throw "MONO_WASM: Failed to load file: '" + file_name + "'"; + throw new Error ("MONO_WASM: Failed to load file: '" + file_name + "'"); } } else { loaded_files.push (response.url); return response ['arrayBuffer'] (); } - }).then (function (blob) { - var asm = new Uint8Array (blob); - var memory = Module._malloc(asm.length); - var heapBytes = new Uint8Array(Module.HEAPU8.buffer, memory, asm.length); - heapBytes.set (asm); - mono_wasm_add_assembly (file_name, memory, asm.length); - - //console.log ("MONO_WASM: Loaded: " + file_name); - --pending; - if (pending == 0) { - MONO.loaded_files = loaded_files; - var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string', 'number']); - - console.log ("MONO_WASM: Initializing mono runtime"); - if (ENVIRONMENT_IS_SHELL || ENVIRONMENT_IS_NODE) { - try { - load_runtime (vfs_prefix, enable_debugging); - } catch (ex) { - print ("MONO_WASM: load_runtime () failed: " + ex); - var err = new Error(); - print ("MONO_WASM: Stacktrace: \n"); - print (err.stack); - - var wasm_exit = Module.cwrap ('mono_wasm_exit', null, ['number']); - wasm_exit (1); - } - } else { - load_runtime (vfs_prefix, enable_debugging); - } - MONO.mono_wasm_runtime_ready (); - loaded_cb (); - } - }); + }; + + var fetch_promise = fetch_file_cb (locateFile (deploy_prefix + "/" + file_name)); + + fetch_promise.then (handleFetchResponse) + .then (processFetchResponseBuffer.bind(this, file_name, false)) }); }, + _globalization_init: function (args, assets) { + var invariantMode = false; + + if (args.globalization_mode === "invariant") + invariantMode = true; + + if (!invariantMode) { + var icudt = assets ["icudt.dat"]; + + if (icudt) { + console.log ("MONO_WASM: Loading ICU data archive icudt.dat"); + var mono_wasm_load_icu_data = Module.cwrap ('mono_wasm_load_icu_data', 'number', ['number']); + var result = mono_wasm_load_icu_data (icudt[0]); + if (result !== 1) + console.log ("MONO_WASM: mono_wasm_load_icu_data returned", result); + } else if (args.globalization_mode !== "icu") { + console.log ("MONO_WASM: icudt.dat not present, using invariant globalization mode"); + invariantMode = true; + } else { + console.log ("MONO_WASM: ERROR: icudt.dat not found and invariant globalization mode is inactive."); + } + } + + this.mono_wasm_setenv("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", invariantMode ? "1" : "0"); + }, + mono_wasm_get_loaded_files: function() { console.log(">>>mono_wasm_get_loaded_files"); return this.loaded_files; }, - + mono_wasm_clear_all_breakpoints: function() { if (!this.mono_clear_bps) this.mono_clear_bps = Module.cwrap ('mono_wasm_clear_all_breakpoints', null); this.mono_clear_bps (); }, - + mono_wasm_add_null_var: function(className) { fixed_class_name = MONO._mono_csharp_fixup_class_name(Module.UTF8ToString (className)); diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs index 0b05c5502c0a57..4fa9023715b564 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -29,6 +29,9 @@ public class WasmAppBuilder : Task public ITaskItem[]? AssemblySearchPaths { get; set; } public ITaskItem[]? ExtraAssemblies { get; set; } public ITaskItem[]? FilesToIncludeInFileSystem { get; set; } + public ITaskItem[]? AssetSources { get; set; } + public ITaskItem[]? Assets { get; set; } + Dictionary? _assemblies; Resolver? _resolver; @@ -144,7 +147,20 @@ public override bool Execute () sw.WriteLine("\t},"); } sw.WriteLine ("\t],"); - sw.WriteLine ("}"); + + if (AssetSources!.Length > 0) { + sw.WriteLine("\truntime_asset_sources: ["); + foreach (var source in AssetSources!) + sw.WriteLine("\t\t\"" + source.ItemSpec + "\", "); + sw.WriteLine ("],"); + } + if (Assets!.Length > 0) { + sw.WriteLine("\truntime_assets: ["); + foreach (var asset in Assets!) + sw.WriteLine("\t\t\"" + asset.ItemSpec + "\", "); + sw.WriteLine ("],"); + } + sw.WriteLine ("};"); } using (var sw = File.CreateText(Path.Join(AppDir, "run-v8.sh"))) From b3e2325ba4911ac6ea0d6d9dc9418b130d7d6517 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 2 Jul 2020 13:49:33 +0300 Subject: [PATCH 04/62] Add stubs for tz and calendar, enable tests --- eng/testing/tests.mobile.targets | 9 ++++-- .../Interop.Calendar.EnumCalendarInfo.Stub.cs | 15 ++++++++++ .../Interop.Calendar.EnumCalendarInfo.cs | 16 +++++++++++ .../Common/src/Interop/Interop.Calendar.cs | 3 -- .../src/Interop/Interop.TimeZoneInfo.Stub.cs | 28 +++++++++++++++++++ .../System.Private.CoreLib.Shared.projitems | 11 +++++++- src/libraries/tests.proj | 9 +++--- 7 files changed, 81 insertions(+), 10 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.Stub.cs create mode 100644 src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.cs create mode 100644 src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Stub.cs diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index ebefed0e7e9600..73349b6d6a442c 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -139,8 +139,9 @@ + + - + AssemblySearchPaths="@(AssemblySearchPaths)" + AssetSources="@(AssetSources)" + Assets="@(Assets)" /> + false; + } +} diff --git a/src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.cs b/src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.cs new file mode 100644 index 00000000000000..220dc6c36f6dc6 --- /dev/null +++ b/src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Globalization; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Globalization + { + [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")] + internal static extern bool EnumCalendarInfo(EnumCalendarInfoCallback callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context); + } +} diff --git a/src/libraries/Common/src/Interop/Interop.Calendar.cs b/src/libraries/Common/src/Interop/Interop.Calendar.cs index 494648f1b1ce35..de9d6fcafc0730 100644 --- a/src/libraries/Common/src/Interop/Interop.Calendar.cs +++ b/src/libraries/Common/src/Interop/Interop.Calendar.cs @@ -19,9 +19,6 @@ internal delegate void EnumCalendarInfoCallback( [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendarInfo")] internal static extern unsafe ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, char* result, int resultCapacity); - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")] - internal static extern bool EnumCalendarInfo(EnumCalendarInfoCallback callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context); - [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")] internal static extern int GetLatestJapaneseEra(); diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Stub.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Stub.cs new file mode 100644 index 00000000000000..d5f51f70658861 --- /dev/null +++ b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Stub.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Globalization + { + // needs to be kept in sync with TimeZoneDisplayNameType in System.Globalization.Native + internal enum TimeZoneDisplayNameType + { + Generic = 0, + Standard = 1, + DaylightSavings = 2, + } + + // Mono-WASM specific ICU doesn't contain timezone bits + // so an english fallback will be used instead. + internal static unsafe ResultCode GetTimeZoneDisplayName( + string localeName, + string timeZoneId, + TimeZoneDisplayNameType type, + char* result, + int resultLength) => ResultCode.UnknownError; + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index a5422abee6b597..7e4d76b0a81cc7 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1046,6 +1046,12 @@ Common\Interop\Interop.Calendar.cs + + Common\Interop\Interop.Calendar.EnumCalendarInfo.cs + + + Common\Interop\Interop.Calendar.EnumCalendarInfo.Stub.cs + Common\Interop\Interop.Casing.cs @@ -1067,9 +1073,12 @@ Common\Interop\Interop.ResultCode.cs - + Common\Interop\Interop.TimeZoneInfo.cs + + Common\Interop\Interop.TimeZoneInfo.Stub.cs + Common\Interop\Interop.Utils.cs diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index ae20da8031b231..1a87acf88645d1 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -29,6 +29,7 @@ + @@ -40,15 +41,14 @@ + - - - - + + @@ -81,6 +81,7 @@ + From ca353634569300ae905e4f8124473e8d916cb75c Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Thu, 2 Jul 2020 13:51:50 +0300 Subject: [PATCH 05/62] Update System.Private.CoreLib.Shared.projitems --- .../src/System.Private.CoreLib.Shared.projitems | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 7e4d76b0a81cc7..0ba14f23d67967 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1049,7 +1049,7 @@ Common\Interop\Interop.Calendar.EnumCalendarInfo.cs - + Common\Interop\Interop.Calendar.EnumCalendarInfo.Stub.cs From 72078b9489d113cdbe8821319f873616640d4ac7 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Fri, 10 Jul 2020 23:49:14 +0300 Subject: [PATCH 06/62] Fix EnumCalendarInfo for wasm (temp workaround) --- .../Interop.Calendar.EnumCalendarInfo.Stub.cs | 15 --------------- .../Interop/Interop.Calendar.EnumCalendarInfo.cs | 16 ---------------- .../Common/src/Interop/Interop.Calendar.cs | 12 +++++++++++- .../pal_icushim_static.c | 12 ++++++++++++ .../src/System.Private.CoreLib.Shared.projitems | 6 ------ .../src/System/Globalization/CalendarData.Icu.cs | 9 ++++++++- src/libraries/tests.proj | 3 +++ 7 files changed, 34 insertions(+), 39 deletions(-) delete mode 100644 src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.Stub.cs delete mode 100644 src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.cs diff --git a/src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.Stub.cs b/src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.Stub.cs deleted file mode 100644 index 6b27efdf1dd42a..00000000000000 --- a/src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.Stub.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Globalization; - -internal static partial class Interop -{ - internal static partial class Globalization - { - // Mono-WASM doesn't support managed callbacks for pinvokes yet - internal static bool EnumCalendarInfo(EnumCalendarInfoCallback callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context) => false; - } -} diff --git a/src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.cs b/src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.cs deleted file mode 100644 index 220dc6c36f6dc6..00000000000000 --- a/src/libraries/Common/src/Interop/Interop.Calendar.EnumCalendarInfo.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Globalization; -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Globalization - { - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")] - internal static extern bool EnumCalendarInfo(EnumCalendarInfoCallback callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context); - } -} diff --git a/src/libraries/Common/src/Interop/Interop.Calendar.cs b/src/libraries/Common/src/Interop/Interop.Calendar.cs index de9d6fcafc0730..6671c8a4728747 100644 --- a/src/libraries/Common/src/Interop/Interop.Calendar.cs +++ b/src/libraries/Common/src/Interop/Interop.Calendar.cs @@ -10,7 +10,7 @@ internal static partial class Interop internal static partial class Globalization { internal delegate void EnumCalendarInfoCallback( - [MarshalAs(UnmanagedType.LPWStr)] string calendarString, + char* calendarString, IntPtr context); [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendars")] @@ -19,6 +19,16 @@ internal delegate void EnumCalendarInfoCallback( [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetCalendarInfo")] internal static extern unsafe ResultCode GetCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType calendarDataType, char* result, int resultCapacity); +#if TARGET_BROWSER + // Temp workaround for pinvoke callbacks for Mono-Wasm-Interpreter + // https://github.com/dotnet/runtime/issues/39100 + [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")] + internal static extern bool EnumCalendarInfo(IntPtr callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context); +#else + [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_EnumCalendarInfo")] + internal static extern bool EnumCalendarInfo(EnumCalendarInfoCallback callback, string localeName, CalendarId calendarId, CalendarDataType calendarDataType, IntPtr context); +#endif + [DllImport(Libraries.GlobalizationNative, EntryPoint = "GlobalizationNative_GetLatestJapaneseEra")] internal static extern int GetLatestJapaneseEra(); diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c index 69f3723883a59f..63735bdd98b50b 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c @@ -9,12 +9,20 @@ #include "pal_icushim.h" #include #include +#include +#include static void log_icu_error (const char * name, UErrorCode status) { const char * statusText = u_errorName(status); fprintf(stderr, "ICU call %s failed with error #%d '%s'.\n", name, status, statusText); } +static void U_CALLCONV icu_trace_data (const void *context, int32_t fnNumber, int32_t level, const char *fmt, va_list args) { + char buf [1000]; + utrace_vformat (buf, sizeof (buf), 0, fmt, args); + printf ("[ICUDT] %s: %s\n", utrace_functionName (fnNumber), buf); +} + #ifdef __EMSCRIPTEN__ #include @@ -28,6 +36,10 @@ EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data (void * pData) { log_icu_error("udata_setCommonData", status); return 0; } else { + //// Uncomment to enable ICU tracing, + //// see https://github.com/unicode-org/icu/blob/master/docs/userguide/icu_data/tracing.md + // utrace_setFunctions(0, 0, 0, icu_trace_data); + // utrace_setLevel(UTRACE_VERBOSE); return 1; } } diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 0ba14f23d67967..74616d48074e79 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1046,12 +1046,6 @@ Common\Interop\Interop.Calendar.cs - - Common\Interop\Interop.Calendar.EnumCalendarInfo.cs - - - Common\Interop\Interop.Calendar.EnumCalendarInfo.Stub.cs - Common\Interop\Interop.Casing.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs index aa3f12a4c29c6d..efb1ca05334f15 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs @@ -424,13 +424,20 @@ internal static bool EnumCalendarInfo(string localeName, CalendarId calendarId, private static unsafe bool EnumCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, ref IcuEnumCalendarsData callbackContext) { +#if TARGET_BROWSER + // Temp workaround for pinvoke callbacks for Mono-Wasm-Interpreter + // https://github.com/dotnet/runtime/issues/39100 + return Interop.Globalization.EnumCalendarInfo(Marshal.GetFunctionPointerForDelegate(EnumCalendarInfoCallback), localeName, calendarId, dataType, (IntPtr)Unsafe.AsPointer(ref callbackContext)); +#else return Interop.Globalization.EnumCalendarInfo(EnumCalendarInfoCallback, localeName, calendarId, dataType, (IntPtr)Unsafe.AsPointer(ref callbackContext)); +#endif } - private static unsafe void EnumCalendarInfoCallback(string calendarString, IntPtr context) + private static unsafe void EnumCalendarInfoCallback(char* calendarStringPtr, IntPtr context) { try { + var calendarString = new string(calendarStringPtr); ref IcuEnumCalendarsData callbackContext = ref Unsafe.As(ref *(byte*)context); if (callbackContext.DisallowDuplicates) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 9d885854f756b1..054081aa6e2e09 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -38,10 +38,13 @@ + + + From 901c499158a61a7ae4ab28fdf6f949b247694206 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 13 Jul 2020 08:20:55 +0300 Subject: [PATCH 07/62] cccc --- .../src/System/Globalization/CalendarData.Icu.cs | 12 ++++++++---- .../System.Private.CoreLib.csproj | 1 + .../src/Mono/MonoPInvokeCallbackAttribute.cs | 11 +++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/mono/netcore/System.Private.CoreLib/src/Mono/MonoPInvokeCallbackAttribute.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs index efb1ca05334f15..091f019bfc4d7c 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs @@ -422,17 +422,21 @@ internal static bool EnumCalendarInfo(string localeName, CalendarId calendarId, return result; } +#if !TARGET_BROWSER + private static unsafe bool EnumCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, ref IcuEnumCalendarsData callbackContext) + { + return Interop.Globalization.EnumCalendarInfo(EnumCalendarInfoCallback, localeName, calendarId, dataType, (IntPtr)Unsafe.AsPointer(ref callbackContext)); + } +#else private static unsafe bool EnumCalendarInfo(string localeName, CalendarId calendarId, CalendarDataType dataType, ref IcuEnumCalendarsData callbackContext) { -#if TARGET_BROWSER // Temp workaround for pinvoke callbacks for Mono-Wasm-Interpreter // https://github.com/dotnet/runtime/issues/39100 return Interop.Globalization.EnumCalendarInfo(Marshal.GetFunctionPointerForDelegate(EnumCalendarInfoCallback), localeName, calendarId, dataType, (IntPtr)Unsafe.AsPointer(ref callbackContext)); -#else - return Interop.Globalization.EnumCalendarInfo(EnumCalendarInfoCallback, localeName, calendarId, dataType, (IntPtr)Unsafe.AsPointer(ref callbackContext)); -#endif } + [Mono.MonoPInvokeCallback(typeof(Interop.Globalization.EnumCalendarInfoCallback))] +#endif private static unsafe void EnumCalendarInfoCallback(char* calendarStringPtr, IntPtr context) { try diff --git a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj index 2eb2ec324e1f13..41c29ffa4c69e0 100644 --- a/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/netcore/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -160,6 +160,7 @@ + diff --git a/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoPInvokeCallbackAttribute.cs b/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoPInvokeCallbackAttribute.cs new file mode 100644 index 00000000000000..c0d911b14f3556 --- /dev/null +++ b/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoPInvokeCallbackAttribute.cs @@ -0,0 +1,11 @@ + +using System; + +namespace Mono +{ + [AttributeUsage(AttributeTargets.Method)] + internal sealed class MonoPInvokeCallbackAttribute : Attribute + { + public MonoPInvokeCallbackAttribute(Type type) {} + } +} From bf6587a582639a55b464fea2a914db51212d298e Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 13 Jul 2020 12:49:21 +0300 Subject: [PATCH 08/62] Fix small issues --- src/libraries/Common/src/Interop/Interop.Calendar.cs | 2 +- .../src/System/Globalization/CalendarData.Icu.cs | 5 ++++- .../src/Mono/MonoPInvokeCallbackAttribute.cs | 1 - .../mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs | 7 ++++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/libraries/Common/src/Interop/Interop.Calendar.cs b/src/libraries/Common/src/Interop/Interop.Calendar.cs index 6671c8a4728747..9be426d367a6e4 100644 --- a/src/libraries/Common/src/Interop/Interop.Calendar.cs +++ b/src/libraries/Common/src/Interop/Interop.Calendar.cs @@ -9,7 +9,7 @@ internal static partial class Interop { internal static partial class Globalization { - internal delegate void EnumCalendarInfoCallback( + internal unsafe delegate void EnumCalendarInfoCallback( char* calendarString, IntPtr context); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs index 091f019bfc4d7c..cdb550d5d245ee 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs @@ -432,7 +432,10 @@ private static unsafe bool EnumCalendarInfo(string localeName, CalendarId calend { // Temp workaround for pinvoke callbacks for Mono-Wasm-Interpreter // https://github.com/dotnet/runtime/issues/39100 - return Interop.Globalization.EnumCalendarInfo(Marshal.GetFunctionPointerForDelegate(EnumCalendarInfoCallback), localeName, calendarId, dataType, (IntPtr)Unsafe.AsPointer(ref callbackContext)); + var calendarInfoCallback = new Interop.Globalization.EnumCalendarInfoCallback(EnumCalendarInfoCallback); + return Interop.Globalization.EnumCalendarInfo( + System.Runtime.InteropServices.Marshal.GetFunctionPointerForDelegate(calendarInfoCallback), + localeName, calendarId, dataType, (IntPtr)Unsafe.AsPointer(ref callbackContext)); } [Mono.MonoPInvokeCallback(typeof(Interop.Globalization.EnumCalendarInfoCallback))] diff --git a/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoPInvokeCallbackAttribute.cs b/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoPInvokeCallbackAttribute.cs index c0d911b14f3556..dbdc8fdead8415 100644 --- a/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoPInvokeCallbackAttribute.cs +++ b/src/mono/netcore/System.Private.CoreLib/src/Mono/MonoPInvokeCallbackAttribute.cs @@ -1,4 +1,3 @@ - using System; namespace Mono diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs index 7523894f961859..a1a5cc81fa81c5 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs @@ -172,10 +172,11 @@ void EmitNativeToInterp(StreamWriter w, List callbacks) w.WriteLine("InterpFtnDesc wasm_native_to_interp_ftndescs[" + callbacks.Count + "];"); foreach (var cb in callbacks) { - var method = cb.Method; + MethodInfo method = cb.Method; + bool isVoid = method.ReturnType.FullName == "System.Void"; - if (method.ReturnType != typeof(void) && !IsBlittable(method.ReturnType)) - Error("The return type of pinvoke callback method '" + method + "' needs to be blittable."); + if (!isVoid && !IsBlittable(method.ReturnType)) + Error($"The returnnn type '{method.ReturnType.FullName}' ('{isVoid}') of pinvoke callback method '{method}' needs to be blittable."); foreach (var p in method.GetParameters()) { if (!IsBlittable(p.ParameterType)) Error("Parameter types of pinvoke callback method '" + method + "' needs to be blittable."); From 39c315ab7bb33e598e5a2ae1d646870dbd539238 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 13 Jul 2020 13:18:52 +0300 Subject: [PATCH 09/62] drop ICU_REPO --- eng/testing/tests.mobile.targets | 2 +- src/mono/mono.proj | 2 +- src/mono/mono/metadata/Makefile.am | 26 ------ src/mono/netcore/sample/wasm/Program.cs | 79 ++++++++++++++++--- .../netcore/sample/wasm/WasmSample.csproj | 2 + src/mono/wasm/Makefile | 17 +--- 6 files changed, 75 insertions(+), 53 deletions(-) diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index 73349b6d6a442c..392c37cd893c0a 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -153,7 +153,7 @@ AssemblySearchPaths="@(AssemblySearchPaths)" AssetSources="@(AssetSources)" Assets="@(Assets)" /> - diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 2396885e514df0..502e2176adf21a 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -643,7 +643,7 @@ <_MonoConfigureParams Include="--disable-icall-tables"/> <_MonoConfigureParams Include="--disable-crash-reporting"/> <_MonoConfigureParams Include="--with-bitcode=yes"/> - <_MonoConfigureParams Condition="'$(ICU_REPO)' != ''" Include="--with-static-icu=yes"/> + <_MonoConfigureParams Include="--with-static-icu=yes"/> <_MonoConfigureParams Include="--enable-minimal=ssa,com,jit,reflection_emit_save,portability,assembly_remapping,attach,verifier,full_messages,appdomains,shadowcopy,security,sgen_marksweep_conc,sgen_split_nursery,sgen_gc_bridge,logging,remoting,shared_perfcounters,sgen_debug_helpers,soft_debug,interpreter,assert_messages,cleanup,mdb,gac,threads,$(_MonoEnableMinimal)"/> <_MonoCFLAGS Include="-fexceptions" /> <_MonoCFLAGS Include="-I$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)/runtimes/browser-wasm/native/include" /> diff --git a/src/mono/mono/metadata/Makefile.am b/src/mono/mono/metadata/Makefile.am index 9716b153d85f99..06abdd51ab2b41 100644 --- a/src/mono/mono/metadata/Makefile.am +++ b/src/mono/mono/metadata/Makefile.am @@ -159,35 +159,9 @@ nodist_libmonoruntime_shimglobalization_la_SOURCES = \ libmonoruntime_shimglobalization_la_CFLAGS = @ICU_CFLAGS@ -I$(top_srcdir)/../libraries/Native/Unix/System.Globalization.Native/ -I$(top_srcdir)/../libraries/Native/Unix/Common/ if STATIC_ICU - -ICU_INCLUDE_DIRECTORY = $(ICU_REPO)/icu4c/source/wasm-usr/include/ -ICU_LIB_DIRECTORY = $(ICU_REPO)/icu4c/source/wasm-build/lib/ -ICU_STUBDATA_DIRECTORY = $(ICU_REPO)/icu4c/source/wasm-build/stubdata - -# Check for the existence of the include and lib directories. -# If they are missing we will get confusing errors later, so fail-fast is best. - -# The conditionals need a space before them to bypass automake's broken parser -# and reach gnu make to be evaluated. see https://patchwork.kernel.org/patch/6709921/ - ifeq (,$(wildcard $(ICU_INCLUDE_DIRECTORY))) -$(error ICU include directory $(ICU_INCLUDE_DIRECTORY) does not exist) - endif - ifeq (,$(wildcard $(ICU_LIB_DIRECTORY))) -$(error ICU lib directory $(ICU_LIB_DIRECTORY) does not exist) - endif - ifeq (,$(wildcard $(ICU_STUBDATA_DIRECTORY))) -$(error ICU lib directory $(ICU_STUBDATA_DIRECTORY) does not exist) - endif - nodist_libmonoruntime_shimglobalization_la_SOURCES += @ICU_SHIM_PATH@/pal_icushim_static.c -libmonoruntime_shimglobalization_la_CFLAGS += -I$(ICU_INCLUDE_DIRECTORY) \ --L$(ICU_LIB_DIRECTORY) -licui18n -licuuc -licutu -licuio \ --L$(ICU_STUBDATA_DIRECTORY) -licudata - else - nodist_libmonoruntime_shimglobalization_la_SOURCES += @ICU_SHIM_PATH@/pal_icushim.c - endif # STATIC_ICU endif # HAVE_SYS_ICU diff --git a/src/mono/netcore/sample/wasm/Program.cs b/src/mono/netcore/sample/wasm/Program.cs index 7579811aff3031..82a4002b10d976 100644 --- a/src/mono/netcore/sample/wasm/Program.cs +++ b/src/mono/netcore/sample/wasm/Program.cs @@ -1,14 +1,73 @@ -// -*- indent-tabs-mode: nil -*- -// 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.Globalization; +using System.Threading; -public class Test +public class Cx { - public static void Main (String[] args) { - Console.WriteLine ("Hello, World!"); - var now = DateTime.Now; - Console.WriteLine ("Now: {0}", now); + static void Main() + { + Type.GetType("System.Console, System.Console").GetMethod("WriteLine", new[] {typeof(string)}) + .Invoke(null, new[] {"hello"}); + + var cculture = new CultureInfo("ru-RU"); + Thread.CurrentThread.CurrentCulture = cculture; + Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; + + Console.WriteLine("\nTime:"); + Console.WriteLine(DateTime.Now.ToLongDateString()); + Console.WriteLine(DateTime.Now.ToLongTimeString()); + + Console.WriteLine("\nCulture:"); + Console.WriteLine(cculture.DisplayName); + Console.WriteLine(cculture.EnglishName); + Console.WriteLine(cculture.NativeName); + Console.WriteLine(cculture.ThreeLetterWindowsLanguageName); + Console.WriteLine(cculture.ThreeLetterISOLanguageName); + Console.WriteLine(cculture.TwoLetterISOLanguageName); + Console.WriteLine(cculture.IetfLanguageTag); + Console.WriteLine(string.Join(";", cculture.DateTimeFormat.DayNames)); + Console.WriteLine(string.Join(";", cculture.DateTimeFormat.MonthNames)); + Console.WriteLine(string.Join(";", cculture.DateTimeFormat.MonthGenitiveNames)); + Console.WriteLine(string.Join(";", cculture.DateTimeFormat.ShortestDayNames)); + Console.WriteLine(string.Join(";", cculture.DateTimeFormat.GetAllDateTimePatterns())); + Console.WriteLine(cculture.DateTimeFormat.TimeSeparator); + Console.WriteLine(cculture.DateTimeFormat.AbbreviatedDayNames); + Console.WriteLine(cculture.DateTimeFormat.AbbreviatedMonthNames); + Console.WriteLine(cculture.DateTimeFormat.AMDesignator); + Console.WriteLine(cculture.DateTimeFormat.LongDatePattern); + Console.WriteLine(cculture.DateTimeFormat.LongTimePattern); + Console.WriteLine(cculture.DateTimeFormat.MonthDayPattern); + Console.WriteLine(cculture.IetfLanguageTag); + + Console.WriteLine("\nCurrency:"); + Console.WriteLine(cculture.NumberFormat.CurrencySymbol); + Console.WriteLine(cculture.NumberFormat.CurrencyDecimalSeparator); + Console.WriteLine(cculture.NumberFormat.CurrencyGroupSeparator); + Console.WriteLine(cculture.NumberFormat.CurrencyDecimalDigits); + Console.WriteLine(string.Join(";", cculture.NumberFormat.CurrencyGroupSizes)); + Console.WriteLine(cculture.NumberFormat.CurrencyNegativePattern); + Console.WriteLine(cculture.NumberFormat.CurrencyPositivePattern); + + + Console.WriteLine("\nRegionInfo:"); + var zone = new RegionInfo(cculture.LCID); + Console.WriteLine(zone.NativeName); + Console.WriteLine(zone.DisplayName); + Console.WriteLine(zone.CurrencyEnglishName); + Console.WriteLine(zone.CurrencyNativeName); + + Console.WriteLine(100000000.ToString("C", new CultureInfo("ru-RU"))); + Console.WriteLine(3.14.ToString(cculture)); + + + foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures)) + { + var str = "\"" + culture.Name + "\","; + str = str.Replace('-', '_'); + if (!str.Contains("_")) + continue; + + //Console.WriteLine(str.PadRight(16, ' '));// + "// " + culture.EnglishName); + } } -} +} \ No newline at end of file diff --git a/src/mono/netcore/sample/wasm/WasmSample.csproj b/src/mono/netcore/sample/wasm/WasmSample.csproj index 2508e7f1a79745..cfb12f56c84d5f 100644 --- a/src/mono/netcore/sample/wasm/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/WasmSample.csproj @@ -42,6 +42,8 @@ + Date: Mon, 13 Jul 2020 13:24:14 +0300 Subject: [PATCH 10/62] Update Program.cs --- src/mono/netcore/sample/wasm/Program.cs | 72 +++---------------------- 1 file changed, 7 insertions(+), 65 deletions(-) diff --git a/src/mono/netcore/sample/wasm/Program.cs b/src/mono/netcore/sample/wasm/Program.cs index 82a4002b10d976..8ecfb758338a17 100644 --- a/src/mono/netcore/sample/wasm/Program.cs +++ b/src/mono/netcore/sample/wasm/Program.cs @@ -1,73 +1,15 @@ +// 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.Globalization; using System.Threading; -public class Cx +public class Test { - static void Main() + public static void Main(String[] args) { - Type.GetType("System.Console, System.Console").GetMethod("WriteLine", new[] {typeof(string)}) - .Invoke(null, new[] {"hello"}); - - var cculture = new CultureInfo("ru-RU"); - Thread.CurrentThread.CurrentCulture = cculture; - Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; - - Console.WriteLine("\nTime:"); + Console.WriteLine("Hello, World!"); Console.WriteLine(DateTime.Now.ToLongDateString()); - Console.WriteLine(DateTime.Now.ToLongTimeString()); - - Console.WriteLine("\nCulture:"); - Console.WriteLine(cculture.DisplayName); - Console.WriteLine(cculture.EnglishName); - Console.WriteLine(cculture.NativeName); - Console.WriteLine(cculture.ThreeLetterWindowsLanguageName); - Console.WriteLine(cculture.ThreeLetterISOLanguageName); - Console.WriteLine(cculture.TwoLetterISOLanguageName); - Console.WriteLine(cculture.IetfLanguageTag); - Console.WriteLine(string.Join(";", cculture.DateTimeFormat.DayNames)); - Console.WriteLine(string.Join(";", cculture.DateTimeFormat.MonthNames)); - Console.WriteLine(string.Join(";", cculture.DateTimeFormat.MonthGenitiveNames)); - Console.WriteLine(string.Join(";", cculture.DateTimeFormat.ShortestDayNames)); - Console.WriteLine(string.Join(";", cculture.DateTimeFormat.GetAllDateTimePatterns())); - Console.WriteLine(cculture.DateTimeFormat.TimeSeparator); - Console.WriteLine(cculture.DateTimeFormat.AbbreviatedDayNames); - Console.WriteLine(cculture.DateTimeFormat.AbbreviatedMonthNames); - Console.WriteLine(cculture.DateTimeFormat.AMDesignator); - Console.WriteLine(cculture.DateTimeFormat.LongDatePattern); - Console.WriteLine(cculture.DateTimeFormat.LongTimePattern); - Console.WriteLine(cculture.DateTimeFormat.MonthDayPattern); - Console.WriteLine(cculture.IetfLanguageTag); - - Console.WriteLine("\nCurrency:"); - Console.WriteLine(cculture.NumberFormat.CurrencySymbol); - Console.WriteLine(cculture.NumberFormat.CurrencyDecimalSeparator); - Console.WriteLine(cculture.NumberFormat.CurrencyGroupSeparator); - Console.WriteLine(cculture.NumberFormat.CurrencyDecimalDigits); - Console.WriteLine(string.Join(";", cculture.NumberFormat.CurrencyGroupSizes)); - Console.WriteLine(cculture.NumberFormat.CurrencyNegativePattern); - Console.WriteLine(cculture.NumberFormat.CurrencyPositivePattern); - - - Console.WriteLine("\nRegionInfo:"); - var zone = new RegionInfo(cculture.LCID); - Console.WriteLine(zone.NativeName); - Console.WriteLine(zone.DisplayName); - Console.WriteLine(zone.CurrencyEnglishName); - Console.WriteLine(zone.CurrencyNativeName); - - Console.WriteLine(100000000.ToString("C", new CultureInfo("ru-RU"))); - Console.WriteLine(3.14.ToString(cculture)); - - - foreach (var culture in CultureInfo.GetCultures(CultureTypes.AllCultures)) - { - var str = "\"" + culture.Name + "\","; - str = str.Replace('-', '_'); - if (!str.Contains("_")) - continue; - - //Console.WriteLine(str.PadRight(16, ' '));// + "// " + culture.EnglishName); - } } -} \ No newline at end of file +} From e2a57ffc7029ed513053e869031377e188d722aa Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 13 Jul 2020 13:29:56 +0300 Subject: [PATCH 11/62] clean up --- src/libraries/tests.proj | 2 -- src/mono/wasm/wasm.targets | 1 - .../tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index cb09293ea63d5e..8a7b0b3f15a2c2 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -33,7 +33,6 @@ - @@ -41,7 +40,6 @@ - diff --git a/src/mono/wasm/wasm.targets b/src/mono/wasm/wasm.targets index 20f6bae9e67969..1a1a6d80f21144 100644 --- a/src/mono/wasm/wasm.targets +++ b/src/mono/wasm/wasm.targets @@ -13,7 +13,6 @@ - diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs index a1a5cc81fa81c5..aea33760c8d9ce 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs @@ -176,7 +176,7 @@ void EmitNativeToInterp(StreamWriter w, List callbacks) bool isVoid = method.ReturnType.FullName == "System.Void"; if (!isVoid && !IsBlittable(method.ReturnType)) - Error($"The returnnn type '{method.ReturnType.FullName}' ('{isVoid}') of pinvoke callback method '{method}' needs to be blittable."); + Error($"The return type '{method.ReturnType.FullName}' ('{isVoid}') of pinvoke callback method '{method}' needs to be blittable."); foreach (var p in method.GetParameters()) { if (!IsBlittable(p.ParameterType)) Error("Parameter types of pinvoke callback method '" + method + "' needs to be blittable."); From f77ad54bce65b5857ad86124b1f8d0c19d59b594 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 13 Jul 2020 13:42:36 +0300 Subject: [PATCH 12/62] Update tests.proj --- src/libraries/tests.proj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index 8a7b0b3f15a2c2..ca933997673cdd 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -33,13 +33,7 @@ - - - - - - From 529e8e1e43f3614726782a9dfed4a9c59158a1db Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 13 Jul 2020 13:43:58 +0300 Subject: [PATCH 13/62] Update Program.cs --- src/mono/netcore/sample/wasm/Program.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/mono/netcore/sample/wasm/Program.cs b/src/mono/netcore/sample/wasm/Program.cs index 8ecfb758338a17..c65e90fdf494e4 100644 --- a/src/mono/netcore/sample/wasm/Program.cs +++ b/src/mono/netcore/sample/wasm/Program.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System; -using System.Globalization; -using System.Threading; public class Test { From c0fb094d7237b43a814249f5ee2b3223f1d0884f Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 13 Jul 2020 13:51:26 +0300 Subject: [PATCH 14/62] Update tests.proj --- src/libraries/tests.proj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index ca933997673cdd..9b2d8f687d2006 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -33,7 +33,11 @@ + + + + From 9698771e439fd4e3f17d5ace27532a466597c5dc Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Mon, 13 Jul 2020 20:55:12 -0700 Subject: [PATCH 15/62] Checkpoint --- .../pal_icushim_static.c | 9 +- src/mono/wasm/runtime/library_mono.js | 306 ++++++++++-------- 2 files changed, 172 insertions(+), 143 deletions(-) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c index 63735bdd98b50b..a9c1f05c1ddb5f 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c @@ -54,12 +54,13 @@ int32_t GlobalizationNative_LoadICU(void) ; // default ICU search path behavior will be used, see http://userguide.icu-project.org/icudata UErrorCode status = 0; - // Invoking u_init will probe to see if ICU common data is already available and if it is missing, - // attempt to load it from the local filesystem. - u_init(&status); + UVersionInfo version; + // Request the CLDR version to perform basic ICU initialization and find out + // whether it worked. + ulocdata_getCLDRVersion(version, &status); if (U_FAILURE(status)) { - log_icu_error("u_init", status); + log_icu_error("ulocdata_getCLDRVersion", status); return 0; } diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index d164bdd5820dea..a8d0f68ae68dc3 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -536,27 +536,124 @@ var MonoSupportLib = { Module.ccall ('mono_wasm_load_profiler_coverage', null, ['string'], [arg]); }, + _apply_configuration_from_args: function (args) { + for (var k in (args.environment_variables || {})) + MONO.mono_wasm_setenv (k, args.environment_variables[k]); + + if (args.runtime_options) + MONO.mono_wasm_set_runtime_options (args.runtime_options); + + if (args.aot_profiler_options) + MONO.mono_wasm_init_aot_profiler (args.aot_profiler_options); + + if (args.coverage_profiler_options) + MONO.mono_wasm_init_coverage_profiler (args.coverage_profiler_options); + }, + + _get_fetch_file_cb_from_args: function (args) { + if (typeof (args.fetch_file_cb) === "function") + return args.fetch_file_cb; + + if (ENVIRONMENT_IS_NODE) { + var fs = require('fs'); + return function (asset) { + console.log ("MONO_WASM: Loading... " + asset); + var binary = fs.readFileSync (asset); + var resolve_func2 = function (resolve, reject) { + resolve (new Uint8Array (binary)); + }; + + var resolve_func1 = function (resolve, reject) { + var response = { + ok: true, + url: asset, + arrayBuffer: function () { + return new Promise (resolve_func2); + } + }; + resolve (response); + }; + + return new Promise (resolve_func1); + }; + } else if (typeof (fetch) === "function") { + return function (asset) { + return fetch (asset, { credentials: 'same-origin' }); + }; + } else { + throw new Error ("No fetch_file_cb was provided and this environment does not expose 'fetch'."); + } + }, + + _load_bytes_into_heap: function (bytes) { + var memoryOffset = Module._malloc (bytes.length); + var heapBytes = new Uint8Array (Module.HEAPU8.buffer, memoryOffset, bytes.length); + heapBytes.set (bytes); + return memoryOffset; + }, + + _handle_loaded_asset: function (ctx, asset, blob) { + var bytes = new Uint8Array (blob); + console.log ("MONO_WASM: Loaded:", asset.name, bytes.length); + + var virtualName = asset.virtual_path || asset.name; + var offset = null; + + switch (asset.behavior) { + case "heap": + case "assembly": + case "icu": + offset = this._load_bytes_into_heap (bytes); + ctx.loaded_assets[virtualName] = [offset, bytes.length]; + break; + + case "vfs": + // FIXME + throw new Error ("Unimplemented behavior: vfs"); + break; + + default: + throw new Error ("Unrecognized asset behavior:", asset.behavior); + } + + if (asset.behavior === "assembly") + ctx.mono_wasm_add_assembly (virtualName, offset, bytes.length); + else if (asset.behavior === "icu") { + if (ctx.mono_wasm_load_icu_data (offset) === 1) + ctx.num_icu_assets_loaded_successfully += 1; + else + console.error ("Error loading ICU asset", asset.name); + } + }, + // Initializes the runtime and loads assemblies, debug information, and other files. // @args is a dictionary-style Object with the following properties: // vfs_prefix: (required) // deploy_prefix: (required) // enable_debugging: (required) - // assembly_list: (required) a list of assemblies and related files to load along - // with the runtime. .pdb files in this list will be treated as optional. + // assets: (required) a list of assets to load along with the runtime. each asset + // is a dictionary-style Object with the following properties: + // name: (required) the name of the asset, including extension. + // behavior: (required) determines how the asset will be handled once loaded: + // "heap": store asset into the native heap + // "assembly": load asset as a managed assembly (or debugging information) + // "icu": load asset as an ICU data archive + // "vfs": load asset into the virtual filesystem (for fopen, File.Open, etc) + // load_remote: (optional) if true, an attempt will be made to load the asset + // from each location in @args.remote_sources. + // virtual_path: (optional) if specified, overrides the path of the asset in + // the virtual filesystem and similar data structures once loaded. + // is_optional: (optional) if true, any failure to load this asset will be ignored. // loaded_cb: (required) a function () invoked when loading has completed. // fetch_file_cb: (optional) a function (string) invoked to fetch a given file. // If no callback is provided a default implementation appropriate for the current // environment will be selected (readFileSync in node, fetch elsewhere). // If no default implementation is available this call will fail. - // runtime_assets: (optional) a list of asset filenames to load along with the runtime. - // runtime assets are loaded into wasm memory and MONO.loaded_runtime_assets is populated - // with [offset, length] tuples for each asset - // runtime_asset_sources: (optional) additional search locations for runtime assets. - // if no runtime asset sources are provided the default will be ["./"]. + // remote_sources: (optional) additional search locations for assets. // sources will be checked in sequential order until the asset is found. // the string "./" indicates to load from the application directory (as with the // files in assembly_list), and a fully-qualified URL like "https://example.com/" indicates - // that asset loads can be attempted from a remote server. Sources must end with a /. + // that asset loads can be attempted from a remote server. Sources must end with a "/". // environment_variables: (optional) dictionary-style Object containing environment variables // runtime_options: (optional) array of runtime options as strings // aot_profiler_options: (optional) dictionary-style Object. see the comments for @@ -564,81 +661,39 @@ var MonoSupportLib = { // coverage_profiler_options: (optional) dictionary-style Object. see the comments for // mono_wasm_init_coverage_profiler. If omitted, coverage profiler will not be initialized. // globalization_mode: (optional) configures the runtime's globalization mode: - // "icu": load ICU globalization data from the runtime asset "icudt.dat" + // "icu": load ICU globalization data from any runtime assets with behavior "icu". // "invariant": operate in invariant globalization mode. - // "auto" (default): if icudt.dat is present, use ICU, otherwise invariant. + // "auto" (default): if "icu" behavior assets are present, use ICU, otherwise invariant. mono_load_runtime_and_bcl_args: function (args) { - var deploy_prefix = args.deploy_prefix; - var assembly_list = args.assembly_list; - var loaded_cb = args.loaded_cb; - var fetch_file_cb = args.fetch_file_cb; - var runtime_assets = (args.runtime_assets || []); - - if (!assembly_list) - throw new Error ("assembly_list not provided"); - if (!loaded_cb) + if (args.assembly_list) + throw new Error ("Invalid args (assembly_list was replaced by assets)"); + if (args.runtime_assets) + throw new Error ("Invalid args (runtime_assets was replaced by assets)"); + if (args.runtime_asset_sources) + throw new Error ("Invalid args (runtime_asset_sources was replaced by remote_sources)"); + if (!args.loaded_cb) throw new Error ("loaded_cb not provided"); console.log ("mono_wasm_load_runtime_with_args", JSON.stringify(args)); - var pending = assembly_list.length + runtime_assets.length; - var loaded_files = []; - var loaded_runtime_assets = {}; - var mono_wasm_add_assembly = Module.cwrap ('mono_wasm_add_assembly', null, ['string', 'number', 'number']); - - for (var k in (args.environment_variables || {})) - this.mono_wasm_setenv (k, args.environment_variables[k]); - - if (args.runtime_options) - this.mono_wasm_set_runtime_options (args.runtime_options); - - if (args.aot_profiler_options) - this.mono_wasm_init_aot_profiler (args.aot_profiler_options); - - if (args.coverage_profiler_options) - this.mono_wasm_init_coverage_profiler (args.coverage_profiler_options); - - if (!fetch_file_cb) { - if (ENVIRONMENT_IS_NODE) { - var fs = require('fs'); - fetch_file_cb = function (asset) { - console.log ("MONO_WASM: Loading... " + asset); - var binary = fs.readFileSync (asset); - var resolve_func2 = function (resolve, reject) { - resolve (new Uint8Array (binary)); - }; + this._apply_configuration_from_args (args); - var resolve_func1 = function (resolve, reject) { - var response = { - ok: true, - url: asset, - arrayBuffer: function () { - return new Promise (resolve_func2); - } - }; - resolve (response); - }; + var fetch_file_cb = this._get_fetch_file_cb_from_args (args); - return new Promise (resolve_func1); - }; - } else if (typeof (fetch) === "function") { - fetch_file_cb = function (asset) { - return fetch (asset, { credentials: 'same-origin' }); - } - } else { - throw new Error ("No fetch_file_cb was provided and this environment does not expose 'fetch'."); - } - } + var ctx = { + pending_count: args.assets.length, + mono_wasm_add_assembly: Module.cwrap ('mono_wasm_add_assembly', null, ['string', 'number', 'number']), + mono_wasm_load_icu_data: Module.cwrap ('mono_wasm_load_icu_data', 'number', ['number']), + loaded_assets: Object.create (), + num_icu_assets_loaded_successfully: 0 + }; var onPendingRequestComplete = function () { - --pending; + --ctx.pending_count; - if (pending == 0) { - MONO.loaded_files = loaded_files; - MONO.loaded_runtime_assets = loaded_runtime_assets; - - MONO._globalization_init (args, loaded_runtime_assets); + if (ctx.pending_count === 0) { + MONO.loaded_assets = ctx.loaded_assets; var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string', 'number']); @@ -658,105 +713,78 @@ var MonoSupportLib = { } else { load_runtime (args.vfs_prefix, args.enable_debugging); } + MONO.mono_wasm_runtime_ready (); - loaded_cb (); + args.loaded_cb (); } }; - var runtime_asset_sources = args.runtime_asset_sources || [""]; - - var processFetchResponseBuffer = function (file_name, is_runtime_asset, blob) { + var processFetchResponseBuffer = function (asset, blob) { try { - var asm = new Uint8Array (blob); - console.log ("MONO_WASM: Loaded:", file_name, asm.length); - - var memoryOffset = Module._malloc (asm.length); - var heapBytes = new Uint8Array (Module.HEAPU8.buffer, memoryOffset, asm.length); - heapBytes.set (asm); - - if (is_runtime_asset) { - loaded_runtime_assets [file_name] = [memoryOffset, asm.length]; - } else { - if (/(\.pdb|\.exe|\.dll)$/.test (file_name)) { - mono_wasm_add_assembly (file_name, memoryOffset, asm.length); - } else { - console.log ("MONO_WASM: Skipping add_assembly for", file_name); - } - } - - onPendingRequestComplete (); + MONO._handle_loaded_asset (ctx, asset, blob); } catch (exc) { - console.log ("Unhandled exception", exc); + console.log ("Unhandled exception in processFetchResponseBuffer", exc); + throw exc; + } finally { + onPendingRequestComplete (); } }; - runtime_assets.forEach (function (file_name) { - var sourceIndex = 0; + args.assets.forEach (function (asset) { var attemptNextSource; + var sourceIndex = 0; + var sourcesList = asset.load_remote ? args.remote_sources : [""]; - var handleFetchResponse = function (file_name, response) { + var handleFetchResponse = function (response) { if (!response.ok) { - attemptNextSource (file_name); + attemptNextSource (); } else { - loaded_files.push (response.url); var bufferPromise = response ['arrayBuffer'] (); - bufferPromise.then ( - processFetchResponseBuffer.bind (this, file_name, true) - ); + bufferPromise.then (processFetchResponseBuffer.bind (this, asset)); } }; - attemptNextSource = function (file_name) { - if (sourceIndex >= runtime_asset_sources.length) { - console.error ("MONO_WASM: Failed to load " + file_name); - --pending; - return; + attemptNextSource = function () { + if (sourceIndex >= sourcesList.length) { + var msg = "MONO_WASM: Failed to load " + asset.name; + try { + console.error (msg); + if (asset.is_optional) + return; + else if (asset.name.match (/\.pdb$/) && MONO.mono_wasm_ignore_pdb_load_errors) + return; + else + throw new Error (msg); + } finally { + onPendingRequestComplete (); + } } - var sourcePrefix = runtime_asset_sources[sourceIndex]; + var sourcePrefix = sourcesList[sourceIndex]; sourceIndex++; // HACK: Special-case because MSBuild doesn't allow "" as an attribute if (sourcePrefix === "./") sourcePrefix = ""; - var attemptUrl = sourcePrefix + file_name; + var attemptUrl; + // FIXME: Unify this + if (sourcePrefix.trim() === "") + attemptUrl = locateFile (args.deploy_prefix + "/" + asset.name); + else + attemptUrl = sourcePrefix + asset.name; try { + console.log ("Attempting to load", asset.name, "from", attemptUrl); var fetch_promise = fetch_file_cb (attemptUrl); - fetch_promise.then (handleFetchResponse.bind (this, file_name)); + fetch_promise.then (handleFetchResponse); } catch (exc) { console.error ("MONO_WASM: Error fetching " + attemptUrl, exc); - attemptNextSource (file_name); + attemptNextSource (); } }; - attemptNextSource (file_name); - }); - - assembly_list.forEach (function (file_name) { - var handleFetchResponse = function (response) { - if (!response.ok) { - // If it's a 404 on a .pdb, we don't want to block the app from starting up. - // We'll just skip that file and continue (though the 404 is logged in the console). - if (response.status === 404 && file_name.match (/\.pdb$/) && MONO.mono_wasm_ignore_pdb_load_errors) { - --pending; - throw new Error ("MONO-WASM: Skipping failed load for .pdb file: '" + file_name + "'"); - } - else { - throw new Error ("MONO_WASM: Failed to load file: '" + file_name + "'"); - } - } - else { - loaded_files.push (response.url); - return response ['arrayBuffer'] (); - } - }; - - var fetch_promise = fetch_file_cb (locateFile (deploy_prefix + "/" + file_name)); - - fetch_promise.then (handleFetchResponse) - .then (processFetchResponseBuffer.bind(this, file_name, false)) + attemptNextSource (); }); }, @@ -771,7 +799,7 @@ var MonoSupportLib = { if (icudt) { console.log ("MONO_WASM: Loading ICU data archive icudt.dat"); - var mono_wasm_load_icu_data = Module.cwrap ('mono_wasm_load_icu_data', 'number', ['number']); + var ; var result = mono_wasm_load_icu_data (icudt[0]); if (result !== 1) console.log ("MONO_WASM: mono_wasm_load_icu_data returned", result); @@ -966,7 +994,7 @@ var MonoSupportLib = { if (m!= null) { if (m.length > 2) folders.add(m.slice(0,m.length-1).join('/')); folders.add(m[0]); - } + } }); folders.forEach(folder => { Module['FS_createPath'](prefix, folder, true, true); From 6d5494acec343def5211d50739f2ec41399ab8ba Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Mon, 13 Jul 2020 23:37:19 -0700 Subject: [PATCH 16/62] Checkpoint --- src/mono/wasm/runtime/library_mono.js | 72 ++++++++++++++++----------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index a8d0f68ae68dc3..9ba4e43e1eab28 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -148,9 +148,8 @@ var MonoSupportLib = { var numBytes = var_list.length * Int32Array.BYTES_PER_ELEMENT; var ptr = Module._malloc(numBytes); var heapBytes = new Int32Array(Module.HEAP32.buffer, ptr, numBytes); - for (let i=0; i 0) { + console.log ("MONO_WASM: ICU data archive(s) loaded, disabling invariant mode"); } else if (args.globalization_mode !== "icu") { - console.log ("MONO_WASM: icudt.dat not present, using invariant globalization mode"); + console.log ("MONO_WASM: ICU data archive(s) not loaded, using invariant globalization mode"); invariantMode = true; } else { - console.log ("MONO_WASM: ERROR: icudt.dat not found and invariant globalization mode is inactive."); + console.error ("MONO_WASM: ERROR: invariant globalization mode is inactive and no ICU data archives were loaded."); } } @@ -815,8 +828,7 @@ var MonoSupportLib = { }, mono_wasm_get_loaded_files: function() { - console.log(">>>mono_wasm_get_loaded_files"); - return this.loaded_files; + throw new Error("not implemented"); }, mono_wasm_clear_all_breakpoints: function() { From 632d1fa25c897e27db48cb4978deafe9e5f2a73b Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 01:10:20 -0700 Subject: [PATCH 17/62] Checkpoint --- src/mono/wasm/runtime/library_mono.js | 59 +++++++++++++++------------ 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 9ba4e43e1eab28..861c590aa9a3bd 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -672,6 +672,35 @@ var MonoSupportLib = { } }, + _finalize_startup: function (args, ctx) { + MONO.loaded_assets = ctx.loaded_assets; + + var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string', 'number']); + + console.log ("MONO_WASM: Initializing mono runtime"); + + this._globalization_init (args, ctx); + + if (ENVIRONMENT_IS_SHELL || ENVIRONMENT_IS_NODE) { + try { + load_runtime (args.vfs_prefix, args.enable_debugging); + } catch (ex) { + print ("MONO_WASM: load_runtime () failed: " + ex); + var err = new Error(); + print ("MONO_WASM: Stacktrace: \n"); + print (err.stack); + + var wasm_exit = Module.cwrap ('mono_wasm_exit', null, ['number']); + wasm_exit (1); + } + } else { + load_runtime (args.vfs_prefix, args.enable_debugging); + } + + MONO.mono_wasm_runtime_ready (); + args.loaded_cb (); + }, + _load_assets_and_runtime: function (args) { if (args.assembly_list) throw new Error ("Invalid args (assembly_list was replaced by assets)"); @@ -700,32 +729,12 @@ var MonoSupportLib = { --ctx.pending_count; if (ctx.pending_count === 0) { - MONO.loaded_assets = ctx.loaded_assets; - - var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string', 'number']); - - console.log ("MONO_WASM: Initializing mono runtime"); - - this._globalization_init (args, ctx); - - if (ENVIRONMENT_IS_SHELL || ENVIRONMENT_IS_NODE) { - try { - load_runtime (args.vfs_prefix, args.enable_debugging); - } catch (ex) { - print ("MONO_WASM: load_runtime () failed: " + ex); - var err = new Error(); - print ("MONO_WASM: Stacktrace: \n"); - print (err.stack); - - var wasm_exit = Module.cwrap ('mono_wasm_exit', null, ['number']); - wasm_exit (1); - } - } else { - load_runtime (args.vfs_prefix, args.enable_debugging); + try { + MONO._finalize_startup (args, ctx); + } catch (exc) { + console.error ("Unhandled exception in _finalize_startup", exc); + throw exc; } - - MONO.mono_wasm_runtime_ready (); - args.loaded_cb (); } }; From 99b64a0b44bc7b0dff1c2b48b002670bc6b6c65d Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 07:51:58 -0700 Subject: [PATCH 18/62] Checkpoint --- src/mono/wasm/runtime-test.js | 3 ++ .../WasmAppBuilder/WasmAppBuilder.cs | 37 ++++++++----------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 777bb807a8ab53..8ea4db506d94de 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -130,6 +130,9 @@ while (true) { } else if (args [0] == "--disable-on-demand-gc") { enable_gc = false; args = args.slice (1); + } else if (args [0] == "--enable-gc") { + enable_gc = true; + args = args.slice (1); } else if (args [0] == "--enable-zoneinfo") { enable_zoneinfo = true; args = args.slice (1); diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs index 4fa9023715b564..c01e359ee95776 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -29,8 +29,8 @@ public class WasmAppBuilder : Task public ITaskItem[]? AssemblySearchPaths { get; set; } public ITaskItem[]? ExtraAssemblies { get; set; } public ITaskItem[]? FilesToIncludeInFileSystem { get; set; } - public ITaskItem[]? AssetSources { get; set; } - public ITaskItem[]? Assets { get; set; } + public ITaskItem[]? RemoteSources { get; set; } + public ITaskItem[]? ICUDataFiles { get; set; } Dictionary? _assemblies; Resolver? _resolver; @@ -126,40 +126,35 @@ public override bool Execute () sw.WriteLine("\tvfs_prefix: \"managed\","); sw.WriteLine("\tdeploy_prefix: \"managed\","); sw.WriteLine("\tenable_debugging: 0,"); - sw.WriteLine("\tassembly_list: ["); + sw.WriteLine("\tassets: ["); foreach (var assembly in _assemblies.Values) { - sw.Write("\t\t\"" + Path.GetFileName(assembly.Location) + "\""); + sw.Write($"\t\t{{ behavior: \"assembly\", name: \"{Path.GetFileName(assembly.Location)}\" }}"); sw.WriteLine(","); } - sw.WriteLine ("\t],"); - sw.WriteLine("\tfiles_to_map: ["); foreach (KeyValuePair> keyValuePair in filesToMap) { - sw.WriteLine("\t{"); - sw.WriteLine($"\t\tdirectory: \"{keyValuePair.Key}\","); - sw.WriteLine("\t\tfiles: ["); + sw.WriteLine("\t\t{"); + sw.WriteLine($"\t\t\tbehavior: \"vfs\","); + sw.WriteLine($"\t\t\tdirectory: \"{keyValuePair.Key}\","); + sw.WriteLine("\t\t\tfiles: ["); foreach (string file in keyValuePair.Value) { - sw.WriteLine($"\t\t\t\"{file}\","); + sw.WriteLine($"\t\t\t\t\"{file}\","); } - sw.WriteLine("\t\t],"); - sw.WriteLine("\t},"); + sw.WriteLine("\t\t\t],"); + sw.WriteLine("\t\t},"); } + foreach (var asset in ICUDataFiles!) + sw.Write($"\t\t{{ behavior: \"icu\", name: \"{asset.ItemSpec}\", load_remote: true }}"); sw.WriteLine ("\t],"); - if (AssetSources!.Length > 0) { - sw.WriteLine("\truntime_asset_sources: ["); - foreach (var source in AssetSources!) + if (RemoteSources!.Length > 0) { + sw.WriteLine("\tremote_sources: ["); + foreach (var source in RemoteSources!) sw.WriteLine("\t\t\"" + source.ItemSpec + "\", "); sw.WriteLine ("],"); } - if (Assets!.Length > 0) { - sw.WriteLine("\truntime_assets: ["); - foreach (var asset in Assets!) - sw.WriteLine("\t\t\"" + asset.ItemSpec + "\", "); - sw.WriteLine ("],"); - } sw.WriteLine ("};"); } From 73e7ec378c91e1e751614d9a279c39fa17b5fa29 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 07:54:45 -0700 Subject: [PATCH 19/62] Checkpoint --- src/mono/netcore/sample/wasm/WasmSample.csproj | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/mono/netcore/sample/wasm/WasmSample.csproj b/src/mono/netcore/sample/wasm/WasmSample.csproj index cfb12f56c84d5f..3b7f66745785a2 100644 --- a/src/mono/netcore/sample/wasm/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/WasmSample.csproj @@ -35,12 +35,12 @@ - - - + + + - + @@ -50,8 +50,8 @@ MainAssembly="bin\WasmSample.dll" MainJS="$(MonoProjectRoot)wasm\runtime-test.js" AssemblySearchPaths="@(AssemblySearchPaths)" - AssetSources="@(AssetSources)" - Assets="@(Assets)" /> + RemoteSources="@(RemoteSources)" + ICUDataFiles="@(ICUDataFiles)" /> From 857cd9b0c1fe5227dbf83a23030a99505ef12f4b Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 07:55:52 -0700 Subject: [PATCH 20/62] Fix formatting error --- .../mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs index c01e359ee95776..8bc8caa79af241 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -127,11 +127,10 @@ public override bool Execute () sw.WriteLine("\tdeploy_prefix: \"managed\","); sw.WriteLine("\tenable_debugging: 0,"); sw.WriteLine("\tassets: ["); + foreach (var assembly in _assemblies.Values) - { - sw.Write($"\t\t{{ behavior: \"assembly\", name: \"{Path.GetFileName(assembly.Location)}\" }}"); - sw.WriteLine(","); - } + sw.WriteLine($"\t\t{{ behavior: \"assembly\", name: \"{Path.GetFileName(assembly.Location)}\" }},"); + foreach (KeyValuePair> keyValuePair in filesToMap) { sw.WriteLine("\t\t{"); @@ -145,8 +144,10 @@ public override bool Execute () sw.WriteLine("\t\t\t],"); sw.WriteLine("\t\t},"); } + foreach (var asset in ICUDataFiles!) - sw.Write($"\t\t{{ behavior: \"icu\", name: \"{asset.ItemSpec}\", load_remote: true }}"); + sw.WriteLine($"\t\t{{ behavior: \"icu\", name: \"{asset.ItemSpec}\", load_remote: true }},"); + sw.WriteLine ("\t],"); if (RemoteSources!.Length > 0) { @@ -155,6 +156,7 @@ public override bool Execute () sw.WriteLine("\t\t\"" + source.ItemSpec + "\", "); sw.WriteLine ("],"); } + sw.WriteLine ("};"); } From 858a2af3e05ba6cc9b38e5c8a62202224033d3e8 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 08:34:56 -0700 Subject: [PATCH 21/62] Checkpoint --- eng/testing/tests.mobile.targets | 6 +- src/mono/wasm/runtime/library_mono.js | 1 + .../WasmAppBuilder/WasmAppBuilder.cs | 86 +++++++------------ 3 files changed, 35 insertions(+), 58 deletions(-) diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index 392c37cd893c0a..7af89d547f5857 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -139,8 +139,7 @@ - - + + ICUDataFiles="@(ICUDataFiles)" /> diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 861c590aa9a3bd..19e17fe8a0d39f 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -722,6 +722,7 @@ var MonoSupportLib = { mono_wasm_add_assembly: Module.cwrap ('mono_wasm_add_assembly', null, ['string', 'number', 'number']), mono_wasm_load_icu_data: Module.cwrap ('mono_wasm_load_icu_data', 'number', ['number']), loaded_assets: Object.create (null), + createPath: Module['FS_createPath'], num_icu_assets_loaded_successfully: 0 }; diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs index 8bc8caa79af241..229d5b9c9e6657 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -77,49 +77,6 @@ public override bool Execute () File.Copy(Path.Join (MicrosoftNetCoreAppRuntimePackDir, "native", f), Path.Join(AppDir, f), true); File.Copy(MainJS!, Path.Join(AppDir, "runtime.js"), true); - var filesToMap = new Dictionary>(); - if (FilesToIncludeInFileSystem != null) - { - string supportFilesDir = Path.Join(AppDir, "supportFiles"); - Directory.CreateDirectory(supportFilesDir); - - foreach (var item in FilesToIncludeInFileSystem) - { - string? targetPath = item.GetMetadata("TargetPath"); - if (string.IsNullOrEmpty(targetPath)) - { - targetPath = Path.GetFileName(item.ItemSpec); - } - - // We normalize paths from `\` to `/` as MSBuild items could use `\`. - targetPath = targetPath.Replace('\\', '/'); - - string? directory = Path.GetDirectoryName(targetPath); - - if (!string.IsNullOrEmpty(directory)) - { - Directory.CreateDirectory(Path.Join(supportFilesDir, directory)); - } - else - { - directory = "/"; - } - - File.Copy(item.ItemSpec, Path.Join(supportFilesDir, targetPath), true); - - if (filesToMap.TryGetValue(directory, out List? files)) - { - files.Add(Path.GetFileName(targetPath)); - } - else - { - files = new List(); - files.Add(Path.GetFileName(targetPath)); - filesToMap[directory] = files; - } - } - } - using (var sw = File.CreateText(Path.Join(AppDir, "mono-config.js"))) { sw.WriteLine("config = {"); @@ -131,26 +88,47 @@ public override bool Execute () foreach (var assembly in _assemblies.Values) sw.WriteLine($"\t\t{{ behavior: \"assembly\", name: \"{Path.GetFileName(assembly.Location)}\" }},"); - foreach (KeyValuePair> keyValuePair in filesToMap) + if (FilesToIncludeInFileSystem != null) { - sw.WriteLine("\t\t{"); - sw.WriteLine($"\t\t\tbehavior: \"vfs\","); - sw.WriteLine($"\t\t\tdirectory: \"{keyValuePair.Key}\","); - sw.WriteLine("\t\t\tfiles: ["); - foreach (string file in keyValuePair.Value) + string supportFilesDir = Path.Join(AppDir, "supportFiles"); + Directory.CreateDirectory(supportFilesDir); + + foreach (var item in FilesToIncludeInFileSystem) { - sw.WriteLine($"\t\t\t\t\"{file}\","); + string? targetPath = item.GetMetadata("TargetPath"); + if (string.IsNullOrEmpty(targetPath)) + { + targetPath = Path.GetFileName(item.ItemSpec); + } + + // We normalize paths from `\` to `/` as MSBuild items could use `\`. + targetPath = targetPath.Replace('\\', '/'); + + var generatedFileName = item.ItemSpec.Replace(":", "_") + .Replace("/", "_") + .Replace("\\", "_"); + + File.Copy(item.ItemSpec, Path.Join(supportFilesDir, generatedFileName), true); + + var actualItemName = "supportFiles/" + generatedFileName; + + sw.WriteLine("\t\t{"); + sw.WriteLine("\t\t\tbehavior: \"vfs\","); + sw.WriteLine($"\t\t\tname: \"{actualItemName}\","); + sw.WriteLine($"\t\t\tvirtual_path: \"{targetPath}\","); + sw.WriteLine("\t\t},"); } - sw.WriteLine("\t\t\t],"); - sw.WriteLine("\t\t},"); } + var enableRemote = (RemoteSources != null) && (RemoteSources!.Length > 0); + var sEnableRemote = enableRemote ? "true" : "false"; + foreach (var asset in ICUDataFiles!) - sw.WriteLine($"\t\t{{ behavior: \"icu\", name: \"{asset.ItemSpec}\", load_remote: true }},"); + sw.WriteLine($"\t\t{{ behavior: \"icu\", name: \"{asset.ItemSpec}\", load_remote: {sEnableRemote}}},"); sw.WriteLine ("\t],"); - if (RemoteSources!.Length > 0) { + if (enableRemote) { sw.WriteLine("\tremote_sources: ["); foreach (var source in RemoteSources!) sw.WriteLine("\t\t\"" + source.ItemSpec + "\", "); From 5ff4030a4100cf5fb3fb0de023526f1d8086f857 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 08:42:20 -0700 Subject: [PATCH 22/62] Checkpoint --- src/mono/wasm/runtime/library_mono.js | 6 +++++- .../tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs | 5 ++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 19e17fe8a0d39f..4860e54a91845d 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -804,7 +804,11 @@ var MonoSupportLib = { } try { - console.log ("Attempting to load", asset.name, "from", attemptUrl); + if (asset.name === attemptUrl) { + console.log ("Attempting to fetch", attemptUrl); + } else { + console.log ("Attempting to fetch", attemptUrl, "for", asset.name); + } var fetch_promise = fetch_file_cb (attemptUrl); fetch_promise.then (handleFetchResponse); } catch (exc) { diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs index 229d5b9c9e6657..d605f5793fa5ba 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -93,6 +93,7 @@ public override bool Execute () string supportFilesDir = Path.Join(AppDir, "supportFiles"); Directory.CreateDirectory(supportFilesDir); + var i = 0; foreach (var item in FilesToIncludeInFileSystem) { string? targetPath = item.GetMetadata("TargetPath"); @@ -104,9 +105,7 @@ public override bool Execute () // We normalize paths from `\` to `/` as MSBuild items could use `\`. targetPath = targetPath.Replace('\\', '/'); - var generatedFileName = item.ItemSpec.Replace(":", "_") - .Replace("/", "_") - .Replace("\\", "_"); + var generatedFileName = $"{i++}_{Path.GetFileName(item.ItemSpec)}"; File.Copy(item.ItemSpec, Path.Join(supportFilesDir, generatedFileName), true); From df66debb9300d95429debb1609248f7bb66911d4 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 15 Jul 2020 03:20:09 +0300 Subject: [PATCH 23/62] bump ICU nuget, skip some tests --- eng/Version.Details.xml | 2 +- eng/Versions.props | 2 +- .../TaiwanCalendarDaysAndMonths.cs | 1 + .../CultureInfo/CultureInfoEnglishName.cs | 4 +++- .../CultureInfo/CultureInfoNativeName.cs | 4 +++- .../DateTimeFormatInfoCalendarWeekRule.cs | 4 +++- .../DateTimeFormatInfoTests.cs | 3 ++- .../NumberFormatInfoCurrencyGroupSizes.cs | 2 +- ...NumberFormatInfoCurrencyNegativePattern.cs | 10 ++++++++-- .../System/Globalization/RegionInfoTests.cs | 6 ++++-- .../System/Globalization/TextInfoTests.cs | 20 +++++++++++++++++-- .../WasmAppBuilder/PInvokeTableGenerator.cs | 2 +- 12 files changed, 46 insertions(+), 14 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 46f4d5a99b09e4..b2917658ab8f78 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -118,7 +118,7 @@ https://github.com/dotnet/runtime-assets 629993236116221fba87fe1de6d7893dd02c3722 - + https://github.com/dotnet/icu diff --git a/eng/Versions.props b/eng/Versions.props index d3ae88f4bf1542..569e39d2dbdb1c 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -118,7 +118,7 @@ 5.0.0-preview.3.20360.3 - 5.0.0-preview.8.20359.5 + 5.0.0-preview.8.20364.1 9.0.1-alpha.1.20356.1 9.0.1-alpha.1.20356.1 diff --git a/src/libraries/System.Globalization.Calendars/tests/TaiwanCalendar/TaiwanCalendarDaysAndMonths.cs b/src/libraries/System.Globalization.Calendars/tests/TaiwanCalendar/TaiwanCalendarDaysAndMonths.cs index 0f96a592bf508e..cb901d27f56a9f 100644 --- a/src/libraries/System.Globalization.Calendars/tests/TaiwanCalendar/TaiwanCalendarDaysAndMonths.cs +++ b/src/libraries/System.Globalization.Calendars/tests/TaiwanCalendar/TaiwanCalendarDaysAndMonths.cs @@ -9,6 +9,7 @@ namespace System.Globalization.Tests public class TaiwanCalendarDaysAndMonths { [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/39285", TestPlatforms.Browser)] public void DayNames_MonthNames() { string[] expectedDayNames = diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index 23c2032c51cd41..1abff4ff15b1f7 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -12,7 +12,9 @@ public static IEnumerable EnglishName_TestData() { yield return new object[] { CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.EnglishName }; yield return new object[] { "en-US", "English (United States)" }; - yield return new object[] { "fr-FR", "French (France)" }; + if (PlatformDetection.IsNotBrowser) + // Browser's ICU returns "French (FR)" instead for "fr-FR" + yield return new object[] { "fr-FR", "French (France)" }; } [Theory] diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs index b97a645b8b2a57..7a54d3123b942c 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs @@ -12,7 +12,9 @@ public static IEnumerable NativeName_TestData() { yield return new object[] { CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.NativeName }; yield return new object[] { "en-US", "English (United States)" }; - yield return new object[] { "en-CA", "English (Canada)" }; + if (PlatformDetection.IsNotBrowser) + // Browser's ICU doesn't contain en-CA locale + yield return new object[] { "en-CA", "English (Canada)" }; } [Theory] diff --git a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoCalendarWeekRule.cs b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoCalendarWeekRule.cs index a0dc8afc4adc82..89097f9788a491 100644 --- a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoCalendarWeekRule.cs +++ b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoCalendarWeekRule.cs @@ -12,7 +12,9 @@ public static IEnumerable CalendarWeekRule_Get_TestData() { yield return new object[] { DateTimeFormatInfo.InvariantInfo, CalendarWeekRule.FirstDay }; yield return new object[] { new CultureInfo("en-US").DateTimeFormat, CalendarWeekRule.FirstDay }; - yield return new object[] { new CultureInfo("br-FR").DateTimeFormat, DateTimeFormatInfoData.BrFRCalendarWeekRule() }; + + if (PlatformDetection.IsNotBrowser) // "br-FR" is not presented in Browser's ICU + yield return new object[] { new CultureInfo("br-FR").DateTimeFormat, DateTimeFormatInfoData.BrFRCalendarWeekRule() }; } [Theory] diff --git a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs index 1689c9e312d2db..5dd96d0464dc16 100644 --- a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs +++ b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs @@ -59,7 +59,8 @@ public void DateSeparatorTimeSeparator_Get_ReturnsExpected() Assert.Equal(expectedFormattedString, d.ToString("HH:mm:ss", dtfi)); } - [Theory] + // Browser's ICU doesn't support NativeCalendarName + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [MemberData(nameof(DateTimeFormatInfo_TestData))] public void NativeCalendarName_Get_ReturnsExpected(DateTimeFormatInfo dtfi, Calendar calendar, string nativeCalendarName) { diff --git a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyGroupSizes.cs b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyGroupSizes.cs index aa283d47e7c083..261edc3fb0d26e 100644 --- a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyGroupSizes.cs +++ b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyGroupSizes.cs @@ -13,7 +13,7 @@ public static IEnumerable CurrencyGroupSizes_TestData() yield return new object[] { NumberFormatInfo.InvariantInfo, new int[] { 3 } }; yield return new object[] { CultureInfo.GetCultureInfo("en-US").NumberFormat, new int[] { 3 } }; - if (!PlatformDetection.IsUbuntu && !PlatformDetection.IsWindows7 && !PlatformDetection.IsWindows8x && !PlatformDetection.IsFedora) + if (PlatformDetection.IsNotBrowser && !PlatformDetection.IsUbuntu && !PlatformDetection.IsWindows7 && !PlatformDetection.IsWindows8x && !PlatformDetection.IsFedora) { yield return new object[] { CultureInfo.GetCultureInfo("ur-IN").NumberFormat, new int[] { 3, 2 } }; } diff --git a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyNegativePattern.cs b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyNegativePattern.cs index e33d39ddea3ea6..b20b283313b0e7 100644 --- a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyNegativePattern.cs +++ b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyNegativePattern.cs @@ -27,8 +27,6 @@ public void CurrencyNegativePattern_Get_ReturnsExpected(NumberFormatInfo format, [InlineData("en-CA")] [InlineData("fa-IR")] [InlineData("fr-CD")] - [InlineData("as")] - [InlineData("es-BO")] [InlineData("fr-CA")] public void CurrencyNegativePattern_Get_ReturnsExpected_ByLocale(string locale) { @@ -46,6 +44,14 @@ public void CurrencyNegativePattern_Get_ReturnsExpected_ByLocale(string locale) Assert.Contains(format.CurrencyNegativePattern, NumberFormatInfoData.GetCurrencyNegativePatterns(locale)); } + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [InlineData("as")] // Browser's ICU doesn't contain these locales + [InlineData("es-BO")] + public void CurrencyNegativePattern_Get_ReturnsExpected_ByLocale_NotBrowser(string locale) + { + CurrencyNegativePattern_Get_ReturnsExpected_ByLocale(locale); + } + [Theory] [InlineData(0)] [InlineData(1)] diff --git a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs index dd99a40e94ca83..e8c0168f344419 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs @@ -90,7 +90,8 @@ public void DisplayName(string name, string expected) } } - [Theory] + // RegionInfo.NativeName is not supported by Browser's ICU + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [InlineData("GB", "United Kingdom")] [InlineData("SE", "Sverige")] [InlineData("FR", "France")] @@ -99,7 +100,8 @@ public void NativeName(string name, string expected) Assert.Equal(expected, new RegionInfo(name).NativeName); } - [Theory] + // RegionInfo.EnglishName is not supported by Browser's ICU + [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] [InlineData("en-US", new string[] { "United States" })] [InlineData("US", new string[] { "United States" })] [InlineData("zh-CN", new string[] { "China", "People's Republic of China", "China mainland" })] diff --git a/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs b/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs index 6b1a2219ca738f..f489b4d97f511e 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs @@ -226,7 +226,15 @@ public static IEnumerable ToLower_TestData() yield return new object[] { cultureName, "\u03A3", "\u03C3" }; } - foreach (string cultureName in new string[] { "tr", "tr-TR", "az", "az-Latn-AZ" }) + var locales = new List { "tr", "tr-TR"}; + if (PlatformDetection.IsNotBrowser) + { + // Browser's ICU doesn't contain these locales + locales.Add("az"); + locales.Add("az-Latn-AZ"); + } + + foreach (string cultureName in locales) { yield return new object[] { cultureName, "\u0130", "i" }; yield return new object[] { cultureName, "i", "i" }; @@ -348,8 +356,16 @@ public static IEnumerable ToUpper_TestData() yield return new object[] { cultureName, "\u0149", "\u0149" }; } + var locales = new List { "tr", "tr-TR"}; + if (PlatformDetection.IsNotBrowser) + { + // Browser's ICU doesn't contain these locales + locales.Add("az"); + locales.Add("az-Latn-AZ"); + } + // Turkish i - foreach (string cultureName in new string[] { "tr", "tr-TR", "az", "az-Latn-AZ" }) + foreach (string cultureName in locales) { yield return new object[] { cultureName, "i", "\u0130" }; yield return new object[] { cultureName, "\u0130", "\u0130" }; diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs index aea33760c8d9ce..d1569f18524c31 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/PInvokeTableGenerator.cs @@ -176,7 +176,7 @@ void EmitNativeToInterp(StreamWriter w, List callbacks) bool isVoid = method.ReturnType.FullName == "System.Void"; if (!isVoid && !IsBlittable(method.ReturnType)) - Error($"The return type '{method.ReturnType.FullName}' ('{isVoid}') of pinvoke callback method '{method}' needs to be blittable."); + Error($"The return type '{method.ReturnType.FullName}' of pinvoke callback method '{method}' needs to be blittable."); foreach (var p in method.GetParameters()) { if (!IsBlittable(p.ParameterType)) Error("Parameter types of pinvoke callback method '" + method + "' needs to be blittable."); From bf979b3ad6fad688bf8eb0820bb095a810c13132 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 16:07:04 -0700 Subject: [PATCH 24/62] Checkpoint --- src/mono/wasm/runtime-test.js | 31 ------------------- src/mono/wasm/runtime/driver.c | 2 +- src/mono/wasm/runtime/library_mono.js | 12 +++---- .../WasmAppBuilder/WasmAppBuilder.cs | 3 +- 4 files changed, 7 insertions(+), 41 deletions(-) diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 8ea4db506d94de..1385aa9a9c4895 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -173,37 +173,6 @@ var Module = { MONO.mono_wasm_setenv (variable, setenv [variable]); } - // Read and write files to virtual file system listed in mono-config - if (typeof config.files_to_map != 'undefined') { - Module.print("Mapping test support files listed in config.files_to_map to VFS"); - const files_to_map = config.files_to_map; - try { - for (var i = 0; i < files_to_map.length; i++) - { - if (typeof files_to_map[i].directory != 'undefined') - { - var directory = files_to_map[i].directory == '' ? '/' : files_to_map[i].directory; - if (directory != '/') { - Module['FS_createPath']('/', directory, true, true); - } - - const files = files_to_map[i].files; - for (var j = 0; j < files.length; j++) - { - var fullPath = directory != '/' ? directory + '/' + files[j] : files[j]; - var content = new Uint8Array (read ("supportFiles/" + fullPath, 'binary')); - writeContentToFile(content, fullPath); - } - } - } - } - catch (err) { - Module.printErr(err); - Module.printErr(err.stack); - test_exit(1); - } - } - if (!enable_gc) { Module.ccall ('mono_wasm_enable_on_demand_gc', 'void', ['number'], [0]); } diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c index 4678830141c243..1a044fef1fc4ef 100644 --- a/src/mono/wasm/runtime/driver.c +++ b/src/mono/wasm/runtime/driver.c @@ -343,7 +343,7 @@ void mono_initialize_internals () } EMSCRIPTEN_KEEPALIVE void -mono_wasm_load_runtime (const char *managed_path, int enable_debugging) +mono_wasm_load_runtime (int enable_debugging) { const char *interp_opts = ""; diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 4860e54a91845d..5cdb5a61d78869 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -627,8 +627,7 @@ var MonoSupportLib = { // Initializes the runtime and loads assemblies, debug information, and other files. // @args is a dictionary-style Object with the following properties: - // vfs_prefix: (required) - // deploy_prefix: (required) the subfolder containing managed assemblies and pdbs + // assembly_root: (required) the subfolder containing managed assemblies and pdbs // enable_debugging: (required) // assets: (required) a list of assets to load along with the runtime. each asset // is a dictionary-style Object with the following properties: @@ -675,7 +674,7 @@ var MonoSupportLib = { _finalize_startup: function (args, ctx) { MONO.loaded_assets = ctx.loaded_assets; - var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string', 'number']); + var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['number']); console.log ("MONO_WASM: Initializing mono runtime"); @@ -683,7 +682,7 @@ var MonoSupportLib = { if (ENVIRONMENT_IS_SHELL || ENVIRONMENT_IS_NODE) { try { - load_runtime (args.vfs_prefix, args.enable_debugging); + load_runtime (args.enable_debugging); } catch (ex) { print ("MONO_WASM: load_runtime () failed: " + ex); var err = new Error(); @@ -694,7 +693,7 @@ var MonoSupportLib = { wasm_exit (1); } } else { - load_runtime (args.vfs_prefix, args.enable_debugging); + load_runtime (args.enable_debugging); } MONO.mono_wasm_runtime_ready (); @@ -794,9 +793,8 @@ var MonoSupportLib = { var attemptUrl; if (sourcePrefix.trim() === "") { - // FIXME: Disgusting magic to match old search behavior if (asset.behavior === "assembly") - attemptUrl = locateFile (args.deploy_prefix + "/" + asset.name); + attemptUrl = locateFile (args.assembly_root + "/" + asset.name); else attemptUrl = asset.name; } else { diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs index d605f5793fa5ba..2c87579cbaf1a0 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -80,8 +80,7 @@ public override bool Execute () using (var sw = File.CreateText(Path.Join(AppDir, "mono-config.js"))) { sw.WriteLine("config = {"); - sw.WriteLine("\tvfs_prefix: \"managed\","); - sw.WriteLine("\tdeploy_prefix: \"managed\","); + sw.WriteLine("\tassembly_root: \"managed\","); sw.WriteLine("\tenable_debugging: 0,"); sw.WriteLine("\tassets: ["); From 4872ae4d9ac9765435846b130391cf2b57d3119f Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 16:07:18 -0700 Subject: [PATCH 25/62] Fix whitespace --- src/mono/wasm/runtime-test.js | 84 +++++++++++++++++------------------ 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index 1385aa9a9c4895..b2593e47e641f1 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -197,48 +197,48 @@ var Module = { } - config.loaded_cb = function () { - App.init (); - }; - config.fetch_file_cb = function (asset) { - // for testing purposes add BCL assets to VFS until we special case File.Open - // to identify when an assembly from the BCL is being open and resolve it correctly. - var content = new Uint8Array (read (asset, 'binary')); - var path = asset.substr(config.deploy_prefix.length); - writeContentToFile(content, path); - - if (typeof window != 'undefined') { - return fetch (asset, { credentials: 'same-origin' }); - } else { - // The default mono_load_runtime_and_bcl defaults to using - // fetch to load the assets. It also provides a way to set a - // fetch promise callback. - // Here we wrap the file read in a promise and fake a fetch response - // structure. - return new Promise ((resolve, reject) => { - var bytes = null, error = null; - try { - bytes = read (asset, 'binary'); - } catch (exc) { - error = exc; - } - var response = { ok: (bytes && !error), url: asset, - arrayBuffer: function () { - return new Promise ((resolve2, reject2) => { - if (error) - reject2 (error); - else - resolve2 (new Uint8Array (bytes)); - } - )} - } - resolve (response); - }) - } - }; - - MONO.mono_load_runtime_and_bcl_args (config); - }, + config.loaded_cb = function () { + App.init (); + }; + config.fetch_file_cb = function (asset) { + // for testing purposes add BCL assets to VFS until we special case File.Open + // to identify when an assembly from the BCL is being open and resolve it correctly. + var content = new Uint8Array (read (asset, 'binary')); + var path = asset.substr(config.deploy_prefix.length); + writeContentToFile(content, path); + + if (typeof window != 'undefined') { + return fetch (asset, { credentials: 'same-origin' }); + } else { + // The default mono_load_runtime_and_bcl defaults to using + // fetch to load the assets. It also provides a way to set a + // fetch promise callback. + // Here we wrap the file read in a promise and fake a fetch response + // structure. + return new Promise ((resolve, reject) => { + var bytes = null, error = null; + try { + bytes = read (asset, 'binary'); + } catch (exc) { + error = exc; + } + var response = { ok: (bytes && !error), url: asset, + arrayBuffer: function () { + return new Promise ((resolve2, reject2) => { + if (error) + reject2 (error); + else + resolve2 (new Uint8Array (bytes)); + } + )} + } + resolve (response); + }) + } + }; + + MONO.mono_load_runtime_and_bcl_args (config); + }, }; if (typeof window == "undefined") From ec10683da7955b379da71d6bc8a7ef01d286bc9d Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 17:27:21 -0700 Subject: [PATCH 26/62] Checkpoint --- src/mono/wasm/runtime-test.js | 3 ++ src/mono/wasm/runtime/library_mono.js | 45 +++++++++++++++++++++++---- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index b2593e47e641f1..c49d3851d69fb6 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -201,11 +201,14 @@ var Module = { App.init (); }; config.fetch_file_cb = function (asset) { + // console.log("fetch_file_cb('" + asset + "')"); // for testing purposes add BCL assets to VFS until we special case File.Open // to identify when an assembly from the BCL is being open and resolve it correctly. + /* var content = new Uint8Array (read (asset, 'binary')); var path = asset.substr(config.deploy_prefix.length); writeContentToFile(content, path); + */ if (typeof window != 'undefined') { return fetch (asset, { credentials: 'same-origin' }); diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 5cdb5a61d78869..7f6d1d1a6045e3 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -608,7 +608,31 @@ var MonoSupportLib = { case "vfs": // FIXME - throw new Error ("Unimplemented behavior: vfs"); + var lastSlash = virtualName.lastIndexOf("/"); + var parentDirectory = (lastSlash > 0) + ? virtualName.substr(0, lastSlash) + : null; + var fileName = (lastSlash > 0) + ? virtualName.substr(lastSlash + 1) + : virtualName; + if (fileName.startsWith("/")) + fileName = fileName.substr(1); + + if (parentDirectory) { + console.log ("MONO_WASM: Creating directory '" + parentDirectory + "'"); + var pathRet = ctx.createPath( + "/", parentDirectory, true, true // fixme: should canWrite be false? + ); + console.log ("MONO_WASM: Directory create returned", pathRet); + } + + console.log ("MONO_WASM: Creating file '" + fileName + "'"); + var fileRet = ctx.createDataFile ( + parentDirectory || "/", fileName, + bytes, true, false, true + ); + console.log ("MONO_WASM: File create returned", fileRet); + break; default: @@ -673,6 +697,7 @@ var MonoSupportLib = { _finalize_startup: function (args, ctx) { MONO.loaded_assets = ctx.loaded_assets; + console.log ("MONO_WASM: loaded_assets: " + JSON.stringify(ctx.loaded_assets)); var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['number']); @@ -722,6 +747,7 @@ var MonoSupportLib = { mono_wasm_load_icu_data: Module.cwrap ('mono_wasm_load_icu_data', 'number', ['number']), loaded_assets: Object.create (null), createPath: Module['FS_createPath'], + createDataFile: Module['FS_createDataFile'], num_icu_assets_loaded_successfully: 0 }; @@ -803,9 +829,9 @@ var MonoSupportLib = { try { if (asset.name === attemptUrl) { - console.log ("Attempting to fetch", attemptUrl); + console.log ("Attempting to fetch '" + attemptUrl + "'"); } else { - console.log ("Attempting to fetch", attemptUrl, "for", asset.name); + console.log ("Attempting to fetch '" + attemptUrl + "' for ", asset.name); } var fetch_promise = fetch_file_cb (attemptUrl); fetch_promise.then (handleFetchResponse); @@ -832,15 +858,22 @@ var MonoSupportLib = { console.log ("MONO_WASM: ICU data archive(s) not loaded, using invariant globalization mode"); invariantMode = true; } else { - console.error ("MONO_WASM: ERROR: invariant globalization mode is inactive and no ICU data archives were loaded."); + var msg = "invariant globalization mode is inactive and no ICU data archives were loaded"; + console.error ("MONO_WASM: ERROR: " + msg); + throw new Error (msg); } } - this.mono_wasm_setenv("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", invariantMode ? "1" : "0"); + if (invariantMode) + this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1"); }, mono_wasm_get_loaded_files: function() { - throw new Error("not implemented"); + throw new Error ("mono_wasm_get_loaded_files was replaced by mono_wasm_get_loaded_assets"); + }, + + mono_wasm_get_loaded_asset_table: function() { + return MONO.loaded_assets; }, mono_wasm_clear_all_breakpoints: function() { From 7ec82a82cf1fdbbb402506cd06e4b79b05723b6e Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 20:27:41 -0700 Subject: [PATCH 27/62] Checkpoint --- src/mono/wasm/runtime/library_mono.js | 36 ++++++++++++++++----------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 7f6d1d1a6045e3..2b41cd9df84ff6 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -781,16 +781,22 @@ var MonoSupportLib = { var sourcesList = asset.load_remote ? args.remote_sources : [""]; var handleFetchResponse = function (response) { - try { - if (!response.ok) { + if (!response.ok) { + try { attemptNextSource (); - } else { - var bufferPromise = response ['arrayBuffer'] (); - bufferPromise.then (processFetchResponseBuffer.bind (this, asset)); + return; + } catch (exc) { + console.error ("MONO_WASM: Unhandled exception in handleFetchResponse attemptNextSource for asset", asset.name, exc); + throw exc; } + } + + try { + var bufferPromise = response ['arrayBuffer'] (); + bufferPromise.then (processFetchResponseBuffer.bind (this, asset)); } catch (exc) { - console.error ("Unhandled exception in handleFetchResponse", exc); - throw exc; + console.error ("MONO_WASM: Unhandled exception in handleFetchResponse for asset", asset.name, exc); + attemptNextSource (); } }; @@ -798,13 +804,15 @@ var MonoSupportLib = { if (sourceIndex >= sourcesList.length) { var msg = "MONO_WASM: Failed to load " + asset.name; try { - console.error (msg); - if (asset.is_optional) - return; - else if (asset.name.match (/\.pdb$/) && MONO.mono_wasm_ignore_pdb_load_errors) - return; - else + var isOk = asset.is_optional || + (asset.name.match (/\.pdb$/) && MONO.mono_wasm_ignore_pdb_load_errors); + + if (isOk) + console.log (msg); + else { + console.error (msg); throw new Error (msg); + } } finally { onPendingRequestComplete (); } @@ -831,7 +839,7 @@ var MonoSupportLib = { if (asset.name === attemptUrl) { console.log ("Attempting to fetch '" + attemptUrl + "'"); } else { - console.log ("Attempting to fetch '" + attemptUrl + "' for ", asset.name); + console.log ("Attempting to fetch '" + attemptUrl + "' for", asset.name); } var fetch_promise = fetch_file_cb (attemptUrl); fetch_promise.then (handleFetchResponse); From 301b1e63b2188fe528cc814e3fabb0a441aa3732 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 21:14:36 -0700 Subject: [PATCH 28/62] Address PR feedback, cleanup whitespace --- src/mono/wasm/Makefile | 2 +- src/mono/wasm/runtime-test.js | 3 --- src/mono/wasm/runtime/driver.c | 2 +- src/mono/wasm/runtime/library_mono.js | 6 +++--- .../tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs | 4 ++-- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/mono/wasm/Makefile b/src/mono/wasm/Makefile index f98b306d1b38b2..8b9e823cc13890 100644 --- a/src/mono/wasm/Makefile +++ b/src/mono/wasm/Makefile @@ -57,7 +57,7 @@ MONO_LIBS = \ $(ICU_LIBDIR)/libicui18n.a \ $(ICU_LIBDIR)/libicudata.a -EMCC_FLAGS=--profiling-funcs -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s ALIASING_FUNCTION_POINTERS=0 -s NO_EXIT_RUNTIME=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString', 'UTF8ArrayToString', 'addFunction']" -s "EXPORTED_FUNCTIONS=['_putchar']" --source-map-base http://example.com -emit-llvm -s WASM_OBJECT_FILES=0 -s FORCE_FILESYSTEM=1 -s USE_ZLIB=1 +EMCC_FLAGS=--profiling-funcs -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s ALIASING_FUNCTION_POINTERS=0 -s NO_EXIT_RUNTIME=1 -s "EXTRA_EXPORTED_RUNTIME_METHODS=['ccall', 'FS_createPath', 'FS_createDataFile', 'cwrap', 'setValue', 'getValue', 'UTF8ToString', 'UTF8ArrayToString', 'addFunction']" -s "EXPORTED_FUNCTIONS=['_putchar']" --source-map-base http://example.com -emit-llvm -s FORCE_FILESYSTEM=1 -s USE_ZLIB=1 EMCC_DEBUG_FLAGS =-g -Os -s ASSERTIONS=1 -DENABLE_NETCORE=1 -DDEBUG=1 EMCC_RELEASE_FLAGS=-Oz --llvm-opts 2 -DENABLE_NETCORE=1 diff --git a/src/mono/wasm/runtime-test.js b/src/mono/wasm/runtime-test.js index c49d3851d69fb6..6265b5cfcc84ad 100644 --- a/src/mono/wasm/runtime-test.js +++ b/src/mono/wasm/runtime-test.js @@ -130,9 +130,6 @@ while (true) { } else if (args [0] == "--disable-on-demand-gc") { enable_gc = false; args = args.slice (1); - } else if (args [0] == "--enable-gc") { - enable_gc = true; - args = args.slice (1); } else if (args [0] == "--enable-zoneinfo") { enable_zoneinfo = true; args = args.slice (1); diff --git a/src/mono/wasm/runtime/driver.c b/src/mono/wasm/runtime/driver.c index 1a044fef1fc4ef..e4456ee6b59583 100644 --- a/src/mono/wasm/runtime/driver.c +++ b/src/mono/wasm/runtime/driver.c @@ -343,7 +343,7 @@ void mono_initialize_internals () } EMSCRIPTEN_KEEPALIVE void -mono_wasm_load_runtime (int enable_debugging) +mono_wasm_load_runtime (const char *unused, int enable_debugging) { const char *interp_opts = ""; diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 2b41cd9df84ff6..b11d7f7f4a3957 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -699,7 +699,7 @@ var MonoSupportLib = { MONO.loaded_assets = ctx.loaded_assets; console.log ("MONO_WASM: loaded_assets: " + JSON.stringify(ctx.loaded_assets)); - var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['number']); + var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string', 'number']); console.log ("MONO_WASM: Initializing mono runtime"); @@ -707,7 +707,7 @@ var MonoSupportLib = { if (ENVIRONMENT_IS_SHELL || ENVIRONMENT_IS_NODE) { try { - load_runtime (args.enable_debugging); + load_runtime ("unused", args.enable_debugging); } catch (ex) { print ("MONO_WASM: load_runtime () failed: " + ex); var err = new Error(); @@ -718,7 +718,7 @@ var MonoSupportLib = { wasm_exit (1); } } else { - load_runtime (args.enable_debugging); + load_runtime ("unused", args.enable_debugging); } MONO.mono_wasm_runtime_ready (); diff --git a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs index 2c87579cbaf1a0..593698d785d1fe 100644 --- a/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -122,7 +122,7 @@ public override bool Execute () var sEnableRemote = enableRemote ? "true" : "false"; foreach (var asset in ICUDataFiles!) - sw.WriteLine($"\t\t{{ behavior: \"icu\", name: \"{asset.ItemSpec}\", load_remote: {sEnableRemote}}},"); + sw.WriteLine($"\t\t{{ behavior: \"icu\", name: \"{asset.ItemSpec}\", load_remote: {sEnableRemote} }},"); sw.WriteLine ("\t],"); @@ -130,7 +130,7 @@ public override bool Execute () sw.WriteLine("\tremote_sources: ["); foreach (var source in RemoteSources!) sw.WriteLine("\t\t\"" + source.ItemSpec + "\", "); - sw.WriteLine ("],"); + sw.WriteLine ("\t],"); } sw.WriteLine ("};"); From 563e9855ce64c079d46cac9787f621a012eb5766 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 21:16:15 -0700 Subject: [PATCH 29/62] Remove testing fallback URL --- src/mono/netcore/sample/wasm/WasmSample.csproj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/netcore/sample/wasm/WasmSample.csproj b/src/mono/netcore/sample/wasm/WasmSample.csproj index 3b7f66745785a2..6faa51c18888b9 100644 --- a/src/mono/netcore/sample/wasm/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/WasmSample.csproj @@ -36,7 +36,6 @@ - From 1a5f206e7366490f0b9155531da49fde08313919 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 23:23:11 -0700 Subject: [PATCH 30/62] Switch back to using u_init because getCLDRVersion is broken. --- .../pal_icushim_static.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c index a9c1f05c1ddb5f..2c8f2036395b3f 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c @@ -54,14 +54,25 @@ int32_t GlobalizationNative_LoadICU(void) ; // default ICU search path behavior will be used, see http://userguide.icu-project.org/icudata UErrorCode status = 0; - UVersionInfo version; - // Request the CLDR version to perform basic ICU initialization and find out - // whether it worked. - ulocdata_getCLDRVersion(version, &status); + // FIXME: Recommended approach for checking data validity, but fails with: + // WASM-ERR: ICU call ulocdata_getCLDRVersion failed with error #2 'U_MISSING_RESOURCE_ERROR'. + if (0) { + UVersionInfo version; + // Request the CLDR version to perform basic ICU initialization and find out + // whether it worked. + ulocdata_getCLDRVersion(version, &status); - if (U_FAILURE(status)) { - log_icu_error("ulocdata_getCLDRVersion", status); - return 0; + if (U_FAILURE(status)) { + log_icu_error("ulocdata_getCLDRVersion", status); + return 0; + } + } else { + u_init(&status); + + if (U_FAILURE(status)) { + log_icu_error("u_init", status); + return 0; + } } return 1; From a64b46a4b5b6752ac1f6e4bb5522a451e076cbd7 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 23:24:55 -0700 Subject: [PATCH 31/62] Implement get_loaded_files --- src/mono/wasm/runtime/library_mono.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index b11d7f7f4a3957..6921cf9797af83 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -877,7 +877,7 @@ var MonoSupportLib = { }, mono_wasm_get_loaded_files: function() { - throw new Error ("mono_wasm_get_loaded_files was replaced by mono_wasm_get_loaded_assets"); + return Object.keys(MONO.loaded_assets); }, mono_wasm_get_loaded_asset_table: function() { From ea40744291b9fc499c03bb4e1bcc89ad22a78bbb Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Tue, 14 Jul 2020 23:36:36 -0700 Subject: [PATCH 32/62] Make loader diagnostic messages optional and off by default --- src/mono/wasm/runtime/library_mono.js | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 6921cf9797af83..78112308916700 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -735,13 +735,8 @@ var MonoSupportLib = { if (!args.loaded_cb) throw new Error ("loaded_cb not provided"); - console.log ("mono_wasm_load_runtime_with_args", JSON.stringify(args)); - - this._apply_configuration_from_args (args); - - var fetch_file_cb = this._get_fetch_file_cb_from_args (args); - var ctx = { + tracing: args.diagnostic_tracing || false, pending_count: args.assets.length, mono_wasm_add_assembly: Module.cwrap ('mono_wasm_add_assembly', null, ['string', 'number', 'number']), mono_wasm_load_icu_data: Module.cwrap ('mono_wasm_load_icu_data', 'number', ['number']), @@ -751,6 +746,13 @@ var MonoSupportLib = { num_icu_assets_loaded_successfully: 0 }; + if (ctx.tracing) + console.log ("mono_wasm_load_runtime_with_args", JSON.stringify(args)); + + this._apply_configuration_from_args (args); + + var fetch_file_cb = this._get_fetch_file_cb_from_args (args); + var onPendingRequestComplete = function () { --ctx.pending_count; @@ -837,9 +839,11 @@ var MonoSupportLib = { try { if (asset.name === attemptUrl) { - console.log ("Attempting to fetch '" + attemptUrl + "'"); + if (ctx.tracing) + console.log ("Attempting to fetch '" + attemptUrl + "'"); } else { - console.log ("Attempting to fetch '" + attemptUrl + "' for", asset.name); + if (ctx.tracing) + console.log ("Attempting to fetch '" + attemptUrl + "' for", asset.name); } var fetch_promise = fetch_file_cb (attemptUrl); fetch_promise.then (handleFetchResponse); From 642d35feda95b51cbdf93ab886d91871e4f1f24f Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 15 Jul 2020 00:01:05 -0700 Subject: [PATCH 33/62] Also silence the loaded assets dict --- src/mono/wasm/runtime/library_mono.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 78112308916700..002abaae06f917 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -697,7 +697,8 @@ var MonoSupportLib = { _finalize_startup: function (args, ctx) { MONO.loaded_assets = ctx.loaded_assets; - console.log ("MONO_WASM: loaded_assets: " + JSON.stringify(ctx.loaded_assets)); + if (ctx.tracing) + console.log ("MONO_WASM: loaded_assets: " + JSON.stringify(ctx.loaded_assets)); var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string', 'number']); From 960ebf0a1a1b4131b922b7a67f3c41b797fa57b4 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 15 Jul 2020 00:28:46 -0700 Subject: [PATCH 34/62] Apply tracing flag to vfs logs as well --- src/mono/wasm/runtime/library_mono.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 002abaae06f917..0364358bd3bb08 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -619,19 +619,23 @@ var MonoSupportLib = { fileName = fileName.substr(1); if (parentDirectory) { - console.log ("MONO_WASM: Creating directory '" + parentDirectory + "'"); + if (ctx.tracing) + console.log ("MONO_WASM: Creating directory '" + parentDirectory + "'"); + var pathRet = ctx.createPath( "/", parentDirectory, true, true // fixme: should canWrite be false? ); - console.log ("MONO_WASM: Directory create returned", pathRet); + } else { + parentDirectory = "/"; } - console.log ("MONO_WASM: Creating file '" + fileName + "'"); + if (ctx.tracing) + console.log ("MONO_WASM: Creating file '" + fileName + "' in directory '" + parentDirectory + "'"); + var fileRet = ctx.createDataFile ( - parentDirectory || "/", fileName, + parentDirectory, fileName, bytes, true, false, true ); - console.log ("MONO_WASM: File create returned", fileRet); break; From 54401b47b3deacaf15ed6cacfbb23b54ed3effbf Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 15 Jul 2020 12:16:23 +0300 Subject: [PATCH 35/62] ulocdata_getCLDRVersion works with new ICU nuget --- .../pal_icushim_static.c | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c index 2c8f2036395b3f..79fc6b387f77d4 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c @@ -54,25 +54,14 @@ int32_t GlobalizationNative_LoadICU(void) ; // default ICU search path behavior will be used, see http://userguide.icu-project.org/icudata UErrorCode status = 0; - // FIXME: Recommended approach for checking data validity, but fails with: - // WASM-ERR: ICU call ulocdata_getCLDRVersion failed with error #2 'U_MISSING_RESOURCE_ERROR'. - if (0) { - UVersionInfo version; - // Request the CLDR version to perform basic ICU initialization and find out - // whether it worked. - ulocdata_getCLDRVersion(version, &status); + UVersionInfo version; + // Request the CLDR version to perform basic ICU initialization and find out + // whether it worked. + ulocdata_getCLDRVersion(version, &status); - if (U_FAILURE(status)) { - log_icu_error("ulocdata_getCLDRVersion", status); - return 0; - } - } else { - u_init(&status); - - if (U_FAILURE(status)) { - log_icu_error("u_init", status); - return 0; - } + if (U_FAILURE(status)) { + log_icu_error("ulocdata_getCLDRVersion", status); + return 0; } return 1; From 7f904dc1f1a641745e163c4eb0a0431a93029562 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 15 Jul 2020 12:42:01 +0300 Subject: [PATCH 36/62] Update RegionInfoTests.cs --- .../tests/System/Globalization/RegionInfoTests.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs index e8c0168f344419..26aeec63a09d09 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs @@ -100,8 +100,7 @@ public void NativeName(string name, string expected) Assert.Equal(expected, new RegionInfo(name).NativeName); } - // RegionInfo.EnglishName is not supported by Browser's ICU - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [Theory] [InlineData("en-US", new string[] { "United States" })] [InlineData("US", new string[] { "United States" })] [InlineData("zh-CN", new string[] { "China", "People's Republic of China", "China mainland" })] From 5dbe40b383ef46d68102985c3b1ac1e870593b5c Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 15 Jul 2020 12:44:42 +0300 Subject: [PATCH 37/62] Update pal_icushim_internal.h --- .../Unix/System.Globalization.Native/pal_icushim_internal.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h index 0908eb8a4ab8fb..fcb669e0fc6ac4 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_internal.h @@ -60,14 +60,12 @@ #if !defined(STATIC_ICU) // List of all functions from the ICU libraries that are used in the System.Globalization.Native.so #define FOR_ALL_UNCONDITIONAL_ICU_FUNCTIONS \ - PER_FUNCTION_BLOCK(u_init, libicuuc) \ PER_FUNCTION_BLOCK(u_charsToUChars, libicuuc) \ PER_FUNCTION_BLOCK(u_getVersion, libicuuc) \ PER_FUNCTION_BLOCK(u_strlen, libicuuc) \ PER_FUNCTION_BLOCK(u_strncpy, libicuuc) \ PER_FUNCTION_BLOCK(u_tolower, libicuuc) \ PER_FUNCTION_BLOCK(u_toupper, libicuuc) \ - PER_FUNCTION_BLOCK(udata_setCommonData, libicuuc) \ PER_FUNCTION_BLOCK(ucal_add, libicui18n) \ PER_FUNCTION_BLOCK(ucal_close, libicui18n) \ PER_FUNCTION_BLOCK(ucal_get, libicui18n) \ @@ -188,14 +186,12 @@ FOR_ALL_ICU_FUNCTIONS // Redefine all calls to ICU functions as calls through pointers that are set // to the functions of the selected version of ICU in the initialization. -#define u_init(...) u_init_ptr(__VA_ARGS__) #define u_charsToUChars(...) u_charsToUChars_ptr(__VA_ARGS__) #define u_getVersion(...) u_getVersion_ptr(__VA_ARGS__) #define u_strlen(...) u_strlen_ptr(__VA_ARGS__) #define u_strncpy(...) u_strncpy_ptr(__VA_ARGS__) #define u_tolower(...) u_tolower_ptr(__VA_ARGS__) #define u_toupper(...) u_toupper_ptr(__VA_ARGS__) -#define udata_setCommonData(...) udata_setCommonData_ptr(__VA_ARGS__) #define ucal_add(...) ucal_add_ptr(__VA_ARGS__) #define ucal_close(...) ucal_close_ptr(__VA_ARGS__) #define ucal_get(...) ucal_get_ptr(__VA_ARGS__) From 55443893a327fc7d47d58f0aee9ef7277df35857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Wed, 15 Jul 2020 17:31:40 +0200 Subject: [PATCH 38/62] Make sure the VFS files have write permissions --- src/mono/wasm/runtime/library_mono.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 0364358bd3bb08..9c6b46168861e9 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -634,7 +634,7 @@ var MonoSupportLib = { var fileRet = ctx.createDataFile ( parentDirectory, fileName, - bytes, true, false, true + bytes, true /* canRead */, true /* canWrite */, true /* canOwn */ ); break; From 88a776a977bae99e72a8890248153465ad92d132 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 15 Jul 2020 21:27:17 +0300 Subject: [PATCH 39/62] Address feedback --- eng/Version.Details.xml | 2 +- .../tests/CultureInfo/CultureInfoEnglishName.cs | 10 ++++++++-- .../tests/CultureInfo/CultureInfoNativeName.cs | 2 ++ .../src/System.Private.CoreLib.Shared.projitems | 4 ++-- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 92f91bce67bfb5..f68032aef04a8e 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -120,7 +120,7 @@ https://github.com/dotnet/icu - bf5a3a643815a8a46693d618d08dbc96f353ca9e + d75e68181dfd8cad98dfd1c42c3ac2f893690d66 https://github.com/dotnet/llvm-project diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index 1abff4ff15b1f7..271d181560f098 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -12,9 +12,15 @@ public static IEnumerable EnglishName_TestData() { yield return new object[] { CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.EnglishName }; yield return new object[] { "en-US", "English (United States)" }; - if (PlatformDetection.IsNotBrowser) - // Browser's ICU returns "French (FR)" instead for "fr-FR" + if (PlatformDetection.IsBrowser) + { + // Browser's ICU returns "French (FR)" for "fr-FR" + yield return new object[] { "fr-FR", "French (FR)" }; + } + else + { yield return new object[] { "fr-FR", "French (France)" }; + } } [Theory] diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs index 7a54d3123b942c..89eb9f1f580809 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs @@ -13,8 +13,10 @@ public static IEnumerable NativeName_TestData() yield return new object[] { CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.NativeName }; yield return new object[] { "en-US", "English (United States)" }; if (PlatformDetection.IsNotBrowser) + { // Browser's ICU doesn't contain en-CA locale yield return new object[] { "en-CA", "English (Canada)" }; + } } [Theory] diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 5da6da57e9cfb7..e3fa7e8ec54ffb 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1069,10 +1069,10 @@ Common\Interop\Interop.ResultCode.cs - + Common\Interop\Interop.TimeZoneInfo.cs - + Common\Interop\Interop.TimeZoneInfo.Stub.cs From 30af86f6f2b0005e50ff0085153194b900db2f6a Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 15 Jul 2020 22:18:47 +0300 Subject: [PATCH 40/62] Disable two tests in System.Runtime.Extensions --- .../System.Runtime.Extensions/tests/System/AppDomainTests.cs | 1 + .../tests/System/Reflection/AssemblyNameProxyTests.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs b/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs index 3fa95271ee2c50..89ec53ebd419bd 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/AppDomainTests.cs @@ -358,6 +358,7 @@ public void Load() } [Fact] + [PlatformSpecific(~TestPlatforms.Browser)] public void LoadBytes() { Assembly assembly = typeof(AppDomainTests).Assembly; diff --git a/src/libraries/System.Runtime.Extensions/tests/System/Reflection/AssemblyNameProxyTests.cs b/src/libraries/System.Runtime.Extensions/tests/System/Reflection/AssemblyNameProxyTests.cs index 14dc0a0f1d0bce..39059fa7eba11f 100644 --- a/src/libraries/System.Runtime.Extensions/tests/System/Reflection/AssemblyNameProxyTests.cs +++ b/src/libraries/System.Runtime.Extensions/tests/System/Reflection/AssemblyNameProxyTests.cs @@ -13,6 +13,7 @@ namespace System.Reflection.Tests public static class AssemblyNameProxyTests { [Fact] + [PlatformSpecific(~TestPlatforms.Browser)] public static void GetAssemblyName_AssemblyNameProxy() { AssemblyNameProxy anp = new AssemblyNameProxy(); From 801b95e3bf18280ab51b8f728ba262792846f859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Wed, 15 Jul 2020 21:25:39 +0200 Subject: [PATCH 41/62] Add satellite assemblies to VFS --- eng/testing/tests.mobile.targets | 9 ++++++++- .../tests/AssemblyLoadContextTest.cs | 1 + .../System.Runtime.Loader/tests/SatelliteAssemblies.cs | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index 7af89d547f5857..0bcf34850d14b3 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -121,10 +121,17 @@ AssemblyFile="$(WasmAppBuilderTasksAssemblyPath)" /> + + + + $([System.IO.Directory]::GetParent('%(Identity)').Name) + + - + + diff --git a/src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs b/src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs index 3979d76aeadb74..290cb3ca06b3da 100644 --- a/src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs +++ b/src/libraries/System.Runtime.Loader/tests/AssemblyLoadContextTest.cs @@ -18,6 +18,7 @@ public partial class AssemblyLoadContextTest private const string TestAssemblyNotSupported = "System.Runtime.Loader.Test.AssemblyNotSupported"; [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/39379", TestPlatforms.Browser)] public static void GetAssemblyNameTest_ValidAssembly() { var expectedName = typeof(AssemblyLoadContextTest).Assembly.GetName(); diff --git a/src/libraries/System.Runtime.Loader/tests/SatelliteAssemblies.cs b/src/libraries/System.Runtime.Loader/tests/SatelliteAssemblies.cs index b82c314a815f8a..658d1f42a12870 100644 --- a/src/libraries/System.Runtime.Loader/tests/SatelliteAssemblies.cs +++ b/src/libraries/System.Runtime.Loader/tests/SatelliteAssemblies.cs @@ -189,6 +189,7 @@ public static IEnumerable SatelliteLoadsCorrectly_TestData() [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotInvariantGlobalization))] [MemberData(nameof(SatelliteLoadsCorrectly_TestData))] + [ActiveIssue("https://github.com/dotnet/runtime/issues/39379", TestPlatforms.Browser)] public void SatelliteLoadsCorrectly(string alc, string assemblyName, string culture) { AssemblyName satelliteAssemblyName = new AssemblyName(assemblyName + ".resources"); From c06c63b78e439b3d9c7e34596e11da288021a123 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 15 Jul 2020 23:18:23 +0300 Subject: [PATCH 42/62] EnglishName_TestData is back to normal for ICU --- .../tests/CultureInfo/CultureInfoEnglishName.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs index 271d181560f098..23c2032c51cd41 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoEnglishName.cs @@ -12,15 +12,7 @@ public static IEnumerable EnglishName_TestData() { yield return new object[] { CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.EnglishName }; yield return new object[] { "en-US", "English (United States)" }; - if (PlatformDetection.IsBrowser) - { - // Browser's ICU returns "French (FR)" for "fr-FR" - yield return new object[] { "fr-FR", "French (FR)" }; - } - else - { - yield return new object[] { "fr-FR", "French (France)" }; - } + yield return new object[] { "fr-FR", "French (France)" }; } [Theory] From 2e4ed37827adb53f732c2ae9d0daf82fce8ce0ef Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 15 Jul 2020 13:23:43 -0700 Subject: [PATCH 43/62] Create and populate MONO.loaded_files --- src/mono/wasm/runtime/library_mono.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 9c6b46168861e9..52258b49e76673 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -599,8 +599,9 @@ var MonoSupportLib = { var offset = null; switch (asset.behavior) { - case "heap": case "assembly": + ctx.loaded_files.push (virtualName); + case "heap": case "icu": offset = this._load_bytes_into_heap (bytes); ctx.loaded_assets[virtualName] = [offset, bytes.length]; @@ -690,6 +691,7 @@ var MonoSupportLib = { // "icu": load ICU globalization data from any runtime assets with behavior "icu". // "invariant": operate in invariant globalization mode. // "auto" (default): if "icu" behavior assets are present, use ICU, otherwise invariant. + // diagnostic_tracing: (optional) enables diagnostic log messages during startup mono_load_runtime_and_bcl_args: function (args) { try { return this._load_assets_and_runtime (args); @@ -701,8 +703,11 @@ var MonoSupportLib = { _finalize_startup: function (args, ctx) { MONO.loaded_assets = ctx.loaded_assets; - if (ctx.tracing) + MONO.loaded_files = ctx.loaded_files; + if (ctx.tracing) { console.log ("MONO_WASM: loaded_assets: " + JSON.stringify(ctx.loaded_assets)); + console.log ("MONO_WASM: loaded_files: " + JSON.stringify(ctx.loaded_files)); + } var load_runtime = Module.cwrap ('mono_wasm_load_runtime', null, ['string', 'number']); @@ -746,6 +751,8 @@ var MonoSupportLib = { mono_wasm_add_assembly: Module.cwrap ('mono_wasm_add_assembly', null, ['string', 'number', 'number']), mono_wasm_load_icu_data: Module.cwrap ('mono_wasm_load_icu_data', 'number', ['number']), loaded_assets: Object.create (null), + // dlls and pdbs, used by blazor and the debugger + loaded_files: [], createPath: Module['FS_createPath'], createDataFile: Module['FS_createDataFile'], num_icu_assets_loaded_successfully: 0 @@ -885,8 +892,9 @@ var MonoSupportLib = { this.mono_wasm_setenv ("DOTNET_SYSTEM_GLOBALIZATION_INVARIANT", "1"); }, + // Used by the debugger to enumerate loaded dlls and pdbs mono_wasm_get_loaded_files: function() { - return Object.keys(MONO.loaded_assets); + return MONO.loaded_files; }, mono_wasm_get_loaded_asset_table: function() { From 855b840b538aec6f8614230f6c65270297f22571 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Wed, 15 Jul 2020 22:42:36 +0200 Subject: [PATCH 44/62] Add icu data file to runtimepack --- eng/liveBuilds.targets | 3 ++- eng/testing/tests.mobile.targets | 6 +----- src/libraries/Native/native-binplace.proj | 1 + src/mono/netcore/sample/wasm/WasmSample.csproj | 5 ----- src/mono/wasm/Makefile | 5 ++++- .../tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs | 6 ++---- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/eng/liveBuilds.targets b/eng/liveBuilds.targets index 763b369167db5c..e7cd12b6a4eaa8 100644 --- a/eng/liveBuilds.targets +++ b/eng/liveBuilds.targets @@ -191,7 +191,8 @@ Include=" $(LibrariesNativeArtifactsPath)dotnet.js; $(LibrariesNativeArtifactsPath)dotnet.wasm; - $(LibrariesNativeArtifactsPath)dotnet.timezones.blat;" + $(LibrariesNativeArtifactsPath)dotnet.timezones.blat; + $(LibrariesNativeArtifactsPath)icudt.dat;" IsNative="true" /> diff --git a/eng/testing/tests.mobile.targets b/eng/testing/tests.mobile.targets index 0bcf34850d14b3..266a6d37be6518 100644 --- a/eng/testing/tests.mobile.targets +++ b/eng/testing/tests.mobile.targets @@ -146,7 +146,6 @@ - - + AssemblySearchPaths="@(AssemblySearchPaths)"/> + diff --git a/src/mono/netcore/sample/wasm/WasmSample.csproj b/src/mono/netcore/sample/wasm/WasmSample.csproj index 6faa51c18888b9..b9d0ff122bf44d 100644 --- a/src/mono/netcore/sample/wasm/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/WasmSample.csproj @@ -38,11 +38,6 @@ - - - - ? _assemblies; Resolver? _resolver; @@ -73,7 +72,7 @@ public override bool Execute () Directory.CreateDirectory(Path.Join(AppDir, "managed")); foreach (var assembly in _assemblies!.Values) File.Copy(assembly.Location, Path.Join(AppDir, "managed", Path.GetFileName(assembly.Location)), true); - foreach (var f in new string[] { "dotnet.wasm", "dotnet.js", "dotnet.timezones.blat" }) + foreach (var f in new string[] { "dotnet.wasm", "dotnet.js", "dotnet.timezones.blat", "icudt.dat" }) File.Copy(Path.Join (MicrosoftNetCoreAppRuntimePackDir, "native", f), Path.Join(AppDir, f), true); File.Copy(MainJS!, Path.Join(AppDir, "runtime.js"), true); @@ -121,8 +120,7 @@ public override bool Execute () var enableRemote = (RemoteSources != null) && (RemoteSources!.Length > 0); var sEnableRemote = enableRemote ? "true" : "false"; - foreach (var asset in ICUDataFiles!) - sw.WriteLine($"\t\t{{ behavior: \"icu\", name: \"{asset.ItemSpec}\", load_remote: {sEnableRemote} }},"); + sw.WriteLine($"\t\t{{ behavior: \"icu\", name: \"icudt.dat\", load_remote: {sEnableRemote} }},"); sw.WriteLine ("\t],"); From 4ea64d92222565b53ce034c885603e7b7c3a669b Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 15 Jul 2020 13:53:43 -0700 Subject: [PATCH 45/62] Adjust public interface for various bits of setup --- src/mono/wasm/runtime/library_mono.js | 49 +++++++++++++++++---------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 52258b49e76673..23e2fad6b23315 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -584,13 +584,6 @@ var MonoSupportLib = { } }, - _load_bytes_into_heap: function (bytes) { - var memoryOffset = Module._malloc (bytes.length); - var heapBytes = new Uint8Array (Module.HEAPU8.buffer, memoryOffset, bytes.length); - heapBytes.set (bytes); - return memoryOffset; - }, - _handle_loaded_asset: function (ctx, asset, blob) { var bytes = new Uint8Array (blob); console.log ("MONO_WASM: Loaded:", asset.name, bytes.length); @@ -603,7 +596,7 @@ var MonoSupportLib = { ctx.loaded_files.push (virtualName); case "heap": case "icu": - offset = this._load_bytes_into_heap (bytes); + offset = this.mono_wasm_load_bytes_into_heap (bytes); ctx.loaded_assets[virtualName] = [offset, bytes.length]; break; @@ -647,7 +640,7 @@ var MonoSupportLib = { if (asset.behavior === "assembly") ctx.mono_wasm_add_assembly (virtualName, offset, bytes.length); else if (asset.behavior === "icu") { - if (ctx.mono_wasm_load_icu_data (offset) === 1) + if (this.mono_wasm_load_icu_data (offset)) ctx.num_icu_assets_loaded_successfully += 1; else console.error ("Error loading ICU asset", asset.name); @@ -701,6 +694,24 @@ var MonoSupportLib = { } }, + // @bytes must be a typed array. space is allocated for it in the native heap + // and it is copied to that location. returns the address of the allocation. + mono_wasm_load_bytes_into_heap: function (bytes) { + var memoryOffset = Module._malloc (bytes.length); + var heapBytes = new Uint8Array (Module.HEAPU8.buffer, memoryOffset, bytes.length); + heapBytes.set (bytes); + return memoryOffset; + }, + + // @offset must be the address of an ICU data archive in the native heap. + // returns true on success. + mono_wasm_load_icu_data: function (offset) { + var fn = Module.cwrap ('mono_wasm_load_icu_data', 'number', ['number']); + var ok = (fn (offset)) === 1; + if (ok) + this.num_icu_assets_loaded_successfully++; + }, + _finalize_startup: function (args, ctx) { MONO.loaded_assets = ctx.loaded_assets; MONO.loaded_files = ctx.loaded_files; @@ -713,7 +724,7 @@ var MonoSupportLib = { console.log ("MONO_WASM: Initializing mono runtime"); - this._globalization_init (args, ctx); + this.mono_wasm_globalization_init (args.globalization_mode); if (ENVIRONMENT_IS_SHELL || ENVIRONMENT_IS_NODE) { try { @@ -745,17 +756,17 @@ var MonoSupportLib = { if (!args.loaded_cb) throw new Error ("loaded_cb not provided"); + this.num_icu_assets_loaded_successfully = 0; + var ctx = { tracing: args.diagnostic_tracing || false, pending_count: args.assets.length, mono_wasm_add_assembly: Module.cwrap ('mono_wasm_add_assembly', null, ['string', 'number', 'number']), - mono_wasm_load_icu_data: Module.cwrap ('mono_wasm_load_icu_data', 'number', ['number']), loaded_assets: Object.create (null), // dlls and pdbs, used by blazor and the debugger loaded_files: [], createPath: Module['FS_createPath'], - createDataFile: Module['FS_createDataFile'], - num_icu_assets_loaded_successfully: 0 + createDataFile: Module['FS_createDataFile'] }; if (ctx.tracing) @@ -869,16 +880,20 @@ var MonoSupportLib = { }); }, - _globalization_init: function (args, ctx) { + // Performs setup for globalization. + // @globalization_mode is one of "icu", "invariant", or "auto". + // "auto" will use "icu" if any ICU data archives have been loaded, + // otherwise "invariant". + mono_wasm_globalization_init: function (globalization_mode) { var invariantMode = false; - if (args.globalization_mode === "invariant") + if (globalization_mode === "invariant") invariantMode = true; if (!invariantMode) { - if (ctx.num_icu_assets_loaded_successfully > 0) { + if (this.num_icu_assets_loaded_successfully > 0) { console.log ("MONO_WASM: ICU data archive(s) loaded, disabling invariant mode"); - } else if (args.globalization_mode !== "icu") { + } else if (globalization_mode !== "icu") { console.log ("MONO_WASM: ICU data archive(s) not loaded, using invariant globalization mode"); invariantMode = true; } else { From 3fb2ec9e674806f252b956a0d8147e0290a5ac31 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 15 Jul 2020 14:37:31 -0700 Subject: [PATCH 46/62] Add compatibility shim for runtime_and_bcl, export some APIs --- src/mono/wasm/runtime/library_mono.js | 38 +++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 23e2fad6b23315..a5f6d5ead77f73 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -25,6 +25,11 @@ var MonoSupportLib = { export_functions: function (module) { module ["pump_message"] = MONO.pump_message; module ["mono_load_runtime_and_bcl"] = MONO.mono_load_runtime_and_bcl; + module ["mono_load_runtime_and_bcl_args"] = MONO.mono_load_runtime_and_bcl_args; + module ["mono_wasm_load_bytes_into_heap"] = MONO.mono_wasm_load_bytes_into_heap; + module ["mono_wasm_load_icu_data"] = MONO.mono_wasm_load_icu_data; + module ["mono_wasm_globalization_init"] = MONO.mono_wasm_globalization_init; + module ["mono_wasm_get_loaded_files"] = MONO.mono_wasm_get_loaded_files; }, mono_text_decoder: undefined, @@ -647,6 +652,35 @@ var MonoSupportLib = { } }, + // deprecated + mono_load_runtime_and_bcl: function ( + unused_vfs_prefix, deploy_prefix, enable_debugging, file_list, loaded_cb, fetch_file_cb + ) { + var args = { + fetch_file_cb: fetch_file_cb, + loaded_cb: loaded_cb, + enable_debugging: enable_debugging, + assembly_root: deploy_prefix, + assets: [] + }; + + for (var i = 0; i < file_list.length; i++) { + var file_name = file_list[i]; + var behavior; + if (file_name === "icudt.dat") + behavior = "icu"; + else // if (file_name.endsWith (".pdb") || file_name.endsWith (".dll")) + behavior = "assembly"; + + args.assets.push ({ + name: file_name, + behavior: behavior + }); + } + + return this.mono_load_runtime_and_bcl_args (args); + }, + // Initializes the runtime and loads assemblies, debug information, and other files. // @args is a dictionary-style Object with the following properties: // assembly_root: (required) the subfolder containing managed assemblies and pdbs @@ -703,6 +737,8 @@ var MonoSupportLib = { return memoryOffset; }, + num_icu_assets_loaded_successfully: 0, + // @offset must be the address of an ICU data archive in the native heap. // returns true on success. mono_wasm_load_icu_data: function (offset) { @@ -756,8 +792,6 @@ var MonoSupportLib = { if (!args.loaded_cb) throw new Error ("loaded_cb not provided"); - this.num_icu_assets_loaded_successfully = 0; - var ctx = { tracing: args.diagnostic_tracing || false, pending_count: args.assets.length, From da898348aa7fe9fe1b005cdfb881b46ba3834897 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 15 Jul 2020 14:42:11 -0700 Subject: [PATCH 47/62] Remove now-broken ICUDataFiles parameter from csproj --- src/mono/netcore/sample/wasm/WasmSample.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/mono/netcore/sample/wasm/WasmSample.csproj b/src/mono/netcore/sample/wasm/WasmSample.csproj index b9d0ff122bf44d..275c2be333060c 100644 --- a/src/mono/netcore/sample/wasm/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/WasmSample.csproj @@ -44,8 +44,7 @@ MainAssembly="bin\WasmSample.dll" MainJS="$(MonoProjectRoot)wasm\runtime-test.js" AssemblySearchPaths="@(AssemblySearchPaths)" - RemoteSources="@(RemoteSources)" - ICUDataFiles="@(ICUDataFiles)" /> + RemoteSources="@(RemoteSources)"/> From 4ac3230497929a5dfdad70d1c27c847e073cc311 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 15 Jul 2020 14:54:10 -0700 Subject: [PATCH 48/62] Fix spurious ICU load error --- src/mono/wasm/runtime/library_mono.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index a5f6d5ead77f73..5c1fa6d21b0110 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -746,6 +746,7 @@ var MonoSupportLib = { var ok = (fn (offset)) === 1; if (ok) this.num_icu_assets_loaded_successfully++; + return ok; }, _finalize_startup: function (args, ctx) { From 279ec28174fc0e5cf6c45324eca031d48917f17e Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Wed, 15 Jul 2020 15:56:31 -0700 Subject: [PATCH 49/62] Store asset URLs into loaded_files instead of names --- src/mono/wasm/runtime/library_mono.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/mono/wasm/runtime/library_mono.js b/src/mono/wasm/runtime/library_mono.js index 5c1fa6d21b0110..e137e8940a0c82 100644 --- a/src/mono/wasm/runtime/library_mono.js +++ b/src/mono/wasm/runtime/library_mono.js @@ -589,16 +589,19 @@ var MonoSupportLib = { } }, - _handle_loaded_asset: function (ctx, asset, blob) { + _handle_loaded_asset: function (ctx, asset, url, blob) { var bytes = new Uint8Array (blob); - console.log ("MONO_WASM: Loaded:", asset.name, bytes.length); + if (ctx.tracing) + console.log ("MONO_WASM: Loaded:", asset.name, "size", bytes.length, "from", url); + else + console.log ("MONO_WASM: Loaded:", asset.name); var virtualName = asset.virtual_path || asset.name; var offset = null; switch (asset.behavior) { case "assembly": - ctx.loaded_files.push (virtualName); + ctx.loaded_files.push (url); case "heap": case "icu": offset = this.mono_wasm_load_bytes_into_heap (bytes); @@ -824,9 +827,9 @@ var MonoSupportLib = { } }; - var processFetchResponseBuffer = function (asset, blob) { + var processFetchResponseBuffer = function (asset, url, blob) { try { - MONO._handle_loaded_asset (ctx, asset, blob); + MONO._handle_loaded_asset (ctx, asset, url, blob); } catch (exc) { console.error ("Unhandled exception in processFetchResponseBuffer", exc); throw exc; @@ -853,7 +856,7 @@ var MonoSupportLib = { try { var bufferPromise = response ['arrayBuffer'] (); - bufferPromise.then (processFetchResponseBuffer.bind (this, asset)); + bufferPromise.then (processFetchResponseBuffer.bind (this, asset, response.url)); } catch (exc) { console.error ("MONO_WASM: Unhandled exception in handleFetchResponse for asset", asset.name, exc); attemptNextSource (); From 23ea27c35d6a067e0c657d3ab2c9ddcab89e03ea Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 02:19:03 +0300 Subject: [PATCH 50/62] Address feedback --- ...eInfo.cs => Interop.TimeZoneInfo.AnyOS.cs} | 0 ...tub.cs => Interop.TimeZoneInfo.Browser.cs} | 1 + .../CultureInfo/CultureInfoNativeName.cs | 6 +--- .../DateTimeFormatInfoCalendarWeekRule.cs | 9 ++++- .../DateTimeFormatInfoTests.cs | 3 +- ...NumberFormatInfoCurrencyNegativePattern.cs | 30 +++++++++-------- .../System/Globalization/TextInfoTests.cs | 33 +++++++++---------- .../System.Private.CoreLib.Shared.projitems | 8 ++--- 8 files changed, 48 insertions(+), 42 deletions(-) rename src/libraries/Common/src/Interop/{Interop.TimeZoneInfo.cs => Interop.TimeZoneInfo.AnyOS.cs} (100%) rename src/libraries/Common/src/Interop/{Interop.TimeZoneInfo.Stub.cs => Interop.TimeZoneInfo.Browser.cs} (99%) diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.AnyOS.cs similarity index 100% rename from src/libraries/Common/src/Interop/Interop.TimeZoneInfo.cs rename to src/libraries/Common/src/Interop/Interop.TimeZoneInfo.AnyOS.cs diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Stub.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs similarity index 99% rename from src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Stub.cs rename to src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs index d5f51f70658861..315379d8702ce9 100644 --- a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Stub.cs +++ b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs @@ -1,3 +1,4 @@ + // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. diff --git a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs index 89eb9f1f580809..b97a645b8b2a57 100644 --- a/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs +++ b/src/libraries/System.Globalization/tests/CultureInfo/CultureInfoNativeName.cs @@ -12,11 +12,7 @@ public static IEnumerable NativeName_TestData() { yield return new object[] { CultureInfo.CurrentCulture.Name, CultureInfo.CurrentCulture.NativeName }; yield return new object[] { "en-US", "English (United States)" }; - if (PlatformDetection.IsNotBrowser) - { - // Browser's ICU doesn't contain en-CA locale - yield return new object[] { "en-CA", "English (Canada)" }; - } + yield return new object[] { "en-CA", "English (Canada)" }; } [Theory] diff --git a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoCalendarWeekRule.cs b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoCalendarWeekRule.cs index 89097f9788a491..2d0bd120bd307d 100644 --- a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoCalendarWeekRule.cs +++ b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoCalendarWeekRule.cs @@ -13,8 +13,15 @@ public static IEnumerable CalendarWeekRule_Get_TestData() yield return new object[] { DateTimeFormatInfo.InvariantInfo, CalendarWeekRule.FirstDay }; yield return new object[] { new CultureInfo("en-US").DateTimeFormat, CalendarWeekRule.FirstDay }; - if (PlatformDetection.IsNotBrowser) // "br-FR" is not presented in Browser's ICU + if (PlatformDetection.IsNotBrowser) + { yield return new object[] { new CultureInfo("br-FR").DateTimeFormat, DateTimeFormatInfoData.BrFRCalendarWeekRule() }; + } + else + { + // "br-FR" is not presented in Browser's ICU. Let's test ru-RU instead. + yield return new object[] { new CultureInfo("ru-RU").DateTimeFormat, CalendarWeekRule.FirstFourDayWeek }; + } } [Theory] diff --git a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs index 5dd96d0464dc16..5e5ed9bbf69ee6 100644 --- a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs +++ b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs @@ -59,8 +59,9 @@ public void DateSeparatorTimeSeparator_Get_ReturnsExpected() Assert.Equal(expectedFormattedString, d.ToString("HH:mm:ss", dtfi)); } + [Theory] // Browser's ICU doesn't support NativeCalendarName - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [PlatformSpecific(~TestPlatforms.Browser)] [MemberData(nameof(DateTimeFormatInfo_TestData))] public void NativeCalendarName_Get_ReturnsExpected(DateTimeFormatInfo dtfi, Calendar calendar, string nativeCalendarName) { diff --git a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyNegativePattern.cs b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyNegativePattern.cs index b20b283313b0e7..76653b6d68af4c 100644 --- a/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyNegativePattern.cs +++ b/src/libraries/System.Globalization/tests/NumberFormatInfo/NumberFormatInfoCurrencyNegativePattern.cs @@ -22,12 +22,24 @@ public void CurrencyNegativePattern_Get_ReturnsExpected(NumberFormatInfo format, Assert.Contains(format.CurrencyNegativePattern, acceptablePatterns); } + public static IEnumerable CurrencyNegativePatternTestLocales() + { + yield return new object[] { "en-US" }; + yield return new object[] { "en-CA" }; + yield return new object[] { "fa-IR" }; + yield return new object[] { "fr-CD" }; + yield return new object[] { "fr-CA" }; + + if (PlatformDetection.IsNotBrowser) + { + // Browser's ICU doesn't contain these locales + yield return new object[] { "as" }; + yield return new object[] { "es-BO" }; + } + } + [Theory] - [InlineData("en-US")] - [InlineData("en-CA")] - [InlineData("fa-IR")] - [InlineData("fr-CD")] - [InlineData("fr-CA")] + [MemberData(nameof(CurrencyNegativePatternTestLocales))] public void CurrencyNegativePattern_Get_ReturnsExpected_ByLocale(string locale) { CultureInfo culture; @@ -44,14 +56,6 @@ public void CurrencyNegativePattern_Get_ReturnsExpected_ByLocale(string locale) Assert.Contains(format.CurrencyNegativePattern, NumberFormatInfoData.GetCurrencyNegativePatterns(locale)); } - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] - [InlineData("as")] // Browser's ICU doesn't contain these locales - [InlineData("es-BO")] - public void CurrencyNegativePattern_Get_ReturnsExpected_ByLocale_NotBrowser(string locale) - { - CurrencyNegativePattern_Get_ReturnsExpected_ByLocale(locale); - } - [Theory] [InlineData(0)] [InlineData(1)] diff --git a/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs b/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs index f489b4d97f511e..099f9c24fb4226 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/TextInfoTests.cs @@ -183,6 +183,19 @@ public static IEnumerable ToLower_TestData_netcore() } } + public static IEnumerable GetTestLocales() + { + yield return "tr"; + yield return "tr-TR"; + + if (PlatformDetection.IsNotBrowser) + { + // Browser's ICU doesn't contain these locales + yield return "az"; + yield return "az-Latn-AZ"; + } + } + public static IEnumerable ToLower_TestData() { foreach (string cultureName in s_cultureNames) @@ -226,15 +239,7 @@ public static IEnumerable ToLower_TestData() yield return new object[] { cultureName, "\u03A3", "\u03C3" }; } - var locales = new List { "tr", "tr-TR"}; - if (PlatformDetection.IsNotBrowser) - { - // Browser's ICU doesn't contain these locales - locales.Add("az"); - locales.Add("az-Latn-AZ"); - } - - foreach (string cultureName in locales) + foreach (string cultureName in GetTestLocales()) { yield return new object[] { cultureName, "\u0130", "i" }; yield return new object[] { cultureName, "i", "i" }; @@ -356,16 +361,8 @@ public static IEnumerable ToUpper_TestData() yield return new object[] { cultureName, "\u0149", "\u0149" }; } - var locales = new List { "tr", "tr-TR"}; - if (PlatformDetection.IsNotBrowser) - { - // Browser's ICU doesn't contain these locales - locales.Add("az"); - locales.Add("az-Latn-AZ"); - } - // Turkish i - foreach (string cultureName in locales) + foreach (string cultureName in GetTestLocales()) { yield return new object[] { cultureName, "i", "\u0130" }; yield return new object[] { cultureName, "\u0130", "\u0130" }; diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index e3fa7e8ec54ffb..1e2a5c46b86b15 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1069,11 +1069,11 @@ Common\Interop\Interop.ResultCode.cs - - Common\Interop\Interop.TimeZoneInfo.cs + + Common\Interop\Interop.TimeZoneInfo.AnyOS.cs - - Common\Interop\Interop.TimeZoneInfo.Stub.cs + + Common\Interop\Interop.TimeZoneInfo.Browser.cs Common\Interop\Interop.Utils.cs From cafd0f2d444b55f55f6f7d847c1657003cd5398c Mon Sep 17 00:00:00 2001 From: Larry Ewing Date: Wed, 15 Jul 2020 19:00:59 -0500 Subject: [PATCH 51/62] Update src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs --- src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs index 315379d8702ce9..d5f51f70658861 100644 --- a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs +++ b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs @@ -1,4 +1,3 @@ - // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. From 3eaa5fba62fd8ee273edef20ee500af18446068b Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Thu, 16 Jul 2020 01:40:05 -0700 Subject: [PATCH 52/62] Revert sample changes --- src/mono/netcore/sample/wasm/Program.cs | 7 +++---- src/mono/netcore/sample/wasm/WasmSample.csproj | 9 ++------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/mono/netcore/sample/wasm/Program.cs b/src/mono/netcore/sample/wasm/Program.cs index c65e90fdf494e4..85a347fe3371fe 100644 --- a/src/mono/netcore/sample/wasm/Program.cs +++ b/src/mono/netcore/sample/wasm/Program.cs @@ -1,3 +1,4 @@ +// -*- indent-tabs-mode: nil -*- // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. @@ -5,9 +6,7 @@ public class Test { - public static void Main(String[] args) - { - Console.WriteLine("Hello, World!"); - Console.WriteLine(DateTime.Now.ToLongDateString()); + public static void Main (String[] args) { + Console.WriteLine ("Hello, World!"); } } diff --git a/src/mono/netcore/sample/wasm/WasmSample.csproj b/src/mono/netcore/sample/wasm/WasmSample.csproj index 275c2be333060c..c84daac2e9f92b 100644 --- a/src/mono/netcore/sample/wasm/WasmSample.csproj +++ b/src/mono/netcore/sample/wasm/WasmSample.csproj @@ -25,7 +25,7 @@ Targets="Build;Publish"/> - @@ -34,17 +34,12 @@ - - - - + AssemblySearchPaths="@(AssemblySearchPaths)"/> From 794e290b0f852ef3d4451d682410ffd5cfe5632a Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Thu, 16 Jul 2020 03:47:28 -0700 Subject: [PATCH 53/62] Update src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alexander Köplinger --- .../Unix/System.Globalization.Native/pal_icushim_static.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c index 79fc6b387f77d4..a6a04076154fa4 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c @@ -12,7 +12,8 @@ #include #include -static void log_icu_error (const char * name, UErrorCode status) { +static void log_icu_error(const char * name, UErrorCode status) +{ const char * statusText = u_errorName(status); fprintf(stderr, "ICU call %s failed with error #%d '%s'.\n", name, status, statusText); } From 34867d7cadebf6573a95b224670c9dc547cf8539 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 13:57:46 +0300 Subject: [PATCH 54/62] enable NativeCalendarName and RegionInfo.NativeName tests for wasm --- .../tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs | 2 -- .../tests/System/Globalization/RegionInfoTests.cs | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs index 5e5ed9bbf69ee6..1689c9e312d2db 100644 --- a/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs +++ b/src/libraries/System.Globalization/tests/DateTimeFormatInfo/DateTimeFormatInfoTests.cs @@ -60,8 +60,6 @@ public void DateSeparatorTimeSeparator_Get_ReturnsExpected() } [Theory] - // Browser's ICU doesn't support NativeCalendarName - [PlatformSpecific(~TestPlatforms.Browser)] [MemberData(nameof(DateTimeFormatInfo_TestData))] public void NativeCalendarName_Get_ReturnsExpected(DateTimeFormatInfo dtfi, Calendar calendar, string nativeCalendarName) { diff --git a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs index 26aeec63a09d09..dd99a40e94ca83 100644 --- a/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs +++ b/src/libraries/System.Globalization/tests/System/Globalization/RegionInfoTests.cs @@ -90,8 +90,7 @@ public void DisplayName(string name, string expected) } } - // RegionInfo.NativeName is not supported by Browser's ICU - [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] + [Theory] [InlineData("GB", "United Kingdom")] [InlineData("SE", "Sverige")] [InlineData("FR", "France")] From fe0e6868e74006ee96615ace75ed8cb84822fdb8 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 14:01:59 +0300 Subject: [PATCH 55/62] Update Version.Details.xml --- eng/Version.Details.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 9e4048cd4a2d33..84a36a50ab2107 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -122,10 +122,6 @@ https://github.com/dotnet/runtime-assets b34a70799faa67f13c2e72852e4f3af463ff4d6c - - https://github.com/dotnet/icu - d75e68181dfd8cad98dfd1c42c3ac2f893690d66 - https://github.com/dotnet/llvm-project 266c9f5b5c1e94333e01ca77fa74d76563969842 From 9b20a788038e8c60041f4ba9c79858fb33ee97ea Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 14:03:39 +0300 Subject: [PATCH 56/62] bump ICU --- eng/Version.Details.xml | 4 ++-- eng/Versions.props | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index 84a36a50ab2107..7607e1d6887d4f 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -4,9 +4,9 @@ https://github.com/dotnet/standard cfe95a23647c7de1fe1a349343115bd7720d6949 - + https://github.com/dotnet/icu - bf5a3a643815a8a46693d618d08dbc96f353ca9e + 7247fa0d9e8faee2cceee6f04856b2c447f41bca diff --git a/eng/Versions.props b/eng/Versions.props index d2c524414b1f6e..46813edef93ede 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -118,7 +118,7 @@ 5.0.0-preview.3.20363.5 - 5.0.0-preview.8.20364.2 + 5.0.0-preview.8.20365.1 9.0.1-alpha.1.20356.1 9.0.1-alpha.1.20356.1 From 49097beec8fc9e61022ff9e15a2325f38be5cf7d Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 14:34:27 +0300 Subject: [PATCH 57/62] Address feedback --- .../pal_icushim_static.c | 19 ++++++++++--------- .../System/Globalization/CalendarData.Icu.cs | 6 +++--- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c index a6a04076154fa4..41a1956a2743c8 100644 --- a/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c +++ b/src/libraries/Native/Unix/System.Globalization.Native/pal_icushim_static.c @@ -1,6 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. // #include @@ -12,26 +11,28 @@ #include #include -static void log_icu_error(const char * name, UErrorCode status) +static void log_icu_error(const char* name, UErrorCode status) { const char * statusText = u_errorName(status); fprintf(stderr, "ICU call %s failed with error #%d '%s'.\n", name, status, statusText); } -static void U_CALLCONV icu_trace_data (const void *context, int32_t fnNumber, int32_t level, const char *fmt, va_list args) { - char buf [1000]; - utrace_vformat (buf, sizeof (buf), 0, fmt, args); - printf ("[ICUDT] %s: %s\n", utrace_functionName (fnNumber), buf); +static void U_CALLCONV icu_trace_data(const void* context, int32_t fnNumber, int32_t level, const char* fmt, va_list args) +{ + char buf[1000]; + utrace_vformat(buf, sizeof(buf), 0, fmt, args); + printf("[ICUDT] %s: %s\n", utrace_functionName(fnNumber), buf); } #ifdef __EMSCRIPTEN__ #include -EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data (void * pData); +EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data(void * pData); -EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data (void * pData) { +EMSCRIPTEN_KEEPALIVE int32_t mono_wasm_load_icu_data(void * pData) +{ UErrorCode status = 0; - udata_setCommonData (pData, &status); + udata_setCommonData(pData, &status); if (U_FAILURE(status)) { log_icu_error("udata_setCommonData", status); diff --git a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs index cdb550d5d245ee..e5425f8d0a31b3 100644 --- a/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs +++ b/src/libraries/System.Private.CoreLib/src/System/Globalization/CalendarData.Icu.cs @@ -444,14 +444,14 @@ private static unsafe void EnumCalendarInfoCallback(char* calendarStringPtr, Int { try { - var calendarString = new string(calendarStringPtr); + var calendarStringSpan = new ReadOnlySpan(calendarStringPtr, string.wcslen(calendarStringPtr)); ref IcuEnumCalendarsData callbackContext = ref Unsafe.As(ref *(byte*)context); if (callbackContext.DisallowDuplicates) { foreach (string existingResult in callbackContext.Results) { - if (string.Equals(calendarString, existingResult, StringComparison.Ordinal)) + if (string.CompareOrdinal(calendarStringSpan, existingResult) == 0) { // the value is already in the results, so don't add it again return; @@ -459,7 +459,7 @@ private static unsafe void EnumCalendarInfoCallback(char* calendarStringPtr, Int } } - callbackContext.Results.Add(calendarString); + callbackContext.Results.Add(calendarStringSpan.ToString()); } catch (Exception e) { From adc967eb02ef5498ebfc98dc79d0f661f9f987a4 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 14:36:09 +0300 Subject: [PATCH 58/62] Update Interop.TimeZoneInfo.Browser.cs --- src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs index d5f51f70658861..3987eddd594815 100644 --- a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs +++ b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs @@ -1,6 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. using System.Runtime.InteropServices; From 6cf61e0d08caf72358c5c48a3bced229816e5eb8 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 15:24:10 +0300 Subject: [PATCH 59/62] Address feedback --- .../Interop/Interop.TimeZoneInfo.Browser.cs | 27 -------- ...eInfo.AnyOS.cs => Interop.TimeZoneInfo.cs} | 0 .../System.Private.CoreLib.Shared.projitems | 9 ++- ...Info.Unix.TimeZoneDisplayName.Invariant.cs | 13 ++++ .../TimeZoneInfo.Unix.TimeZoneDisplayName.cs | 67 +++++++++++++++++++ .../src/System/TimeZoneInfo.Unix.cs | 47 ------------- 6 files changed, 84 insertions(+), 79 deletions(-) delete mode 100644 src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs rename src/libraries/Common/src/Interop/{Interop.TimeZoneInfo.AnyOS.cs => Interop.TimeZoneInfo.cs} (100%) create mode 100644 src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.Invariant.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.cs diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs deleted file mode 100644 index 3987eddd594815..00000000000000 --- a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.Browser.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System.Runtime.InteropServices; - -internal static partial class Interop -{ - internal static partial class Globalization - { - // needs to be kept in sync with TimeZoneDisplayNameType in System.Globalization.Native - internal enum TimeZoneDisplayNameType - { - Generic = 0, - Standard = 1, - DaylightSavings = 2, - } - - // Mono-WASM specific ICU doesn't contain timezone bits - // so an english fallback will be used instead. - internal static unsafe ResultCode GetTimeZoneDisplayName( - string localeName, - string timeZoneId, - TimeZoneDisplayNameType type, - char* result, - int resultLength) => ResultCode.UnknownError; - } -} diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.AnyOS.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.cs similarity index 100% rename from src/libraries/Common/src/Interop/Interop.TimeZoneInfo.AnyOS.cs rename to src/libraries/Common/src/Interop/Interop.TimeZoneInfo.cs diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 9f4349dd9daf1d..5045d1010635c4 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1071,11 +1071,8 @@ Common\Interop\Interop.ResultCode.cs - - Common\Interop\Interop.TimeZoneInfo.AnyOS.cs - - - Common\Interop\Interop.TimeZoneInfo.Browser.cs + + Common\Interop\Interop.TimeZoneInfo.cs Common\Interop\Interop.Utils.cs @@ -1824,6 +1821,8 @@ + + diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.Invariant.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.Invariant.cs new file mode 100644 index 00000000000000..14b302d86b8015 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.Invariant.cs @@ -0,0 +1,13 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +namespace System +{ + public sealed partial class TimeZoneInfo + { + private unsafe void GetDisplayName(Interop.Globalization.TimeZoneDisplayNameType nameType, string uiCulture, ref string? displayName) + { + displayName = _standardDisplayName; + } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.cs new file mode 100644 index 00000000000000..b557c15384bb46 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.cs @@ -0,0 +1,67 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Buffers; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.IO; +using System.Text; +using System.Threading; +using System.Security; + +using Internal.IO; + +namespace System +{ + public sealed partial class TimeZoneInfo + { + private unsafe void GetDisplayName(Interop.Globalization.TimeZoneDisplayNameType nameType, string uiCulture, ref string? displayName) + { + if (GlobalizationMode.Invariant) + { + displayName = _standardDisplayName; + return; + } + + string? timeZoneDisplayName; + bool result = Interop.CallStringMethod( + (buffer, locale, id, type) => + { + fixed (char* bufferPtr = buffer) + { + return Interop.Globalization.GetTimeZoneDisplayName(locale, id, type, bufferPtr, buffer.Length); + } + }, + uiCulture, + _id, + nameType, + out timeZoneDisplayName); + + if (!result && uiCulture != FallbackCultureName) + { + // Try to fallback using FallbackCultureName just in case we can make it work. + result = Interop.CallStringMethod( + (buffer, locale, id, type) => + { + fixed (char* bufferPtr = buffer) + { + return Interop.Globalization.GetTimeZoneDisplayName(locale, id, type, bufferPtr, buffer.Length); + } + }, + FallbackCultureName, + _id, + nameType, + out timeZoneDisplayName); + } + + // If there is an unknown error, don't set the displayName field. + // It will be set to the abbreviation that was read out of the tzfile. + if (result) + { + displayName = timeZoneDisplayName; + } + } + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs index 7dbcf577a657de..0be8b50a064f6d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.cs @@ -107,53 +107,6 @@ private TimeZoneInfo(byte[] data, string id, bool dstDisabled) ValidateTimeZoneInfo(_id, _baseUtcOffset, _adjustmentRules, out _supportsDaylightSavingTime); } - private unsafe void GetDisplayName(Interop.Globalization.TimeZoneDisplayNameType nameType, string uiCulture, ref string? displayName) - { - if (GlobalizationMode.Invariant) - { - displayName = _standardDisplayName; - return; - } - - string? timeZoneDisplayName; - bool result = Interop.CallStringMethod( - (buffer, locale, id, type) => - { - fixed (char* bufferPtr = buffer) - { - return Interop.Globalization.GetTimeZoneDisplayName(locale, id, type, bufferPtr, buffer.Length); - } - }, - uiCulture, - _id, - nameType, - out timeZoneDisplayName); - - if (!result && uiCulture != FallbackCultureName) - { - // Try to fallback using FallbackCultureName just in case we can make it work. - result = Interop.CallStringMethod( - (buffer, locale, id, type) => - { - fixed (char* bufferPtr = buffer) - { - return Interop.Globalization.GetTimeZoneDisplayName(locale, id, type, bufferPtr, buffer.Length); - } - }, - FallbackCultureName, - _id, - nameType, - out timeZoneDisplayName); - } - - // If there is an unknown error, don't set the displayName field. - // It will be set to the abbreviation that was read out of the tzfile. - if (result) - { - displayName = timeZoneDisplayName; - } - } - /// /// Returns a cloned array of AdjustmentRule objects /// From eff92b44fda525ec3b4818af12d2e7c12adf7835 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 16:30:07 +0300 Subject: [PATCH 60/62] Address feedback --- .../src/System.Private.CoreLib.Shared.projitems | 4 ++-- ....Invariant.cs => TimeZoneInfo.GetDisplayName.Invariant.cs} | 0 ....TimeZoneDisplayName.cs => TimeZoneInfo.GetDisplayName.cs} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/libraries/System.Private.CoreLib/src/System/{TimeZoneInfo.Unix.TimeZoneDisplayName.Invariant.cs => TimeZoneInfo.GetDisplayName.Invariant.cs} (100%) rename src/libraries/System.Private.CoreLib/src/System/{TimeZoneInfo.Unix.TimeZoneDisplayName.cs => TimeZoneInfo.GetDisplayName.cs} (100%) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 5045d1010635c4..3c1fdce2266250 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1821,8 +1821,8 @@ - - + + diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.Invariant.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.GetDisplayName.Invariant.cs similarity index 100% rename from src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.Invariant.cs rename to src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.GetDisplayName.Invariant.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.cs b/src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.GetDisplayName.cs similarity index 100% rename from src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.Unix.TimeZoneDisplayName.cs rename to src/libraries/System.Private.CoreLib/src/System/TimeZoneInfo.GetDisplayName.cs From 7a1a28ed23d400831ddde5b8e01c117df1d286ee Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 16:35:56 +0300 Subject: [PATCH 61/62] ignore Interop.TimeZoneInfo on wasm --- .../Interop/Interop.TimeZoneDisplayNameType.cs | 16 ++++++++++++++++ .../Common/src/Interop/Interop.TimeZoneInfo.cs | 8 -------- .../src/System.Private.CoreLib.Shared.projitems | 5 ++++- 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 src/libraries/Common/src/Interop/Interop.TimeZoneDisplayNameType.cs diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneDisplayNameType.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneDisplayNameType.cs new file mode 100644 index 00000000000000..f46072196eb914 --- /dev/null +++ b/src/libraries/Common/src/Interop/Interop.TimeZoneDisplayNameType.cs @@ -0,0 +1,16 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +internal static partial class Interop +{ + internal static partial class Globalization + { + // needs to be kept in sync with TimeZoneDisplayNameType in System.Globalization.Native + internal enum TimeZoneDisplayNameType + { + Generic = 0, + Standard = 1, + DaylightSavings = 2, + } + } +} diff --git a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.cs b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.cs index 5d848e11ed4643..d1ab917229f21c 100644 --- a/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.cs +++ b/src/libraries/Common/src/Interop/Interop.TimeZoneInfo.cs @@ -7,14 +7,6 @@ internal static partial class Interop { internal static partial class Globalization { - // needs to be kept in sync with TimeZoneDisplayNameType in System.Globalization.Native - internal enum TimeZoneDisplayNameType - { - Generic = 0, - Standard = 1, - DaylightSavings = 2, - } - [DllImport(Libraries.GlobalizationNative, CharSet = CharSet.Unicode, EntryPoint = "GlobalizationNative_GetTimeZoneDisplayName")] internal static extern unsafe ResultCode GetTimeZoneDisplayName( string localeName, diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 3c1fdce2266250..42bbdfe8a33f86 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1071,7 +1071,10 @@ Common\Interop\Interop.ResultCode.cs - + + Common\Interop\Interop.TimeZoneDisplayNameType.cs + + Common\Interop\Interop.TimeZoneInfo.cs From d64d256956d00792a27ad67e413246879b1a12f8 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Thu, 16 Jul 2020 16:41:56 +0300 Subject: [PATCH 62/62] Address feedback --- .../src/System.Private.CoreLib.Shared.projitems | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 42bbdfe8a33f86..2a42d4cbf25016 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -1824,14 +1824,14 @@ - - + +