From 7128a1609931c344dbac16bf4f38a769548cb0a9 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 7 Oct 2025 16:31:19 +0200 Subject: [PATCH 1/4] try --- src/mono/browser/browser.proj | 26 +++++++++++++++---- src/mono/browser/build/BrowserWasmApp.targets | 2 +- src/mono/browser/runtime/CMakeLists.txt | 6 ++--- src/mono/mono/mini/CMakeLists.txt | 2 +- src/mono/wasi/wasi.proj | 10 +++++-- src/mono/wasm/build/WasmApp.Common.targets | 10 +++---- 6 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index 2088d661ad7943..4b27c2c98aee3c 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -228,8 +228,24 @@ <_EmccLinkFlags Include="-Wno-limited-postlink-optimizations"/> + + + + + + + + + + + + + + + + - + <_EmccLinkFlags Include="-s TEXTDECODER=0"/> @@ -307,13 +323,13 @@ -g -Os -DDEBUG=1 -Oz + $(CMakeConfigurationEmccFlags) -msimd128 -mbulk-memory - $(CMakeConfigurationEmccFlags) -s ASSERTIONS=1 - -O2 + $(CMakeConfigurationEmccFlags) --all-features -s ASSERTIONS=1 + -O2 --all-features $(CMakeConfigurationLinkFlags) -s EXPORT_ES6=1 -lexports.js - $(CMakeConfigurationLinkFlags) -msimd128 $(CMakeConfigurationLinkFlags) -Wno-pthreads-mem-growth $(CMakeConfigurationLinkFlags) --emit-symbol-map @@ -328,7 +344,7 @@ $(CMakeBuildRuntimeConfigureCmd) -DMONO_OBJ_INCLUDES="$(MonoObjDir.TrimEnd('\/').Replace('\','/'))" $(CMakeBuildRuntimeConfigureCmd) -DMONO_ARTIFACTS_DIR="$(MonoArtifactsPath.TrimEnd('\/').Replace('\','/'))" $(CMakeBuildRuntimeConfigureCmd) -DNATIVE_BIN_DIR="$(NativeBinDir.TrimEnd('\/').Replace('\','/'))" - $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_COMPILE_OPTIONS="-msimd128" -DCONFIGURATION_INTERPSIMDTABLES_LIB="simd" + $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_COMPILE_OPTION1="-msimd128" -DCONFIGURATION_COMPILE_OPTION2="-mbulk-memory" -DCONFIGURATION_INTERPSIMDTABLES_LIB="simd" $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_INTERPSIMDTABLES_LIB="nosimd" $(CMakeBuildRuntimeConfigureCmd) -DDISABLE_THREADS=0 $(CMakeBuildRuntimeConfigureCmd) -DENABLE_JS_INTEROP_BY_VALUE=1 diff --git a/src/mono/browser/build/BrowserWasmApp.targets b/src/mono/browser/build/BrowserWasmApp.targets index b42a869f811f57..f056be6c5912fb 100644 --- a/src/mono/browser/build/BrowserWasmApp.targets +++ b/src/mono/browser/build/BrowserWasmApp.targets @@ -56,7 +56,7 @@ <_WasmDefaultFlags Condition="'$(WasmEnableExceptionHandling)' == 'false'">-fexceptions <_WasmDefaultFlags Condition="'$(WasmEnableExceptionHandling)' != 'false'">-fwasm-exceptions - <_WasmDefaultFlags Condition="'$(WasmEnableSIMD)' == 'true'">-msimd128 + <_WasmDefaultFlags Condition="'$(WasmEnableSIMD)' == 'true'">-msimd128 -mbulk-memory <_WasmOutputFileName Condition="'$(WasmSingleFileBundle)' != 'true'">dotnet.native.wasm diff --git a/src/mono/browser/runtime/CMakeLists.txt b/src/mono/browser/runtime/CMakeLists.txt index 1fd1db756049e3..09dbe43eab746a 100644 --- a/src/mono/browser/runtime/CMakeLists.txt +++ b/src/mono/browser/runtime/CMakeLists.txt @@ -9,7 +9,7 @@ set(CMAKE_EXECUTABLE_SUFFIX ".js") add_executable(dotnet.native runtime.c corebindings.c driver.c pinvoke.c) target_include_directories(dotnet.native PUBLIC ${MONO_INCLUDES} ${MONO_OBJ_INCLUDES} ${CMAKE_CURRENT_BINARY_DIR}/include/wasm) -target_compile_options(dotnet.native PUBLIC @${NATIVE_BIN_DIR}/src/emcc-default.rsp @${NATIVE_BIN_DIR}/src/emcc-compile.rsp -DGEN_PINVOKE=1 ${CONFIGURATION_COMPILE_OPTIONS}) +target_compile_options(dotnet.native PUBLIC @${NATIVE_BIN_DIR}/src/emcc-default.rsp @${NATIVE_BIN_DIR}/src/emcc-compile.rsp -DGEN_PINVOKE=1 ${CONFIGURATION_COMPILE_OPTION1} ${CONFIGURATION_COMPILE_OPTION2}) set_target_properties(dotnet.native PROPERTIES COMPILE_FLAGS ${CONFIGURATION_EMCC_FLAGS}) @@ -39,12 +39,12 @@ set_target_properties(dotnet.native PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${NATIVE_BIN_DIR}") set(ignoreMeWasmOptFlags "${CONFIGURATION_WASM_OPT_FLAGS}") -set(ignoreMeWasmOptAdditionalFlags "${CONFIGURATION_COMPILE_OPTIONS}") +set(ignoreMeWasmOptAdditionalFlags "${CONFIGURATION_COMPILE_OPTION1}" "${CONFIGURATION_COMPILE_OPTION2}") set(ignoreMeEmsdkPath "${EMSDK_PATH}") if(CMAKE_BUILD_TYPE STREQUAL "Release") add_custom_command(TARGET dotnet.native - POST_BUILD COMMAND ${EMSDK_PATH}/bin/wasm-opt --enable-exception-handling --enable-simd --enable-bulk-memory ${CONFIGURATION_WASM_OPT_FLAGS} --strip-dwarf ${NATIVE_BIN_DIR}/dotnet.native.wasm -o ${NATIVE_BIN_DIR}/dotnet.native.wasm + POST_BUILD COMMAND ${EMSDK_PATH}/bin/wasm-opt ${CONFIGURATION_WASM_OPT_FLAGS} --strip-dwarf ${NATIVE_BIN_DIR}/dotnet.native.wasm -o ${NATIVE_BIN_DIR}/dotnet.native.wasm COMMENT "Stripping debug symbols from dotnet.native.wasm using wasm-opt") endif() diff --git a/src/mono/mono/mini/CMakeLists.txt b/src/mono/mono/mini/CMakeLists.txt index 23b8d15bf708f1..9803dfd8ac32b9 100644 --- a/src/mono/mono/mini/CMakeLists.txt +++ b/src/mono/mono/mini/CMakeLists.txt @@ -484,7 +484,7 @@ endif() if(HOST_BROWSER OR HOST_WASI) add_library(mono-wasm-simd STATIC interp/interp-simd.c) target_link_libraries (mono-wasm-simd PRIVATE monoapi eglib_api) - set_target_properties(mono-wasm-simd PROPERTIES COMPILE_FLAGS "-msimd128") + set_target_properties(mono-wasm-simd PROPERTIES COMPILE_FLAGS "-msimd128 -mbulk-memory") install(TARGETS mono-wasm-simd LIBRARY) endif() diff --git a/src/mono/wasi/wasi.proj b/src/mono/wasi/wasi.proj index 266af5227107c6..b0692bb64d027f 100644 --- a/src/mono/wasi/wasi.proj +++ b/src/mono/wasi/wasi.proj @@ -59,8 +59,14 @@ + + + + + + - + @@ -156,7 +162,7 @@ $(CMakeBuildRuntimeConfigureCmd) -DMONO_OBJ_INCLUDES="$(MonoObjDir.TrimEnd('\/'))" $(CMakeBuildRuntimeConfigureCmd) -DMONO_ARTIFACTS_DIR="$(MonoArtifactsPath.TrimEnd('\/'))" $(CMakeBuildRuntimeConfigureCmd) -DNATIVE_BIN_DIR="$(NativeBinDir.TrimEnd('\/'))" - $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_COMPILE_OPTIONS="-msimd128" -DCONFIGURATION_INTERPSIMDTABLES_LIB="simd" + $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_COMPILE_OPTIONS="-msimd128 -mbulk-memory" -DCONFIGURATION_INTERPSIMDTABLES_LIB="simd" $(CMakeBuildRuntimeConfigureCmd) -DCONFIGURATION_INTERPSIMDTABLES_LIB="nosimd" $(CMakeBuildRuntimeConfigureCmd) -DDISABLE_THREADS=0 call "$(RepositoryEngineeringDir)native\init-vs-env.cmd" wasm && $(CMakeBuildRuntimeConfigureCmd) diff --git a/src/mono/wasm/build/WasmApp.Common.targets b/src/mono/wasm/build/WasmApp.Common.targets index d9bf8e3b931dae..264c4559c3ea42 100644 --- a/src/mono/wasm/build/WasmApp.Common.targets +++ b/src/mono/wasm/build/WasmApp.Common.targets @@ -462,12 +462,12 @@ + + + - - - @@ -911,8 +911,8 @@ - - + From 67fc22f4729fa6256489c5d243dce602449c6c05 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 7 Oct 2025 18:17:04 +0200 Subject: [PATCH 2/4] more --- src/mono/browser/browser.proj | 45 +++++++++++++++++------------------ 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index 4b27c2c98aee3c..17ff2929996601 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -193,6 +193,27 @@ + + + + + + + + + + + + + + + + + + + + <_EmccLinkFlags Include="-s TEXTDECODER=0"/> + <_EmccExportedLibraryFunction>"[@(EmccExportedLibraryFunction -> '%27%(Identity)%27', ',')]" <_EmccExportedRuntimeMethods>"[@(EmccExportedRuntimeMethod -> '%27%(Identity)%27', ',')]" @@ -209,6 +230,7 @@ <_EmccLinkFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-Wno-pthreads-mem-growth" /> <_EmccLinkFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE=0" /> <_EmccLinkFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE_STRICT=0" /> + <_EmccLinkFlags Condition="'$(WasmEnableSIMD)' == 'true'" Include="-s BINARYEN_EXTRA_PASSES=@(WasmOptConfigurationFlags, ',')" /> <_EmccLinkFlags Include="-s ALLOW_MEMORY_GROWTH=1" /> <_EmccLinkFlags Include="-s ALLOW_TABLE_GROWTH=1" /> @@ -228,29 +250,6 @@ <_EmccLinkFlags Include="-Wno-limited-postlink-optimizations"/> - - - - - - - - - - - - - - - - - - - - - <_EmccLinkFlags Include="-s TEXTDECODER=0"/> - - <_EmccLinkFlags Include="--profiling-funcs" /> <_EmccFlags Include="@(_EmccCommonFlags)" /> From 21219b49ac6c2abb9fdb36060bdd4aeb63bdc226 Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 7 Oct 2025 21:56:17 +0200 Subject: [PATCH 3/4] fix --- src/mono/browser/browser.proj | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index 17ff2929996601..12154979fd3ab2 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -218,6 +218,7 @@ <_EmccExportedLibraryFunction>"[@(EmccExportedLibraryFunction -> '%27%(Identity)%27', ',')]" <_EmccExportedRuntimeMethods>"[@(EmccExportedRuntimeMethod -> '%27%(Identity)%27', ',')]" <_EmccExportedFunctions>@(EmccExportedFunction -> '%(Identity)',',') + <_WasmOptConfigurationFlags>"[@(WasmOptConfigurationFlags -> '%27%(Identity)%27', ',')]" 33554432 5MB @@ -230,7 +231,7 @@ <_EmccLinkFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-Wno-pthreads-mem-growth" /> <_EmccLinkFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE=0" /> <_EmccLinkFlags Condition="'$(WasmEnableThreads)' == 'true'" Include="-s PTHREAD_POOL_SIZE_STRICT=0" /> - <_EmccLinkFlags Condition="'$(WasmEnableSIMD)' == 'true'" Include="-s BINARYEN_EXTRA_PASSES=@(WasmOptConfigurationFlags, ',')" /> + <_EmccLinkFlags Condition="'$(WasmEnableSIMD)' == 'true'" Include="-s BINARYEN_EXTRA_PASSES=$(_WasmOptConfigurationFlags)" /> <_EmccLinkFlags Include="-s ALLOW_MEMORY_GROWTH=1" /> <_EmccLinkFlags Include="-s ALLOW_TABLE_GROWTH=1" /> From 9d4b8f22e431ebd9cb63c4c850364a5528cce1be Mon Sep 17 00:00:00 2001 From: pavelsavara Date: Tue, 7 Oct 2025 22:38:03 +0200 Subject: [PATCH 4/4] fix --- src/mono/browser/browser.proj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/browser/browser.proj b/src/mono/browser/browser.proj index 12154979fd3ab2..15536e7ae22075 100644 --- a/src/mono/browser/browser.proj +++ b/src/mono/browser/browser.proj @@ -218,7 +218,7 @@ <_EmccExportedLibraryFunction>"[@(EmccExportedLibraryFunction -> '%27%(Identity)%27', ',')]" <_EmccExportedRuntimeMethods>"[@(EmccExportedRuntimeMethod -> '%27%(Identity)%27', ',')]" <_EmccExportedFunctions>@(EmccExportedFunction -> '%(Identity)',',') - <_WasmOptConfigurationFlags>"[@(WasmOptConfigurationFlags -> '%27%(Identity)%27', ',')]" + <_WasmOptConfigurationFlags>"@(WasmOptConfigurationFlags -> '%27%(Identity)%27', ',')" 33554432 5MB