Commit 6b3ea40
authored
[wasm] First attempt at a wasm app host (#68696)
First attempt at implementing a wasm app host
Regular dotnet apps can be run with `dotnet run`. But this is not the case for
wasm apps. We use `xharness` to run the test apps that we generate for library
tests.
Templates for browser, and console wasm projects were added recently, but they
have to be run manually by either invoking a v8 script, or running a
`http-server` in the bundle directory. Though to use a debugger with this
requires starting the debug proxy separately, and connecting few bits.
# WasmAppHost
This PR adds a new `WasmAppHost`, which can be used through `dotnet run`:
- it can run "wasm app" from it's `AppBundle` directory, using various hosts
like `v8`, `node`, or a browser. An example use:
```
$ dotnet new wasmconsole
$ dotnet run
WasmAppHost --runtime-config /tmp/c0/bin/Debug/net7.0/browser-wasm/AppBundle//c0.runtimeconfig.json
[02:26:40] info: host[0] Running: node main.cjs
[02:26:40] dbug: host[0] Using working directory: /tmp/c0/bin/Debug/net7.0/browser-wasm/AppBundle
Incoming arguments:
Application arguments:
Debugger.Debug: DEBUGGING ENABLED
mono_wasm_runtime_ready fe00e07a-5519-4dfe-b35a-f867dbaf2e28
Could not find symbols file dotnet.js.symbols. Ignoring.
Initializing.....
Hello, Console!
```
The console template project is run with `node` by default.
- it supports a `--debug` parameter, which (for the browser case) would startup
a webserver, and the debug proxy for Chrome, and firefox.
```
$ dotnet new wasmbrowser
$ dotnet run --debug
WasmAppHost --runtime-config /workspaces/test/br0/bin/Debug/net7.0/browser-wasm/AppBundle//br0.runtimeconfig.json --debug --forward-console
Debug proxy for chrome now listening on http://127.0.0.1:9300/. And expecting chrome at http://localhost:9222/
Hosting environment: Production
Content root path: /workspaces/test/br0/bin/Debug/net7.0/browser-wasm/AppBundle
Now listening on: http://127.0.0.1:9300
Debug proxy for firefox now listening on tcp://127.0.0.1:6300. And expecting firefox at port 6000 .
App url: http://127.0.0.1:9000/index.html
App url: https://127.0.0.1:38331/index.html
```
- This enables using `dotnet run` with wasm samples, and library tests too.
## How do I try this out?
You'll need a dotnet with the updated packs. For now, you can use:
```
$ ./dotnet.sh build -p:TargetOS=Browser -p:TargetArchitecture=wasm -p:Configuration=Release src/tests/BuildWasmApps/Wasm.Build.Tests/Wasm.Build.Tests.csproj /t:InstallWorkloadUsingArtifacts
```
.. which would install a sdk in `artifacts/bin/dotnet-workload` with all the packs installed.
- Use that dotnet to create console, or browser wasm apps from templates, for example `dotnet new wasmconsole`, or `dotnet new wasmbrowser`.
### Debugging library tests
```
runtime$ ./artifacts/bin/dotnet-workload/dotnet run -f net7.0 -r browser-wasm -c $YourRuntimeConfig --project src/libraries/System.Buffers/tests/System.Buffers.Tests.csproj -p:DebuggerSupport=true --debug --host browser
```
- If the runtime was built in `Release` config, then you need to add `-p:DebuggerSupport=true`, so the pdbs would get deployed
- And use `--debug` to start the debugger
- Opening the url will show a `Run tests` button, which you can click after connecting with the IDE, to start running the tests
## Notes, and TODO
- `WasmAppHost`, along with the debug proxy are bundled in the `WebAssembly.Sdk` pack right now.
- This might be changed in the future to use the dotnet app host pack pattern, and with
additional support adding in the Sdk.
- This would also allow using `launchSettings.json`, similar to blazor
- `WasmAppHost` depends on host config in `runtimeconfig.json`, which can be
controlled by a `runtimeconfig.template.json` in the project directory.
- Needs more tests, cleanup, `--help` for command line arguments
- `app-support.*js` in templates, and `test-main.js` need more work to share the code
Fixes #672361 parent 637f8f2 commit 6b3ea40
File tree
63 files changed
+4718
-354
lines changed- eng/testing
- xunit
- src
- libraries
- System.Buffers/tests
- mono
- mono/component
- nuget
- Microsoft.NET.Runtime.WebAssembly.Sdk
- Sdk
- Microsoft.NET.Workload.Mono.Toolchain.Manifest
- sample/wasm
- wasm
- build
- debugger
- BrowserDebugHost
- BrowserDebugProxy
- Firefox
- DebuggerTestSuite
- host
- templates/templates
- browser
- console
- tasks/WasmAppBuilder
- tests/BuildWasmApps/Wasm.Build.Tests
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
63 files changed
+4718
-354
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | 58 | | |
| 59 | + | |
67 | 60 | | |
68 | 61 | | |
69 | 62 | | |
70 | 63 | | |
71 | 64 | | |
72 | 65 | | |
73 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
74 | 77 | | |
75 | 78 | | |
76 | 79 | | |
| |||
102 | 105 | | |
103 | 106 | | |
104 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
105 | 113 | | |
106 | 114 | | |
107 | 115 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | | - | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
140 | | - | |
| 140 | + | |
141 | 141 | | |
142 | 142 | | |
143 | 143 | | |
| |||
src/mono/nuget/Microsoft.NET.Runtime.WebAssembly.Sdk/Microsoft.NET.Runtime.WebAssembly.Sdk.pkgproj
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
36 | 40 | | |
| 41 | + | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
6 | 9 | | |
7 | 10 | | |
8 | 11 | | |
| |||
0 commit comments