Skip to content

Commit

Permalink
check for SIMD and EH support
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelsavara committed Jul 24, 2023
1 parent 4964d54 commit 487f24a
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 17 deletions.
2 changes: 1 addition & 1 deletion eng/testing/performance/performance-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ if [[ -n "$wasm_bundle_directory" ]]; then
wasm_bundle_directory_path=$payload_directory
mv $wasm_bundle_directory/* $wasm_bundle_directory_path
find $wasm_bundle_directory_path -type d
wasm_args="--expose_wasm"
wasm_args="--experimental-wasm-eh --expose_wasm"
if [ "$javascript_engine" == "v8" ]; then
# for es6 module support
wasm_args="$wasm_args --module"
Expand Down
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="v8 --expose_wasm --module $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
</Target>
<Target Name="RunSampleWithNode" DependsOnTargets="BuildSampleInTree;_ComputeMainJSFileName">
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --experimental-wasm-eh --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args)" IgnoreExitCode="true" />
</Target>
<Target Name="DebugSampleWithNode" DependsOnTargets="BuildSampleInTree;_ComputeMainJSFileName">
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args) --inspect=9222" IgnoreExitCode="true" />
<Exec WorkingDirectory="bin/$(Configuration)/AppBundle" Command="node --experimental-wasm-eh --expose_wasm $(_WasmMainJSFileName) -- $(DOTNET_MONO_LOG_LEVEL) --run $(_SampleAssembly) $(Args) --inspect=9222" IgnoreExitCode="true" />
</Target>
<Target Name="CheckServe">
<Exec Command="dotnet tool install -g dotnet-serve" IgnoreExitCode="true" />
Expand Down
4 changes: 2 additions & 2 deletions src/mono/sample/wasm/wasm.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ run-console:
cd bin/$(CONFIG)/AppBundle && $(V8_PATH) --stack-trace-limit=1000 --single-threaded --expose_wasm --module $(MAIN_JS) -- $(ARGS)

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

debug-console-node:
cd bin/$(CONFIG)/AppBundle && node --inspect=9222 --stack-trace-limit=1000 --single-threaded --expose_wasm $(MAIN_JS) $(ARGS)
cd bin/$(CONFIG)/AppBundle && node --inspect=9222 --stack-trace-limit=1000 --single-threaded --experimental-wasm-eh --expose_wasm $(MAIN_JS) $(ARGS)
21 changes: 21 additions & 0 deletions src/mono/wasm/runtime/loader/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

import { exceptions, simd } from "wasm-feature-detect";

import MonoWasmThreads from "consts:monoWasmThreads";
import WasmEnableSIMD from "consts:wasmEnableSIMD";
import WasmEnableExceptionHandling from "consts:wasmEnableExceptionHandling";

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

export async function verifyEnvironmentAsync() {
if (ENVIRONMENT_IS_NODE) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore:
const process = await import(/* webpackIgnore: true */"process");
if (process.versions.node.split(".")[0] < 14) {
throw new Error(`NodeJS at '${process.execPath}' has too low version '${process.versions.node}'`);
}
}
if (WasmEnableSIMD) {
mono_assert(await simd(), "This browser/engine doesn't support WASM SIMD. Please use a modern version.");
}
if (WasmEnableExceptionHandling) {
mono_assert(await exceptions(), "This browser/engine doesn't support WASM exception handling. Please use a modern version.");
}
}

export async function detect_features_and_polyfill(module: DotnetModuleInternal): Promise<void> {

const scriptUrlQuery =/* webpackIgnore: true */import.meta.url;
Expand Down
11 changes: 2 additions & 9 deletions src/mono/wasm/runtime/loader/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { deep_merge_config, deep_merge_module, mono_wasm_load_config } from "./c
import { mono_exit } from "./exit";
import { setup_proxy_console, mono_log_info } from "./logging";
import { resolve_asset_path, start_asset_download } from "./assets";
import { detect_features_and_polyfill } from "./polyfills";
import { detect_features_and_polyfill, verifyEnvironmentAsync } from "./polyfills";
import { runtimeHelpers, loaderHelpers } from "./globals";
import { init_globalization } from "./icu";
import { setupPreloadChannelToMainThread } from "./worker";
Expand Down Expand Up @@ -350,14 +350,7 @@ export class HostBuilder implements DotnetHostBuilder {
if (ENVIRONMENT_IS_WEB && (module.config! as MonoConfigInternal).forwardConsoleLogsToWS && typeof globalThis.WebSocket != "undefined") {
setup_proxy_console("main", globalThis.console, globalThis.location.origin);
}
if (ENVIRONMENT_IS_NODE) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore:
const process = await import(/* webpackIgnore: true */"process");
if (process.versions.node.split(".")[0] < 14) {
throw new Error(`NodeJS at '${process.execPath}' has too low version '${process.versions.node}'`);
}
}
await verifyEnvironmentAsync();
mono_assert(module, "Null moduleConfig");
mono_assert(module.config, "Null moduleConfig.config");
await createEmscripten(module);
Expand Down
52 changes: 52 additions & 0 deletions src/mono/wasm/runtime/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/mono/wasm/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@
"author": "Microsoft",
"license": "MIT",
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.1.0",
"@rollup/plugin-terser": "0.4.3",
"@rollup/plugin-typescript": "11.1.2",
"@rollup/plugin-virtual": "3.0.1",
"@typescript-eslint/eslint-plugin": "5.59.1",
"@typescript-eslint/parser": "5.59.1",
"magic-string": "0.30.1",
"eslint": "8.44.0",
"fast-glob": "3.3.0",
"git-commit-info": "2.0.2",
"magic-string": "0.30.1",
"rollup": "3.26.2",
"rollup-plugin-dts": "5.3.0",
"terser": "5.19.0",
"tslib": "2.6.0",
"typescript": "5.1.6"
},
"dependencies": {
"wasm-feature-detect": "^1.5.1"
}
}
7 changes: 6 additions & 1 deletion src/mono/wasm/runtime/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { defineConfig } from "rollup";
import typescript from "@rollup/plugin-typescript";
import terser from "@rollup/plugin-terser";
import virtual from "@rollup/plugin-virtual";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { readFile, writeFile, mkdir } from "fs/promises";
import * as fs from "fs";
import * as path from "path";
Expand All @@ -18,6 +19,8 @@ const isContinuousIntegrationBuild = process.env.ContinuousIntegrationBuild ===
const productVersion = process.env.ProductVersion || "8.0.0-dev";
const nativeBinDir = process.env.NativeBinDir ? process.env.NativeBinDir.replace(/"/g, "") : "bin";
const monoWasmThreads = process.env.MonoWasmThreads === "true" ? true : false;
const wasmEnableSIMD = process.env.WasmEnableSIMD === "true" ? true : false;
const wasmEnableExceptionHandling = process.env.WasmEnableExceptionHandling === "true" ? true : false;
const wasmEnableLegacyJsInterop = process.env.DISABLE_LEGACY_JS_INTEROP !== "1" ? true : false;
const monoDiagnosticsMock = process.env.MonoDiagnosticsMock === "true" ? true : false;
const terserConfig = {
Expand Down Expand Up @@ -90,6 +93,8 @@ const envConstants = {
productVersion,
configuration,
monoWasmThreads,
wasmEnableSIMD,
wasmEnableExceptionHandling,
monoDiagnosticsMock,
gitHash,
wasmEnableLegacyJsInterop,
Expand Down Expand Up @@ -154,7 +159,7 @@ const loaderConfig = {
}
],
external: externalDependencies,
plugins: [regexReplace(inlineAssert), regexCheck([checkAssert, checkNoRuntime]), ...outputCodePlugins],
plugins: [nodeResolve(), regexReplace(inlineAssert), regexCheck([checkAssert, checkNoRuntime]), ...outputCodePlugins],
onwarn: onwarn
};
const runtimeConfig = {
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasm/wasm.proj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<ICULibDir Condition="'$(MonoWasmThreads)' != 'true'">$([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm', 'native', 'lib'))</ICULibDir>
<ICULibDir Condition="'$(MonoWasmThreads)' == 'true'">$([MSBuild]::NormalizeDirectory('$(PkgMicrosoft_NETCore_Runtime_ICU_Transport)', 'runtimes', 'browser-wasm-threads', 'native', 'lib'))</ICULibDir>
<WasmEnableSIMD Condition="'$(WasmEnableSIMD)' == ''">true</WasmEnableSIMD>
<WasmEnableExceptionHandling Condition="'$(WasmEnableExceptionHandling)' == ''">true</WasmEnableExceptionHandling>
<WasmEnableLegacyJsInterop Condition="'$(WasmEnableLegacyJsInterop)' == ''">true</WasmEnableLegacyJsInterop>
<FilterSystemTimeZones Condition="'$(FilterSystemTimeZones)' == ''">false</FilterSystemTimeZones>
<EmccCmd>emcc</EmccCmd>
Expand Down Expand Up @@ -517,7 +518,7 @@

<Target Name="SetMonoRollupEnvironment" DependsOnTargets="GetProductVersions">
<PropertyGroup>
<MonoRollupEnvironment>Configuration:$(Configuration),NativeBinDir:$(NativeBinDir),ProductVersion:$(ProductVersion),MonoWasmThreads:$(MonoWasmThreads),DISABLE_LEGACY_JS_INTEROP:$(_DisableLegacyJsInterop),MonoDiagnosticsMock:$(MonoDiagnosticsMock),ContinuousIntegrationBuild:$(ContinuousIntegrationBuild)</MonoRollupEnvironment>
<MonoRollupEnvironment>Configuration:$(Configuration),NativeBinDir:$(NativeBinDir),ProductVersion:$(ProductVersion),MonoWasmThreads:$(MonoWasmThreads),WasmEnableSIMD:$(WasmEnableSIMD),WasmEnableExceptionHandling:$(WasmEnableExceptionHandling),DISABLE_LEGACY_JS_INTEROP:$(_DisableLegacyJsInterop),MonoDiagnosticsMock:$(MonoDiagnosticsMock),ContinuousIntegrationBuild:$(ContinuousIntegrationBuild)</MonoRollupEnvironment>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 487f24a

Please sign in to comment.