Skip to content

Commit 487f24a

Browse files
committed
check for SIMD and EH support
1 parent 4964d54 commit 487f24a

File tree

9 files changed

+93
-17
lines changed

9 files changed

+93
-17
lines changed

eng/testing/performance/performance-setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ if [[ -n "$wasm_bundle_directory" ]]; then
403403
wasm_bundle_directory_path=$payload_directory
404404
mv $wasm_bundle_directory/* $wasm_bundle_directory_path
405405
find $wasm_bundle_directory_path -type d
406-
wasm_args="--expose_wasm"
406+
wasm_args="--experimental-wasm-eh --expose_wasm"
407407
if [ "$javascript_engine" == "v8" ]; then
408408
# for es6 module support
409409
wasm_args="$wasm_args --module"

src/mono/sample/wasm/Directory.Build.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="v8 --expose_wasm --module $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
5656
</Target>
5757
<Target Name="RunSampleWithNode" DependsOnTargets="BuildSampleInTree;_ComputeMainJSFileName">
58-
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
58+
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --experimental-wasm-eh --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
5959
</Target>
6060
<Target Name="DebugSampleWithNode" DependsOnTargets="BuildSampleInTree;_ComputeMainJSFileName">
61-
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args) --inspect=9222" IgnoreExitCode="true" />
61+
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --experimental-wasm-eh --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args) --inspect=9222" IgnoreExitCode="true" />
6262
</Target>
6363
<Target Name="CheckServe">
6464
<Exec Command="dotnet tool install -g dotnet-serve" IgnoreExitCode="true" />

src/mono/sample/wasm/wasm.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ run-console:
4545
cd bin/$(CONFIG)/AppBundle && $(V8_PATH) --stack-trace-limit=1000 --single-threaded --expose_wasm --module $(MAIN_JS) -- $(ARGS)
4646

4747
run-console-node:
48-
cd bin/$(CONFIG)/AppBundle && node --stack-trace-limit=1000 --single-threaded --expose_wasm $(MAIN_JS) $(ARGS)
48+
cd bin/$(CONFIG)/AppBundle && node --stack-trace-limit=1000 --single-threaded --experimental-wasm-eh --expose_wasm $(MAIN_JS) $(ARGS)
4949

5050
debug-console-node:
51-
cd bin/$(CONFIG)/AppBundle && node --inspect=9222 --stack-trace-limit=1000 --single-threaded --expose_wasm $(MAIN_JS) $(ARGS)
51+
cd bin/$(CONFIG)/AppBundle && node --inspect=9222 --stack-trace-limit=1000 --single-threaded --experimental-wasm-eh --expose_wasm $(MAIN_JS) $(ARGS)

src/mono/wasm/runtime/loader/polyfills.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4+
import { exceptions, simd } from "wasm-feature-detect";
5+
46
import MonoWasmThreads from "consts:monoWasmThreads";
7+
import WasmEnableSIMD from "consts:wasmEnableSIMD";
8+
import WasmEnableExceptionHandling from "consts:wasmEnableExceptionHandling";
59

610
import type { DotnetModuleInternal } from "../types/internal";
711
import { INTERNAL, ENVIRONMENT_IS_NODE, ENVIRONMENT_IS_SHELL, loaderHelpers, ENVIRONMENT_IS_WEB, mono_assert } from "./globals";
@@ -31,6 +35,23 @@ export function verifyEnvironment() {
3135
// See https://github.com/dotnet/runtime/issues/84574
3236
}
3337

38+
export async function verifyEnvironmentAsync() {
39+
if (ENVIRONMENT_IS_NODE) {
40+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
41+
// @ts-ignore:
42+
const process = await import(/* webpackIgnore: true */"process");
43+
if (process.versions.node.split(".")[0] < 14) {
44+
throw new Error(`NodeJS at '${process.execPath}' has too low version '${process.versions.node}'`);
45+
}
46+
}
47+
if (WasmEnableSIMD) {
48+
mono_assert(await simd(), "This browser/engine doesn't support WASM SIMD. Please use a modern version.");
49+
}
50+
if (WasmEnableExceptionHandling) {
51+
mono_assert(await exceptions(), "This browser/engine doesn't support WASM exception handling. Please use a modern version.");
52+
}
53+
}
54+
3455
export async function detect_features_and_polyfill(module: DotnetModuleInternal): Promise<void> {
3556

3657
const scriptUrlQuery =/* webpackIgnore: true */import.meta.url;

src/mono/wasm/runtime/loader/run.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { deep_merge_config, deep_merge_module, mono_wasm_load_config } from "./c
1111
import { mono_exit } from "./exit";
1212
import { setup_proxy_console, mono_log_info } from "./logging";
1313
import { resolve_asset_path, start_asset_download } from "./assets";
14-
import { detect_features_and_polyfill } from "./polyfills";
14+
import { detect_features_and_polyfill, verifyEnvironmentAsync } from "./polyfills";
1515
import { runtimeHelpers, loaderHelpers } from "./globals";
1616
import { init_globalization } from "./icu";
1717
import { setupPreloadChannelToMainThread } from "./worker";
@@ -350,14 +350,7 @@ export class HostBuilder implements DotnetHostBuilder {
350350
if (ENVIRONMENT_IS_WEB && (module.config! as MonoConfigInternal).forwardConsoleLogsToWS && typeof globalThis.WebSocket != "undefined") {
351351
setup_proxy_console("main", globalThis.console, globalThis.location.origin);
352352
}
353-
if (ENVIRONMENT_IS_NODE) {
354-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
355-
// @ts-ignore:
356-
const process = await import(/* webpackIgnore: true */"process");
357-
if (process.versions.node.split(".")[0] < 14) {
358-
throw new Error(`NodeJS at '${process.execPath}' has too low version '${process.versions.node}'`);
359-
}
360-
}
353+
await verifyEnvironmentAsync();
361354
mono_assert(module, "Null moduleConfig");
362355
mono_assert(module.config, "Null moduleConfig.config");
363356
await createEmscripten(module);

src/mono/wasm/runtime/package-lock.json

Lines changed: 52 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mono/wasm/runtime/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,23 @@
2222
"author": "Microsoft",
2323
"license": "MIT",
2424
"devDependencies": {
25+
"@rollup/plugin-node-resolve": "^15.1.0",
2526
"@rollup/plugin-terser": "0.4.3",
2627
"@rollup/plugin-typescript": "11.1.2",
2728
"@rollup/plugin-virtual": "3.0.1",
2829
"@typescript-eslint/eslint-plugin": "5.59.1",
2930
"@typescript-eslint/parser": "5.59.1",
30-
"magic-string": "0.30.1",
3131
"eslint": "8.44.0",
3232
"fast-glob": "3.3.0",
3333
"git-commit-info": "2.0.2",
34+
"magic-string": "0.30.1",
3435
"rollup": "3.26.2",
3536
"rollup-plugin-dts": "5.3.0",
3637
"terser": "5.19.0",
3738
"tslib": "2.6.0",
3839
"typescript": "5.1.6"
40+
},
41+
"dependencies": {
42+
"wasm-feature-detect": "^1.5.1"
3943
}
4044
}

src/mono/wasm/runtime/rollup.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { defineConfig } from "rollup";
22
import typescript from "@rollup/plugin-typescript";
33
import terser from "@rollup/plugin-terser";
44
import virtual from "@rollup/plugin-virtual";
5+
import { nodeResolve } from "@rollup/plugin-node-resolve";
56
import { readFile, writeFile, mkdir } from "fs/promises";
67
import * as fs from "fs";
78
import * as path from "path";
@@ -18,6 +19,8 @@ const isContinuousIntegrationBuild = process.env.ContinuousIntegrationBuild ===
1819
const productVersion = process.env.ProductVersion || "8.0.0-dev";
1920
const nativeBinDir = process.env.NativeBinDir ? process.env.NativeBinDir.replace(/"/g, "") : "bin";
2021
const monoWasmThreads = process.env.MonoWasmThreads === "true" ? true : false;
22+
const wasmEnableSIMD = process.env.WasmEnableSIMD === "true" ? true : false;
23+
const wasmEnableExceptionHandling = process.env.WasmEnableExceptionHandling === "true" ? true : false;
2124
const wasmEnableLegacyJsInterop = process.env.DISABLE_LEGACY_JS_INTEROP !== "1" ? true : false;
2225
const monoDiagnosticsMock = process.env.MonoDiagnosticsMock === "true" ? true : false;
2326
const terserConfig = {
@@ -90,6 +93,8 @@ const envConstants = {
9093
productVersion,
9194
configuration,
9295
monoWasmThreads,
96+
wasmEnableSIMD,
97+
wasmEnableExceptionHandling,
9398
monoDiagnosticsMock,
9499
gitHash,
95100
wasmEnableLegacyJsInterop,
@@ -154,7 +159,7 @@ const loaderConfig = {
154159
}
155160
],
156161
external: externalDependencies,
157-
plugins: [regexReplace(inlineAssert), regexCheck([checkAssert, checkNoRuntime]), ...outputCodePlugins],
162+
plugins: [nodeResolve(), regexReplace(inlineAssert), regexCheck([checkAssert, checkNoRuntime]), ...outputCodePlugins],
158163
onwarn: onwarn
159164
};
160165
const runtimeConfig = {

src/mono/wasm/wasm.proj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<ICULibDir Condition="'$(MonoWasmThreads)' != 'true'">$([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm', 'native', 'lib'))</ICULibDir>
2626
<ICULibDir Condition="'$(MonoWasmThreads)' == 'true'">$([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm-threads', 'native', 'lib'))</ICULibDir>
2727
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">true</WasmEnableSIMD>
28+
<WasmEnableExceptionHandling Condition="'$(WasmEnableExceptionHandling)' == ''">true</WasmEnableExceptionHandling>
2829
<WasmEnableLegacyJsInterop Condition="'$(WasmEnableLegacyJsInterop)' == ''">true</WasmEnableLegacyJsInterop>
2930
<FilterSystemTimeZones Condition="'$(FilterSystemTimeZones)' == ''">false</FilterSystemTimeZones>
3031
<EmccCmd>emcc</EmccCmd>
@@ -517,7 +518,7 @@
517518

518519
<Target Name="SetMonoRollupEnvironment" DependsOnTargets="GetProductVersions">
519520
<PropertyGroup>
520-
<MonoRollupEnvironment>Configuration:$(Configuration),NativeBinDir:$(NativeBinDir),ProductVersion:$(ProductVersion),MonoWasmThreads:$(MonoWasmThreads),DISABLE_LEGACY_JS_INTEROP:$(_DisableLegacyJsInterop),MonoDiagnosticsMock:$(MonoDiagnosticsMock),ContinuousIntegrationBuild:$(ContinuousIntegrationBuild)</MonoRollupEnvironment>
521+
<MonoRollupEnvironment>Configuration:$(Configuration),NativeBinDir:$(NativeBinDir),ProductVersion:$(ProductVersion),MonoWasmThreads:$(MonoWasmThreads),WasmEnableSIMD:$(WasmEnableSIMD),WasmEnableExceptionHandling:$(WasmEnableExceptionHandling),DISABLE_LEGACY_JS_INTEROP:$(_DisableLegacyJsInterop),MonoDiagnosticsMock:$(MonoDiagnosticsMock),ContinuousIntegrationBuild:$(ContinuousIntegrationBuild)</MonoRollupEnvironment>
521522
</PropertyGroup>
522523

523524
<PropertyGroup>

0 commit comments

Comments
 (0)