Skip to content

Commit dc652c1

Browse files
github-actions[bot]marafmarek-safar
authored
[release/8.0] [nodejs] Remove experimental wasm arguments from template (#91401)
* Remove experimental wasm arguments from template and add them to features.md * Fix WBT * Use lowercase host in runtimeconfig.template.json * Override runtimeconfig only for wasmconsole --------- Co-authored-by: Marek Fišera <[email protected]> Co-authored-by: Marek Safar <[email protected]>
1 parent ee24056 commit dc652c1

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33

44
#nullable enable
55

6+
using System;
67
using System.IO;
8+
using System.Text.Json.Nodes;
79
using Xunit.Abstractions;
810

911
namespace Wasm.Build.Tests;
@@ -45,18 +47,38 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse
4547
if (runAnalyzers)
4648
extraProperties += "<RunAnalyzers>true</RunAnalyzers>";
4749

48-
// TODO: Can be removed after updated templates propagate in.
49-
string extraItems = string.Empty;
50-
if (template == "wasmbrowser")
51-
extraItems += "<WasmExtraFilesToDeploy Include=\"main.js\" />";
52-
else
53-
extraItems += "<WasmExtraFilesToDeploy Include=\"main.mjs\" />";
50+
if (template == "wasmconsole")
51+
{
52+
UpdateRuntimeconfigTemplateForNode(_projectDir);
53+
}
5454

55-
AddItemsPropertiesToProject(projectfile, extraProperties, extraItems);
55+
AddItemsPropertiesToProject(projectfile, extraProperties);
5656

5757
return projectfile;
5858
}
5959

60+
private static void UpdateRuntimeconfigTemplateForNode(string projectDir)
61+
{
62+
// TODO: Can be removed once Node >= 20
63+
64+
string runtimeconfigTemplatePath = Path.Combine(projectDir, "runtimeconfig.template.json");
65+
string runtimeconfigTemplateContent = File.ReadAllText(runtimeconfigTemplatePath);
66+
var runtimeconfigTemplate = JsonObject.Parse(runtimeconfigTemplateContent);
67+
if (runtimeconfigTemplate == null)
68+
throw new Exception($"Unable to parse runtimeconfigtemplate at '{runtimeconfigTemplatePath}'");
69+
70+
var perHostConfigs = runtimeconfigTemplate?["wasmHostProperties"]?["perHostConfig"]?.AsArray();
71+
if (perHostConfigs == null || perHostConfigs.Count == 0 || perHostConfigs[0] == null)
72+
throw new Exception($"Unable to find perHostConfig in runtimeconfigtemplate at '{runtimeconfigTemplatePath}'");
73+
74+
perHostConfigs[0]!["host-args"] = new JsonArray(
75+
"--experimental-wasm-simd",
76+
"--experimental-wasm-eh"
77+
);
78+
79+
File.WriteAllText(runtimeconfigTemplatePath, runtimeconfigTemplate!.ToString());
80+
}
81+
6082
public (string projectDir, string buildOutput) BuildTemplateProject(BuildArgs buildArgs,
6183
string id,
6284
BuildProjectOptions buildProjectOptions)

src/mono/wasm/features.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,24 @@ A WebAssembly application that works well on desktop PCs browser may take minute
292292
### Shell environments - NodeJS & V8
293293
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.
294294

295+
#### NodeJS < 20
296+
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
297+
298+
```json
299+
"wasmHostProperties": {
300+
"perHostConfig": [
301+
{
302+
"name": "node",
303+
...
304+
"host-args": [
305+
"--experimental-wasm-simd", // 👈 Enable SIMD support
306+
"--experimental-wasm-eh" // 👈 Enable exception handling support
307+
]
308+
}
309+
]
310+
}
311+
```
312+
295313
## Choosing the right platform target
296314
Every end user has different needs, so the right platform for every application may differ.
297315

src/mono/wasm/templates/templates/console/runtimeconfig.template.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44
{
55
"name": "node",
66
"js-path": "main.mjs",
7-
"Host": "nodejs",
8-
"host-args": [
9-
"--experimental-wasm-simd",
10-
"--experimental-wasm-eh"
11-
]
7+
"host": "nodejs"
128
}
139
]
1410
}
15-
}
11+
}

0 commit comments

Comments
 (0)