Skip to content

[nodejs] Remove experimental wasm arguments from template #91384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#nullable enable

using System;
using System.IO;
using System.Text.Json.Nodes;
using Xunit.Abstractions;

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

// TODO: Can be removed after updated templates propagate in.
string extraItems = string.Empty;
if (template == "wasmbrowser")
extraItems += "<WasmExtraFilesToDeploy Include=\"main.js\" />";
else
extraItems += "<WasmExtraFilesToDeploy Include=\"main.mjs\" />";
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)
Expand Down
18 changes: 18 additions & 0 deletions src/mono/wasm/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
{
"name": "node",
"js-path": "main.mjs",
"Host": "nodejs",
"host-args": [
"--experimental-wasm-simd",
"--experimental-wasm-eh"
]
"host": "nodejs"
}
]
}
}
}