From fe95ddbe92a298eab2e56ed10e7d6e92c9bb5f0a Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Sat, 11 Mar 2023 01:41:26 +0100 Subject: [PATCH] [wasm] Initial emscripten 3.1.30 support (#81215) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * [wasm] Initial emscripten 3.1.30 support * Update icu dependency * Update emsdk dependency * Use new docker images * Add "icudt68_dat" as JS imported function. It's an undefined symbol in ICU, because we are not linking in a lib, that should in the end be linked out. Updated version of emscripten has by default turned on the LLD_REPORT_UNDEFINED . * Drop build-time support for undefined icudt68_dat. * Fix linker options Should be `--lto-O0` * Fix remaining conflict * Limit new warnings option to browser * Try to force reinstall of certifi * Unset `FROZEN_CACHE` for `embuilder build MINIMAL` * Update emsdk deps * Remove assert for stack address The linker puts stack at 0 sometime, so just check that the stack size is not zero. * Get back the stack base assert For non-wasm targets. Add comment. * Set stack size to 5MB Which was the default size in older emscripten versions. Let see if it is related to some of the issues. * Disable WBT tests with SkiSharp context: https://github.com/dotnet/runtime/issues/82725 * Disable more WBT tests with SkiSharp * Set the stack size also in native targets * Update icu deps * Update emsdk deps * Enable BigInt support Co-authored-by: pavelsavara * Enable BigInt here as well * Temporarily allow undefined symbols To unblock other work. After merge of main we are now again getting linker errors with: .nuget/packages/microsoft.netcore.runtime.icu.transport/8.0.0-preview.3.23128.1/runtimes/browser-wasm/native/lib/libicuuc.a(udata.ao): undefined symbol: icudt68_dat * Try to use pip-system-certs package Co-authored-by: Ankit Jain * Fix merge damage for marking "icudt68_dat" a JS imported function + revert temporal fix. * Try another python certifi package * Try install pip-system-certs for emsdk's python * Try to update machine certs for www.sqlite.org * Refactor + upgrade pip Also use the newer pip-system-certs again * Use new net8 images * Add `-s INCOMING_MODULE_JS_API=print,printErr` * Introduce EmccStackSize msbuild property * Remove FIXME from merge We don't have afterUpdateGlobalBufferAndViews anymore * Fixes around updateMemoryViews * Pass --experimental-wasm-bigint to v8 Ubuntu 18.04 helix image has old v8 * Try multiple --engine-arg options * Revert "Introduce EmccStackSize msbuild property" This reverts commit f67ea5e303421bb89f5521f425f22a82aa5d6f46. * Disable 3 filesystem related tests * Add bigint to AOT test template * Introduce EmccStackSize msbuild property * Update emsdk deps * Update icu deps * Revert "Add `-s INCOMING_MODULE_JS_API=print,printErr`" This reverts commit 889d0366e4438880029c85ac800d4403f713dfff. * Update emsdk deps * Update icu deps * Disable one more file related test --------- Co-authored-by: Marek Fišera Co-authored-by: pavelsavara Co-authored-by: Ankit Jain Co-authored-by: Larry Ewing --- eng/Version.Details.xml | 8 ++-- eng/Versions.props | 4 +- .../common/templates/pipeline-with-resources.yml | 4 +- eng/pipelines/libraries/helix-queues-setup.yml | 2 +- eng/pipelines/mono/update-machine-certs.ps1 | 46 +++++++++++++--------- eng/testing/WasmRunnerAOTTemplate.sh | 10 ++--- eng/testing/WasmRunnerTemplate.sh | 6 ++- eng/testing/tests.browser.targets | 2 +- .../System.IO.FileSystem/tests/File/GetSetTimes.cs | 2 + .../tests/MemoryMappedFile.CreateFromFile.Tests.cs | 1 + .../tests/MemoryMappedViewAccessor.Tests.cs | 1 + src/mono/CMakeLists.txt | 1 + src/mono/mono.proj | 5 +++ src/mono/mono/utils/mono-threads.c | 4 ++ .../Wasm.Build.Tests/Blazor/BuildPublishTests.cs | 1 + .../wasm/Wasm.Build.Tests/Blazor/NativeRefTests.cs | 2 + .../wasm/Wasm.Build.Tests/NativeLibraryTests.cs | 1 + src/mono/wasm/build/WasmApp.Native.targets | 7 +++- src/mono/wasm/build/WasmApp.targets | 4 +- src/mono/wasm/emscripten-version.txt | 2 +- src/mono/wasm/runtime/assets.ts | 16 ++++---- src/mono/wasm/runtime/dotnet.d.ts | 4 +- src/mono/wasm/runtime/es6/dotnet.es6.lib.js | 6 ++- src/mono/wasm/runtime/exports-internal.ts | 2 +- src/mono/wasm/runtime/exports.ts | 8 ++-- src/mono/wasm/runtime/http.ts | 2 +- src/mono/wasm/runtime/icu.ts | 2 +- src/mono/wasm/runtime/invoke-cs.ts | 2 +- src/mono/wasm/runtime/invoke-js.ts | 2 +- src/mono/wasm/runtime/memory.ts | 20 ++-------- src/mono/wasm/runtime/polyfills.ts | 8 ++-- src/mono/wasm/runtime/run.ts | 6 +-- src/mono/wasm/runtime/startup.ts | 8 ++-- src/mono/wasm/runtime/types.ts | 4 +- src/mono/wasm/runtime/types/emscripten.ts | 5 ++- src/mono/wasm/wasm.proj | 14 +++---- src/native/libs/CMakeLists.txt | 4 ++ 37 files changed, 127 insertions(+), 99 deletions(-) diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml index af70e1c..4d1df17 100644 --- a/eng/Version.Details.xml +++ b/eng/Version.Details.xml @@ -1,8 +1,8 @@ - + https://github.com/dotnet/icu - 38d4086df0bf334ccf48e12e257b8759b0c9e97f + ce62ebe8dbfec7cdf79421d32b2c8eac439ad78c https://github.com/dotnet/msquic @@ -85,9 +85,9 @@ b126490cd618d6066ed44e0369b4585e845cf9ab - + https://github.com/dotnet/emsdk - b211c38c398416b516ffab1806b8ba47d49c42da + 352d64e0ce9b99a8cff6207621432a986920ffd9 diff --git a/eng/Versions.props b/eng/Versions.props index f7241f8..2a90537 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -219,7 +219,7 @@ 0.11.4-alpha.23156.1 - 8.0.0-preview.3.23159.2 + 8.0.0-preview.3.23160.1 2.1.7 8.0.0-alpha.1.23156.1 @@ -238,7 +238,7 @@ Note: when the name is updated, make sure to update dependency name in eng/pipelines/common/xplat-setup.yml like - DarcDependenciesChanged.Microsoft_NET_Workload_Emscripten_Current_Manifest-8_0_100_Transport --> - 8.0.0-preview.3.23159.3 + 8.0.0-preview.3.23160.1 $(MicrosoftNETWorkloadEmscriptenCurrentManifest80100TransportVersion) 1.1.87-gba258badda diff --git a/eng/pipelines/common/templates/pipeline-with-resources.yml b/eng/pipelines/common/templates/pipeline-with-resources.yml index 3657fae..e849da7 100644 --- a/eng/pipelines/common/templates/pipeline-with-resources.yml +++ b/eng/pipelines/common/templates/pipeline-with-resources.yml @@ -60,10 +60,10 @@ resources: ROOTFS_DIR: /crossrootfs/ppc64le - container: browser_wasm - image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-webassembly + image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-webassembly-net8 - container: wasi_wasm - image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-20.04-webassembly + image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-20.04-webassembly-net8 - container: freebsd_x64 image: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-18.04-cross-freebsd-12 diff --git a/eng/pipelines/libraries/helix-queues-setup.yml b/eng/pipelines/libraries/helix-queues-setup.yml index 9623ee8..ed34402 100644 --- a/eng/pipelines/libraries/helix-queues-setup.yml +++ b/eng/pipelines/libraries/helix-queues-setup.yml @@ -201,6 +201,6 @@ jobs: # Browser WebAssembly windows - ${{ if in(parameters.platform, 'browser_wasm_win', 'wasi_wasm_win') }}: - - (Windows.Amd64.Server2022.Open)windows.amd64.server2022.open@mcr.microsoft.com/dotnet-buildtools/prereqs:windowsservercore-ltsc2022-helix-webassembly + - (Windows.Amd64.Server2022.Open)windows.amd64.server2022.open@mcr.microsoft.com/dotnet-buildtools/prereqs:windowsservercore-ltsc2022-helix-webassembly-net8 ${{ insert }}: ${{ parameters.jobParameters }} diff --git a/eng/pipelines/mono/update-machine-certs.ps1 b/eng/pipelines/mono/update-machine-certs.ps1 index 21c3da4..e0c877c 100644 --- a/eng/pipelines/mono/update-machine-certs.ps1 +++ b/eng/pipelines/mono/update-machine-certs.ps1 @@ -1,28 +1,38 @@ # This seems to update the machine cert store so that python can download the files as required by emscripten's install # Based on info at https://pypi.org/project/certifi/ -pip install certifi +python -m pip install --upgrade pip +pip install --upgrade certifi pip-system-certs -$WebsiteURL="storage.googleapis.com" -Try { - $Conn = New-Object System.Net.Sockets.TcpClient($WebsiteURL,443) +function UpdateSite { + + param ( + $WebsiteURL + ) Try { - $Stream = New-Object System.Net.Security.SslStream($Conn.GetStream()) - $Stream.AuthenticateAsClient($WebsiteURL) + $Conn = New-Object System.Net.Sockets.TcpClient($WebsiteURL,443) - $Cert = $Stream.Get_RemoteCertificate() + Try { + $Stream = New-Object System.Net.Security.SslStream($Conn.GetStream()) + $Stream.AuthenticateAsClient($WebsiteURL) - $ValidTo = [datetime]::Parse($Cert.GetExpirationDatestring()) + $Cert = $Stream.Get_RemoteCertificate() - Write-Host "`nConnection Successful" -ForegroundColor DarkGreen - Write-Host "Website: $WebsiteURL" - } - Catch { Throw $_ } - Finally { $Conn.close() } - } - Catch { - Write-Host "`nError occurred connecting to $($WebsiteURL)" -ForegroundColor Yellow + $ValidTo = [datetime]::Parse($Cert.GetExpirationDatestring()) + + Write-Host "`nConnection Successful" -ForegroundColor DarkGreen Write-Host "Website: $WebsiteURL" - Write-Host "Status:" $_.exception.innerexception.message -ForegroundColor Yellow - Write-Host "" + } + Catch { Throw $_ } + Finally { $Conn.close() } + } + Catch { + Write-Host "`nError occurred connecting to $($WebsiteURL)" -ForegroundColor Yellow + Write-Host "Website: $WebsiteURL" + Write-Host "Status:" $_.exception.innerexception.message -ForegroundColor Yellow + Write-Host "" + } } + +UpdateSite("storage.googleapis.com") +UpdateSite("www.sqlite.org") diff --git a/eng/testing/WasmRunnerAOTTemplate.sh b/eng/testing/WasmRunnerAOTTemplate.sh index b012eaf..68a94e8 100644 --- a/eng/testing/WasmRunnerAOTTemplate.sh +++ b/eng/testing/WasmRunnerAOTTemplate.sh @@ -32,23 +32,23 @@ if [[ -z "$XHARNESS_COMMAND" ]]; then fi if [[ "$XHARNESS_COMMAND" == "test" ]]; then + if [[ -z "$JS_ENGINE_ARGS" ]]; then + JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000" + fi + if [[ -z "$JS_ENGINE" ]]; then if [[ "$SCENARIO" == "WasmTestOnNodeJS" || "$SCENARIO" == "wasmtestonnodejs" ]]; then JS_ENGINE="--engine=NodeJS" JS_ENGINE_ARGS="$JS_ENGINE_ARGS --engine-arg=--experimental-wasm-simd" else JS_ENGINE="--engine=V8" - JS_ENGINE_ARGS="$JS_ENGINE_ARGS --engine-arg=--experimental-wasm-simd" + JS_ENGINE_ARGS="$JS_ENGINE_ARGS --engine-arg=--experimental-wasm-simd --engine-arg=--experimental-wasm-bigint" fi fi if [[ -z "$MAIN_JS" ]]; then MAIN_JS="--js-file=test-main.js" fi - - if [[ -z "$JS_ENGINE_ARGS" ]]; then - JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000" - fi fi if [[ -z "$XHARNESS_ARGS" ]]; then diff --git a/eng/testing/WasmRunnerTemplate.sh b/eng/testing/WasmRunnerTemplate.sh index 077f891..2238017 100644 --- a/eng/testing/WasmRunnerTemplate.sh +++ b/eng/testing/WasmRunnerTemplate.sh @@ -45,7 +45,11 @@ if [[ "$XHARNESS_COMMAND" == "test" ]]; then fi if [[ -z "$JS_ENGINE_ARGS" ]]; then - JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000" + if [[ "$SCENARIO" == "WasmTestOnNodeJS" || "$SCENARIO" == "wasmtestonnodejs" ]]; then + JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000" + else + JS_ENGINE_ARGS="--engine-arg=--stack-trace-limit=1000 --engine-arg=--experimental-wasm-bigint" + fi fi fi diff --git a/eng/testing/tests.browser.targets b/eng/testing/tests.browser.targets index 77c7021..fac79d3 100644 --- a/eng/testing/tests.browser.targets +++ b/eng/testing/tests.browser.targets @@ -196,7 +196,7 @@ - -Oz -Wl,-O0 -Wl,-lto-O0 + -Oz -Wl,-O0 -Wl,--lto-O0 diff --git a/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs b/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs index e622c7d..2eaa67a 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/GetSetTimes.cs @@ -138,6 +138,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/83197", TestPlatforms.Browser)] public void SetLastWriteTimeTicks() { string firstFile = GetTestFilePath(); @@ -184,6 +185,7 @@ namespace System.IO.Tests } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/83197", TestPlatforms.Browser)] public void SetLastAccessTimeTicks() { string firstFile = GetTestFilePath(); diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs index 4e06fb0..8877936 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedFile.CreateFromFile.Tests.cs @@ -737,6 +737,7 @@ namespace System.IO.MemoryMappedFiles.Tests [Theory] [InlineData(true)] [InlineData(false)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/83197", TestPlatforms.Browser)] public void LeaveOpenRespected_OutstandingViews(bool leaveOpen) { const int Capacity = 4096; diff --git a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewAccessor.Tests.cs b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewAccessor.Tests.cs index 8fe3539..6747758 100644 --- a/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewAccessor.Tests.cs +++ b/src/libraries/System.IO.MemoryMappedFiles/tests/MemoryMappedViewAccessor.Tests.cs @@ -475,6 +475,7 @@ namespace System.IO.MemoryMappedFiles.Tests /// Test to verify that we can still use a view after the associated map has been disposed. /// [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/83197", TestPlatforms.Browser)] public void UseAfterMMFDisposal() { foreach (MemoryMappedFile mmf in CreateSampleMaps(8192)) diff --git a/src/mono/CMakeLists.txt b/src/mono/CMakeLists.txt index 5df4453..7b57776 100644 --- a/src/mono/CMakeLists.txt +++ b/src/mono/CMakeLists.txt @@ -266,6 +266,7 @@ elseif(CLR_CMAKE_HOST_OS STREQUAL "emscripten") add_definitions(-D_THREAD_SAFE) add_compile_options(-Wno-strict-prototypes) add_compile_options(-Wno-unused-but-set-variable) + add_compile_options(-Wno-single-bit-bitfield-constant-conversion) set(DISABLE_EXECUTABLES 1) # FIXME: Is there a cmake option for this ? set(DISABLE_SHARED_LIBS 1) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 5a56949..695064c 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -153,6 +153,7 @@ $(EMSDK_PATH)/emsdk$(EmsdkExt) activate $(EmscriptenVersion) powershell -NonInteractive -command "& $(InstallCmd); Exit $LastExitCode " powershell -NonInteractive -command "& $(ActivateCmd); Exit $LastExitCode " + setlocal EnableDelayedExpansion && call "$([MSBuild]::NormalizePath('$(EMSDK_PATH)', 'emsdk_env.bat'))" && !EMSDK_PYTHON! @@ -162,6 +163,10 @@ + diff --git a/src/mono/mono/utils/mono-threads.c b/src/mono/mono/utils/mono-threads.c index 2ef2fe4..026c290 100644 --- a/src/mono/mono/utils/mono-threads.c +++ b/src/mono/mono/utils/mono-threads.c @@ -511,7 +511,11 @@ register_thread (MonoThreadInfo *info) mono_native_tls_set_value (thread_info_key, info); mono_thread_info_get_stack_bounds (&staddr, &stsize); + + /* for wasm, the stack can be placed at the start of the linear memory */ +#ifndef TARGET_WASM g_assert (staddr); +#endif g_assert (stsize); info->stack_start_limit = staddr; info->stack_end = staddr + stsize; diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index 63e2cae..2f7501e 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -88,6 +88,7 @@ public class BuildPublishTests : BuildTestBase [InlineData("Release", /*build*/true, /*publish*/false)] [InlineData("Release", /*build*/false, /*publish*/true)] [InlineData("Release", /*build*/true, /*publish*/true)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/82725")] public async Task WithDllImportInMainAssembly(string config, bool build, bool publish) { // Based on https://github.com/dotnet/runtime/issues/59255 diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/NativeRefTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/NativeRefTests.cs index c9b34d0..74e6f9f 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/NativeRefTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/NativeRefTests.cs @@ -20,6 +20,7 @@ public class NativeRefTests : BuildTestBase [Theory] [InlineData("Debug")] [InlineData("Release")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/82725")] public void WithNativeReference_AOTInProjectFile(string config) { string id = $"blz_nativeref_aot_{config}_{Path.GetRandomFileName()}"; @@ -41,6 +42,7 @@ public class NativeRefTests : BuildTestBase [Theory] [InlineData("Debug")] [InlineData("Release")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/82725")] public void WithNativeReference_AOTOnCommandLine(string config) { string id = $"blz_nativeref_aot_{config}_{Path.GetRandomFileName()}"; diff --git a/src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs b/src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs index fd3ccf5..268b327 100644 --- a/src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/NativeLibraryTests.cs @@ -51,6 +51,7 @@ namespace Wasm.Build.Tests [Theory] [BuildAndRun(aot: false)] [BuildAndRun(aot: true)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/82725")] public void ProjectUsingSkiaSharp(BuildArgs buildArgs, RunHost host, string id) { string projectName = $"AppUsingSkiaSharp"; diff --git a/src/mono/wasm/build/WasmApp.Native.targets b/src/mono/wasm/build/WasmApp.Native.targets index a89540b..d0837e1 100644 --- a/src/mono/wasm/build/WasmApp.Native.targets +++ b/src/mono/wasm/build/WasmApp.Native.targets @@ -187,6 +187,7 @@ <_EmccLinkRsp>$(_WasmIntermediateOutputPath)emcc-link.rsp $(EmccTotalMemory) + 5MB false @@ -322,10 +323,12 @@ + + - + @@ -419,6 +422,8 @@ <_EmccLDSFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" /> + <_EmccLDSFlags Include="-s STACK_SIZE=$(EmccStackSize)" /> + <_EmccLDSFlags Include="-s WASM_BIGINT=1" /> <_WasmNativeFileForLinking Include="%(_BitcodeFile.ObjectFile)" /> <_WasmNativeFileForLinking Include="%(_WasmSourceFileToCompile.ObjectFile)" /> diff --git a/src/mono/wasm/build/WasmApp.targets b/src/mono/wasm/build/WasmApp.targets index 6cf8f68..df0858f 100644 --- a/src/mono/wasm/build/WasmApp.targets +++ b/src/mono/wasm/build/WasmApp.targets @@ -50,8 +50,10 @@ - $(EmccExtraLDFlags) - Extra emcc flags for linking - $(EmccExtraCFlags) - Extra emcc flags for compiling native files - $(EmccInitialHeapSize) - Initial heap size specified with `emcc`. Default value: 16777216 or size of the DLLs, whichever is larger. - Corresponds to `INITIAL_MEMORY` arg for emcc. + Corresponds to `-s INITIAL_MEMORY=...` emcc arg. (previously named EmccTotalMemory, which is still kept as an alias) + - $(EmccStackSize) - Stack size. Default value: 5MB. + Corresponds to `-s STACK_SIZE=...` emcc arg. - $(WasmBuildAppAfterThisTarget) - This target is used as `AfterTargets` for `WasmBuildApp. this is what triggers the wasm app building. Defaults to `Build`. diff --git a/src/mono/wasm/emscripten-version.txt b/src/mono/wasm/emscripten-version.txt index ffbbb67..f4e47c2 100644 --- a/src/mono/wasm/emscripten-version.txt +++ b/src/mono/wasm/emscripten-version.txt @@ -1 +1 @@ -3.1.12 \ No newline at end of file +3.1.30 \ No newline at end of file diff --git a/src/mono/wasm/runtime/assets.ts b/src/mono/wasm/runtime/assets.ts index cd89212..d3ae945 100644 --- a/src/mono/wasm/runtime/assets.ts +++ b/src/mono/wasm/runtime/assets.ts @@ -123,17 +123,17 @@ export async function mono_download_assets(): Promise { // and we are not awating it here Promise.all(promises_of_asset_instantiation).then(() => { allAssetsInMemory.promise_control.resolve(); - }).catch(err => { - Module.printErr("MONO_WASM: Error in mono_download_assets: " + err); - abort_startup(err, true); + }).catch(e => { + Module.err("MONO_WASM: Error in mono_download_assets: " + e); + abort_startup(e, true); }); // OPTIMIZATION explained: // we do it this way so that we could allocate memory immediately after asset is downloaded (and after onRuntimeInitialized which happened already) // spreading in time // rather than to block all downloads after onRuntimeInitialized or block onRuntimeInitialized after all downloads are done. That would create allocation burst. - } catch (err: any) { - Module.printErr("MONO_WASM: Error in mono_download_assets: " + err); - throw err; + } catch (e: any) { + Module.err("MONO_WASM: Error in mono_download_assets: " + e); + throw e; } } @@ -282,7 +282,7 @@ async function start_asset_download_sources(asset: AssetEntryInternal): Promise< err.status = response.status; throw err; } else { - Module.print(`MONO_WASM: optional download '${response.url}' for ${asset.name} failed ${response.status} ${response.statusText}`); + Module.out(`MONO_WASM: optional download '${response.url}' for ${asset.name} failed ${response.status} ${response.statusText}`); return undefined; } } @@ -426,7 +426,7 @@ function _instantiate_asset(asset: AssetEntry, url: string, bytes: Uint8Array) { } else if (asset.behavior === "icu") { if (!mono_wasm_load_icu_data(offset!)) - Module.printErr(`MONO_WASM: Error loading ICU asset ${asset.name}`); + Module.err(`MONO_WASM: Error loading ICU asset ${asset.name}`); } else if (asset.behavior === "resource") { cwraps.mono_wasm_add_satellite_assembly(virtualName, asset.culture || "", offset!, bytes.length); diff --git a/src/mono/wasm/runtime/dotnet.d.ts b/src/mono/wasm/runtime/dotnet.d.ts index 7afa4bc..4e3b461 100644 --- a/src/mono/wasm/runtime/dotnet.d.ts +++ b/src/mono/wasm/runtime/dotnet.d.ts @@ -45,8 +45,8 @@ declare interface EmscriptenModule { HEAPF64: Float64Array; _malloc(size: number): VoidPtr; _free(ptr: VoidPtr): void; - print(message: string): void; - printErr(message: string): void; + out(message: string): void; + err(message: string): void; ccall(ident: string, returnType?: string | null, argTypes?: string[], args?: any[], opts?: any): T; cwrap(ident: string, returnType: string, argTypes?: string[], opts?: any): T; cwrap(ident: string, ...args: any[]): T; diff --git a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js index 04bc104..4e446e8 100644 --- a/src/mono/wasm/runtime/es6/dotnet.es6.lib.js +++ b/src/mono/wasm/runtime/es6/dotnet.es6.lib.js @@ -32,7 +32,7 @@ __dotnet_replacement_PThread.loadWasmModuleToWorker = PThread.loadWasmModuleToWo __dotnet_replacement_PThread.threadInitTLS = PThread.threadInitTLS; __dotnet_replacement_PThread.allocateUnusedWorker = PThread.allocateUnusedWorker; ` : ''} -let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateGlobalBufferAndViews, pthreadReplacements: __dotnet_replacement_PThread}; +let __dotnet_replacements = {scriptUrl: import.meta.url, fetch: globalThis.fetch, require, updateMemoryViews, pthreadReplacements: __dotnet_replacement_PThread}; if (ENVIRONMENT_IS_NODE) { __dotnet_replacements.requirePromise = __requirePromise; } @@ -40,7 +40,7 @@ let __dotnet_exportedAPI = __initializeImportsAndExports( { isGlobal:false, isNode:ENVIRONMENT_IS_NODE, isWorker:ENVIRONMENT_IS_WORKER, isShell:ENVIRONMENT_IS_SHELL, isWeb:ENVIRONMENT_IS_WEB, isPThread:${isPThread}, quit_, ExitStatus, requirePromise:__dotnet_replacements.requirePromise }, { mono:MONO, binding:BINDING, internal:INTERNAL, module:Module, marshaled_imports: IMPORTS }, __dotnet_replacements, __callbackAPI); -updateGlobalBufferAndViews = __dotnet_replacements.updateGlobalBufferAndViews; +updateMemoryViews = __dotnet_replacements.updateMemoryViews; fetch = __dotnet_replacements.fetch; _scriptDir = __dirname = scriptDirectory = __dotnet_replacements.scriptDirectory; if (ENVIRONMENT_IS_NODE) { @@ -97,6 +97,8 @@ let linked_functions = [ "mono_wasm_invoke_import", "mono_wasm_bind_cs_function", "mono_wasm_marshal_promise", + + "icudt68_dat", ]; if (monoWasmThreads) { diff --git a/src/mono/wasm/runtime/exports-internal.ts b/src/mono/wasm/runtime/exports-internal.ts index 519d091..fdd68c0 100644 --- a/src/mono/wasm/runtime/exports-internal.ts +++ b/src/mono/wasm/runtime/exports-internal.ts @@ -18,7 +18,7 @@ import { mono_wasm_gc_lock, mono_wasm_gc_unlock } from "./gc-lock"; export function export_internal(): any { return { // tests - mono_wasm_exit: (exit_code: number) => { Module.printErr("MONO_WASM: early exit " + exit_code); }, + mono_wasm_exit: (exit_code: number) => { Module.err("MONO_WASM: early exit " + exit_code); }, mono_wasm_enable_on_demand_gc: cwraps.mono_wasm_enable_on_demand_gc, mono_wasm_profiler_init_aot: cwraps.mono_wasm_profiler_init_aot, mono_wasm_profiler_init_browser: cwraps.mono_wasm_profiler_init_browser, diff --git a/src/mono/wasm/runtime/exports.ts b/src/mono/wasm/runtime/exports.ts index 3c08426..e185a3a 100644 --- a/src/mono/wasm/runtime/exports.ts +++ b/src/mono/wasm/runtime/exports.ts @@ -80,11 +80,11 @@ function initializeImportsAndExports( module.configSrc = "./mono-config.json"; } - if (!module.print) { - module.print = console.log.bind(console); + if (!module.out) { + module.out = console.log.bind(console); } - if (!module.printErr) { - module.printErr = console.error.bind(console); + if (!module.err) { + module.err = console.error.bind(console); } if (typeof module.disableDotnet6Compatibility === "undefined") { diff --git a/src/mono/wasm/runtime/http.ts b/src/mono/wasm/runtime/http.ts index 5b07dac..62a1f4b 100644 --- a/src/mono/wasm/runtime/http.ts +++ b/src/mono/wasm/runtime/http.ts @@ -25,7 +25,7 @@ export function http_wasm_abort_response(res: ResponseExtension): void { if (res.__reader) { res.__reader.cancel().catch((err) => { if (err && err.name !== "AbortError") { - Module.printErr("MONO_WASM: Error in http_wasm_abort_response: " + err); + Module.err("MONO_WASM: Error in http_wasm_abort_response: " + err); } // otherwise, it's expected }); diff --git a/src/mono/wasm/runtime/icu.ts b/src/mono/wasm/runtime/icu.ts index 69c7cbc..f362ec8 100644 --- a/src/mono/wasm/runtime/icu.ts +++ b/src/mono/wasm/runtime/icu.ts @@ -40,7 +40,7 @@ export function mono_wasm_globalization_init(): void { invariantMode = true; } else { const msg = "invariant globalization mode is inactive and no ICU data archives were loaded"; - Module.printErr(`MONO_WASM: ERROR: ${msg}`); + Module.err(`MONO_WASM: ERROR: ${msg}`); throw new Error(msg); } } diff --git a/src/mono/wasm/runtime/invoke-cs.ts b/src/mono/wasm/runtime/invoke-cs.ts index 5d419ce..2b10b20 100644 --- a/src/mono/wasm/runtime/invoke-cs.ts +++ b/src/mono/wasm/runtime/invoke-cs.ts @@ -91,7 +91,7 @@ export function mono_wasm_bind_cs_function(fully_qualified_name: MonoStringRef, wrap_no_error_root(is_exception, resultRoot); } catch (ex: any) { - Module.printErr(ex.toString()); + Module.err(ex.toString()); wrap_error_root(is_exception, ex, resultRoot); } finally { resultRoot.release(); diff --git a/src/mono/wasm/runtime/invoke-js.ts b/src/mono/wasm/runtime/invoke-js.ts index 85c1db5..3fd1b66 100644 --- a/src/mono/wasm/runtime/invoke-js.ts +++ b/src/mono/wasm/runtime/invoke-js.ts @@ -90,7 +90,7 @@ export function mono_wasm_bind_js_function(function_name: MonoStringRef, module_ endMeasure(mark, MeasuredBlock.bindJsFunction, js_function_name); } catch (ex: any) { setI32_unchecked(function_js_handle, 0); - Module.printErr(ex.toString()); + Module.err(ex.toString()); wrap_error_root(is_exception, ex, resultRoot); } finally { resultRoot.release(); diff --git a/src/mono/wasm/runtime/memory.ts b/src/mono/wasm/runtime/memory.ts index a5efafe..2a5cf95 100644 --- a/src/mono/wasm/runtime/memory.ts +++ b/src/mono/wasm/runtime/memory.ts @@ -10,7 +10,6 @@ import cwraps, { I52Error } from "./cwraps"; const alloca_stack: Array = []; const alloca_buffer_size = 32 * 1024; let alloca_base: VoidPtr, alloca_offset: VoidPtr, alloca_limit: VoidPtr; -let HEAPI64: BigInt64Array = null; function _ensure_allocated(): void { if (alloca_base) @@ -20,7 +19,8 @@ function _ensure_allocated(): void { alloca_limit = (alloca_base + alloca_buffer_size); } -const is_bigint_supported = typeof BigInt !== "undefined" && typeof BigInt64Array !== "undefined"; +const max_int64_big = BigInt("9223372036854775807"); +const min_int64_big = BigInt("-9223372036854775808"); export function temp_malloc(size: number): VoidPtr { _ensure_allocated(); @@ -135,11 +135,10 @@ export function setU52(offset: MemOffset, value: number): void { } export function setI64Big(offset: MemOffset, value: bigint): void { - mono_assert(is_bigint_supported, "BigInt is not supported."); mono_assert(typeof value === "bigint", () => `Value is not an bigint: ${value} (${typeof (value)})`); mono_assert(value >= min_int64_big && value <= max_int64_big, () => `Overflow: value ${value} is out of ${min_int64_big} ${max_int64_big} range`); - HEAPI64[offset >>> 3] = value; + Module.HEAP64[offset >>> 3] = value; } export function setF32(offset: MemOffset, value: number): void { @@ -218,8 +217,7 @@ export function getU52(offset: MemOffset): number { } export function getI64Big(offset: MemOffset): bigint { - mono_assert(is_bigint_supported, "BigInt is not supported."); - return HEAPI64[offset >>> 3]; + return Module.HEAP64[offset >>> 3]; } export function getF32(offset: MemOffset): number { @@ -230,16 +228,6 @@ export function getF64(offset: MemOffset): number { return Module.HEAPF64[offset >>> 3]; } -let max_int64_big: BigInt; -let min_int64_big: BigInt; -export function afterUpdateGlobalBufferAndViews(buffer: ArrayBufferLike): void { - if (is_bigint_supported) { - max_int64_big = BigInt("9223372036854775807"); - min_int64_big = BigInt("-9223372036854775808"); - HEAPI64 = new BigInt64Array(buffer); - } -} - /// Allocates a new buffer of the given size on the Emscripten stack and passes a pointer to it to the callback. /// Returns the result of the callback. As usual with stack allocations, the buffer is freed when the callback returns. /// Do not attempt to use the stack pointer after the callback is finished. diff --git a/src/mono/wasm/runtime/polyfills.ts b/src/mono/wasm/runtime/polyfills.ts index 78c305a..78fdd1f 100644 --- a/src/mono/wasm/runtime/polyfills.ts +++ b/src/mono/wasm/runtime/polyfills.ts @@ -4,7 +4,6 @@ import BuildConfiguration from "consts:configuration"; import MonoWasmThreads from "consts:monoWasmThreads"; import { ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, ENVIRONMENT_IS_WEB, ENVIRONMENT_IS_WORKER, INTERNAL, Module, runtimeHelpers } from "./imports"; -import { afterUpdateGlobalBufferAndViews } from "./memory"; import { replaceEmscriptenPThreadLibrary } from "./pthreads/shared/emscripten-replacements"; import { DotnetModuleConfigImports, EarlyReplacements } from "./types"; import { TypedArray } from "./types/emscripten"; @@ -175,10 +174,9 @@ export function init_polyfills(replacements: EarlyReplacements): void { } // memory - const originalUpdateGlobalBufferAndViews = replacements.updateGlobalBufferAndViews; - runtimeHelpers.updateGlobalBufferAndViews = replacements.updateGlobalBufferAndViews = (buffer: ArrayBufferLike) => { - originalUpdateGlobalBufferAndViews(buffer); - afterUpdateGlobalBufferAndViews(buffer); + const originalUpdateMemoryViews = replacements.updateMemoryViews; + runtimeHelpers.updateMemoryViews = replacements.updateMemoryViews = () => { + originalUpdateMemoryViews(); }; } diff --git a/src/mono/wasm/runtime/run.ts b/src/mono/wasm/runtime/run.ts index 2e624bc..7fc3729 100644 --- a/src/mono/wasm/runtime/run.ts +++ b/src/mono/wasm/runtime/run.ts @@ -111,11 +111,11 @@ function set_exit_code_and_quit_now(exit_code: number, reason?: any): void { if (reason && !(reason instanceof runtimeHelpers.ExitStatus)) { if (!runtimeHelpers.config.logExitCode) { if (reason instanceof Error) - Module.printErr(mono_wasm_stringify_as_error_with_stack(reason)); + Module.err(mono_wasm_stringify_as_error_with_stack(reason)); else if (typeof reason == "string") - Module.printErr(reason); + Module.err(reason); else - Module.printErr(JSON.stringify(reason)); + Module.err(JSON.stringify(reason)); } } else { diff --git a/src/mono/wasm/runtime/startup.ts b/src/mono/wasm/runtime/startup.ts index b98911b..482c967 100644 --- a/src/mono/wasm/runtime/startup.ts +++ b/src/mono/wasm/runtime/startup.ts @@ -100,7 +100,7 @@ function instantiateWasm( // this is called so early that even Module exports like addRunDependency don't exist yet if (!Module.configSrc && !Module.config && !userInstantiateWasm) { - Module.print("MONO_WASM: configSrc nor config was specified"); + Module.out("MONO_WASM: configSrc nor config was specified"); } normalizeConfig(); @@ -392,10 +392,10 @@ async function mono_wasm_after_user_runtime_initialized(): Promise { function _print_error(message: string, err: any): void { - Module.printErr(`${message}: ${JSON.stringify(err)}`); + Module.err(`${message}: ${JSON.stringify(err)}`); if (err.stack) { - Module.printErr("MONO_WASM: Stacktrace: \n"); - Module.printErr(err.stack); + Module.err("MONO_WASM: Stacktrace: \n"); + Module.err(err.stack); } } diff --git a/src/mono/wasm/runtime/types.ts b/src/mono/wasm/runtime/types.ts index 718cb95..19a13ea 100644 --- a/src/mono/wasm/runtime/types.ts +++ b/src/mono/wasm/runtime/types.ts @@ -230,7 +230,7 @@ export type RuntimeHelpers = { loadedFiles: string[], preferredIcuAsset: string | null, timezone: string | null, - updateGlobalBufferAndViews: (buffer: ArrayBufferLike) => void + updateMemoryViews: () => void } export type GlobalizationMode = @@ -368,7 +368,7 @@ export type EarlyReplacements = { require: any, requirePromise: Promise, noExitRuntime: boolean, - updateGlobalBufferAndViews: Function, + updateMemoryViews: Function, pthreadReplacements: PThreadReplacements | undefined | null scriptDirectory: string; scriptUrl: string diff --git a/src/mono/wasm/runtime/types/emscripten.ts b/src/mono/wasm/runtime/types/emscripten.ts index 81b89a1..0c3fca99 100644 --- a/src/mono/wasm/runtime/types/emscripten.ts +++ b/src/mono/wasm/runtime/types/emscripten.ts @@ -26,6 +26,7 @@ export declare interface EmscriptenModule { HEAP8: Int8Array, HEAP16: Int16Array; HEAP32: Int32Array; + HEAP64: BigInt64Array; HEAPU8: Uint8Array; HEAPU16: Uint16Array; HEAPU32: Uint32Array; @@ -37,8 +38,8 @@ export declare interface EmscriptenModule { _free(ptr: VoidPtr): void; // this should match emcc -s EXPORTED_RUNTIME_METHODS - print(message: string): void; - printErr(message: string): void; + out(message: string): void; + err(message: string): void; ccall(ident: string, returnType?: string | null, argTypes?: string[], args?: any[], opts?: any): T; cwrap(ident: string, returnType: string, argTypes?: string[], opts?: any): T; cwrap(ident: string, ...args: any[]): T; diff --git a/src/mono/wasm/wasm.proj b/src/mono/wasm/wasm.proj index ded4d1a..76cab4d 100644 --- a/src/mono/wasm/wasm.proj +++ b/src/mono/wasm/wasm.proj @@ -33,7 +33,6 @@ <_EmccDefaultsRspPath>$(NativeBinDir)src\emcc-default.rsp <_EmccCompileRspPath>$(NativeBinDir)src\emcc-compile.rsp <_EmccLinkRspPath>$(NativeBinDir)src\emcc-link.rsp - <_EmccLinkUndefinedSymbolsFile>$(WasmObjDir)src\symbols.undefined false $(EMSDK_PATH)\upstream\bin\llvm-ar $(EmSdkLLVMAr).exe @@ -186,7 +185,8 @@ - + + @@ -275,9 +275,11 @@ <_EmccExportedRuntimeMethods>"[@(EmccExportedRuntimeMethod -> '%27%(Identity)%27', ',')]" <_EmccExportedFunctions>@(EmccExportedFunction -> '%(Identity)',',') 16777216 + 5MB <_EmccLinkFlags Include="-s INITIAL_MEMORY=$(EmccInitialHeapSize)" /> + <_EmccLinkFlags Include="-s STACK_SIZE=$(EmccStackSize)" /> <_EmccCommonFlags Condition="'$(WasmEnableSIMD)' == 'true'" Include="-msimd128" /> <_EmccCommonFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-s USE_PTHREADS=1" /> <_EmccLinkFlags Condition="'$(MonoWasmThreads)' == 'true'" Include="-Wno-pthreads-mem-growth" /> @@ -292,6 +294,7 @@ <_EmccLinkFlags Include="-s EXPORTED_FUNCTIONS=$(_EmccExportedFunctions)" /> <_EmccLinkFlags Include="--source-map-base http://example.com" /> <_EmccLinkFlags Include="-s STRICT_JS=1" /> + <_EmccLinkFlags Include="-s WASM_BIGINT=1" /> <_EmccLinkFlags Include="-s EXPORT_NAME="'createDotnetRuntime'"" /> <_EmccLinkFlags Include="-s MODULARIZE=1"/> @@ -299,8 +302,6 @@ <_EmccLinkFlags Include="-Wno-limited-postlink-optimizations"/> - - <_EmccLinkUndefinedSymbols Include="icudt68_dat" /> @@ -355,10 +356,6 @@ Lines="@(_EmccLinkFlags)" WriteOnlyWhenDifferent="true" Overwrite="true" /> - @@ -382,7 +379,6 @@ -O2 $(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1 - $(CMakeConfigurationLinkFlags) -Wl,--allow-undefined-file=$(_EmccLinkUndefinedSymbolsFile) $(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth $(CMakeConfigurationLinkFlags) --emit-symbol-map diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index f72e04b..12ba766 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -156,6 +156,10 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) add_compile_options(-Wno-typedef-redefinition) add_compile_options(-Wno-c11-extensions) add_compile_options(-Wno-thread-safety-analysis) + if (CLR_CMAKE_TARGET_BROWSER) + add_compile_options(-Wno-unsafe-buffer-usage) + add_compile_options(-Wno-cast-function-type-strict) + endif () endif () add_subdirectory(System.Native) -- 2.7.4