Wasm tests use Microsoft.NET.Sdk.WebAssembly and support CoreClr runtime#2998
Wasm tests use Microsoft.NET.Sdk.WebAssembly and support CoreClr runtime#2998ilonatommy wants to merge 9 commits intodotnet:masterfrom
Microsoft.NET.Sdk.WebAssembly and support CoreClr runtime#2998Conversation
Instead of explicitly passing UseMonoRuntime, we should disable runtime/targeting pack download, similar to dotnet/runtime#124288 |
We don't pass it explicitly. We decided to change the sdk type instead, to change the value UseMonoRuntime defaults to. |
…RunV8Script and redundant PublishTrimmed.
Microsoft.NET.Sdk.WebAssemblyMicrosoft.NET.Sdk.WebAssembly and support CoreClr runtime
Require --output (BuildPartition.cs) — WASM needs explicit output paths because the WebAssembly SDK publishes to wwwroot/ inside the output directory. Without --output, build artifacts land in the default bin/ tree where the executor doesn't look. excludeArtifactsPath (DotNetCliCommand.cs) — BDN normally passes /p:ArtifactsPath to redirect output. But the SDK auto-sets UseArtifactsOutput=true when ArtifactsPath is non-empty, which adds $(ArtifactsPath)/** to DefaultItemExcludes — excluding every file in the project directory (including wwwroot/) from default Content globs. For WASM, we pass /p:UseArtifactsOutput=false instead, since OutDir/OutputPath/--output already control where output goes. Content Update (WasmCsProj.txt) — With UseArtifactsOutput=false, the SDK's default <Content Include="wwwroot\**" ...> glob works, so Content Update can upgrade those items with CopyToOutputDirectory=PreserveNewest.
| internal static string GetBuildCommand(ArtifactsPaths artifactsPaths, BuildPartition buildPartition, string filePath, string tfm, string? extraArguments = null, string? binLogSuffix = null, bool excludeOutput = false) | ||
| => new StringBuilder() | ||
| { | ||
| bool excludeArtifactsPath = buildPartition.RepresentativeBenchmarkCase.Job.GetToolchain() is WasmToolchain; |
There was a problem hiding this comment.
Better to pass it in as an optional argument.
| // exclude all project files (including wwwroot/) from default Content globs. | ||
| .AppendArgument(excludeArtifactsPath | ||
| ? "/p:UseArtifactsOutput=false" | ||
| : $"/p:ArtifactsPath=\"{artifactsPaths.BuildArtifactsDirectoryPath}{Path.AltDirectorySeparatorChar}\"") |
There was a problem hiding this comment.
We use artifacts path so that builds are safe to run in parallel. Without it, the build must be ran sequentially. If this is truly required, you'll need to update
BenchmarkDotNet/src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs
Lines 90 to 97 in c342c49
| { | ||
| CustomRuntimePack = customRuntimePack; | ||
| MainJS = (targetFrameworkMoniker == "net5.0" || targetFrameworkMoniker == "net6.0") ? "main.js" : "test-main.js"; | ||
| MainJS = (targetFrameworkMoniker == "net5.0" || targetFrameworkMoniker == "net6.0") ? "main.js" : "benchmark-main.mjs"; |
There was a problem hiding this comment.
It looks like the net5.0 and net6.0 path can be removed now, and the MainJS field can be made a constant.
Problem
The autogenerated benchmark project uses Microsoft.NET.Sdk, which does not set UseMonoRuntime=true. This causes ProcessFrameworkReferences to resolve the CoreCLR runtime pack (Microsoft.NETCore.App.Runtime.browser-wasm) instead of the Mono one (Microsoft.NETCore.App.Runtime.Mono.browser-wasm). The CoreCLR pack does not exist for browser-wasm, so the build fails.
PR #2994 worked around this by adding -r browser-wasm to the restore command, but this only defers the error — the runtime pack is still not resolved correctly during build.
Fix
Switch the autogenerated WASM project SDK from Microsoft.NET.Sdk to Microsoft.NET.Sdk.WebAssembly. This SDK auto-defaults UseMonoRuntime=true, ensuring the correct Mono runtime pack is selected, and auto-defaults PublishTrimmed=true, so we can drop that property too.
Additional cleanup
Testing
Integration tests: 4/4 WasmTests pass (net8.0, AOT + Interpreter × V8 + JSC)
benchmarks_ci.py: 5/5 Perf_Boolean.Parse benchmarks pass on Wasm AOT