diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs index 6280a022c1a424..a7ae3fba70ed30 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs @@ -3,7 +3,9 @@ #nullable enable +using System; using System.IO; +using System.Text.Json.Nodes; using Xunit.Abstractions; namespace Wasm.Build.Tests; @@ -45,18 +47,38 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse if (runAnalyzers) extraProperties += "true"; - // TODO: Can be removed after updated templates propagate in. - string extraItems = string.Empty; - if (template == "wasmbrowser") - extraItems += ""; - else - extraItems += ""; + if (template == "wasmconsole") + { + UpdateRuntimeconfigTemplateForNode(_projectDir); + } - AddItemsPropertiesToProject(projectfile, extraProperties, extraItems); + AddItemsPropertiesToProject(projectfile, extraProperties); return projectfile; } + private static void UpdateRuntimeconfigTemplateForNode(string projectDir) + { + // TODO: Can be removed once Node >= 20 + + string runtimeconfigTemplatePath = Path.Combine(projectDir, "runtimeconfig.template.json"); + string runtimeconfigTemplateContent = File.ReadAllText(runtimeconfigTemplatePath); + var runtimeconfigTemplate = JsonObject.Parse(runtimeconfigTemplateContent); + if (runtimeconfigTemplate == null) + throw new Exception($"Unable to parse runtimeconfigtemplate at '{runtimeconfigTemplatePath}'"); + + var perHostConfigs = runtimeconfigTemplate?["wasmHostProperties"]?["perHostConfig"]?.AsArray(); + if (perHostConfigs == null || perHostConfigs.Count == 0 || perHostConfigs[0] == null) + throw new Exception($"Unable to find perHostConfig in runtimeconfigtemplate at '{runtimeconfigTemplatePath}'"); + + perHostConfigs[0]!["host-args"] = new JsonArray( + "--experimental-wasm-simd", + "--experimental-wasm-eh" + ); + + File.WriteAllText(runtimeconfigTemplatePath, runtimeconfigTemplate!.ToString()); + } + public (string projectDir, string buildOutput) BuildTemplateProject(BuildArgs buildArgs, string id, BuildProjectOptions buildProjectOptions) diff --git a/src/mono/wasm/features.md b/src/mono/wasm/features.md index c131002dde7968..d3d85f2e570a9e 100644 --- a/src/mono/wasm/features.md +++ b/src/mono/wasm/features.md @@ -292,6 +292,24 @@ A WebAssembly application that works well on desktop PCs browser may take minute ### Shell environments - NodeJS & V8 While our primary target is web browsers, we have partial support for Node.JS v14 sufficient to pass most of our automated tests. We also have partial support for the D8 command-line shell, version 11 or higher, sufficient to pass most of our automated tests. Both of these environments may lack support for features that are available in the browser. +#### NodeJS < 20 +Until node version 20, you may need to pass these arguments when running the application `--experimental-wasm-simd --experimental-wasm-eh`. When you run the application using `dotnet run`, you can add these to the runtimeconfig template + +```json +"wasmHostProperties": { + "perHostConfig": [ + { + "name": "node", + ... + "host-args": [ + "--experimental-wasm-simd", // 👈 Enable SIMD support + "--experimental-wasm-eh" // 👈 Enable exception handling support + ] + } + ] +} +``` + ## Choosing the right platform target Every end user has different needs, so the right platform for every application may differ. diff --git a/src/mono/wasm/templates/templates/console/runtimeconfig.template.json b/src/mono/wasm/templates/templates/console/runtimeconfig.template.json index 49721faa0baa4d..a056e67f11cf9a 100644 --- a/src/mono/wasm/templates/templates/console/runtimeconfig.template.json +++ b/src/mono/wasm/templates/templates/console/runtimeconfig.template.json @@ -4,12 +4,8 @@ { "name": "node", "js-path": "main.mjs", - "Host": "nodejs", - "host-args": [ - "--experimental-wasm-simd", - "--experimental-wasm-eh" - ] + "host": "nodejs" } ] } -} +} \ No newline at end of file