Skip to content

Commit 7cdc7fe

Browse files
authored
[nodejs] Remove experimental wasm arguments from template (#91384)
* 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
1 parent 9316b8a commit 7cdc7fe

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;
@@ -48,18 +50,38 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse
4850
if (runAnalyzers)
4951
extraProperties += "<RunAnalyzers>true</RunAnalyzers>";
5052

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

58-
AddItemsPropertiesToProject(projectfile, extraProperties, extraItems);
58+
AddItemsPropertiesToProject(projectfile, extraProperties);
5959

6060
return projectfile;
6161
}
6262

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