From 6d25912069e811d7e703cd553fcee756794ba325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 19 Jan 2024 14:45:36 +0100 Subject: [PATCH 01/22] Update debug level logic --- src/mono/browser/runtime/lazyLoading.ts | 2 +- src/mono/browser/runtime/loader/config.ts | 13 ++++--------- src/mono/browser/runtime/loader/globals.ts | 3 +-- src/mono/browser/runtime/types/internal.ts | 1 - .../Microsoft.NET.Sdk.WebAssembly.Browser.targets | 7 ++++--- .../GenerateWasmBootJson.cs | 11 ++++++++++- 6 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/mono/browser/runtime/lazyLoading.ts b/src/mono/browser/runtime/lazyLoading.ts index 55bcfd67101e8c..235ca9110e1b5b 100644 --- a/src/mono/browser/runtime/lazyLoading.ts +++ b/src/mono/browser/runtime/lazyLoading.ts @@ -26,7 +26,7 @@ export async function loadLazyAssembly(assemblyNameToLoad: string): Promise debugBuild=true & debugLevel=-1 => -1 - // - Build (release) => debugBuild=true & debugLevel=0 => 0 - // - Publish (debug) => debugBuild=false & debugLevel=-1 => 0 - // - Publish (release) => debugBuild=false & debugLevel=0 => 0 - config.debugLevel = hasDebuggingEnabled(config) ? config.debugLevel : 0; + if (config.debugLevel !== 0 && !isDebuggingSupported()) + config.debugLevel = 0; if (config.diagnosticTracing === undefined && BuildConfiguration === "Debug") { config.diagnosticTracing = true; @@ -271,14 +267,13 @@ export async function mono_wasm_load_config(module: DotnetModuleInternal): Promi } } -export function hasDebuggingEnabled(config: MonoConfigInternal): boolean { +export function isDebuggingSupported(): boolean { // Copied from blazor MonoDebugger.ts/attachDebuggerHotkey if (!globalThis.navigator) { return false; } - const hasReferencedPdbs = !!config.resources!.pdb; - return (hasReferencedPdbs || config.debugLevel != 0) && (loaderHelpers.isChromium || loaderHelpers.isFirefox); + return loaderHelpers.isChromium || loaderHelpers.isFirefox; } async function loadBootConfig(module: DotnetModuleInternal): Promise { diff --git a/src/mono/browser/runtime/loader/globals.ts b/src/mono/browser/runtime/loader/globals.ts index fa07faabf0b6df..80f93d380ab0cb 100644 --- a/src/mono/browser/runtime/loader/globals.ts +++ b/src/mono/browser/runtime/loader/globals.ts @@ -15,7 +15,7 @@ import { assertIsControllablePromise, createPromiseController, getPromiseControl import { mono_download_assets, resolve_single_asset_path, retrieve_asset_download } from "./assets"; import { mono_set_thread_name, setup_proxy_console } from "./logging"; import { invokeLibraryInitializers } from "./libraryInitializers"; -import { deep_merge_config, hasDebuggingEnabled } from "./config"; +import { deep_merge_config } from "./config"; import { logDownloadStatsToConsole, purgeUnusedCacheEntriesAsync } from "./assetsCache"; // if we are the first script loaded in the web worker, we are expected to become the sidecar @@ -118,7 +118,6 @@ export function setLoaderGlobals( logDownloadStatsToConsole, purgeUnusedCacheEntriesAsync, - hasDebuggingEnabled, retrieve_asset_download, invokeLibraryInitializers, diff --git a/src/mono/browser/runtime/types/internal.ts b/src/mono/browser/runtime/types/internal.ts index c97d4c98f0211b..5d2d2382f77084 100644 --- a/src/mono/browser/runtime/types/internal.ts +++ b/src/mono/browser/runtime/types/internal.ts @@ -148,7 +148,6 @@ export type LoaderHelpers = { out(message: string): void; err(message: string): void; - hasDebuggingEnabled(config: MonoConfig): boolean, retrieve_asset_download(asset: AssetEntry): Promise; onDownloadResourceProgress?: (resourcesLoaded: number, totalResources: number) => void; logDownloadStatsToConsole: () => void; diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 28517e9c58ba3b..53a534a9d9a646 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -204,8 +204,6 @@ Copyright (c) .NET Foundation. All rights reserved. <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter) <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) <_WasmDebugLevel>$(WasmDebugLevel) - <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == ''">0 - <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == '0' and ('$(DebuggerSupport)' == 'true' or '$(Configuration)' == 'Debug')">-1 $(OutputPath)$(PublishDirName)\ @@ -336,6 +334,7 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json + <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == ''">-1 @@ -533,6 +532,9 @@ Copyright (c) .NET Foundation. All rights reserved. + + <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == ''">0 + <_WasmPublishAsset @@ -549,7 +551,6 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmPublishAsset Remove="@(_BlazorExtensionsCandidatesForPublish)" /> - 0 ? -1 : 0; + + result.debugLevel = debugLevel; + } if (ConfigurationFiles != null) { From 64708febf19abbe57150bcace06c850ec81f8613 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 19 Jan 2024 14:52:52 +0100 Subject: [PATCH 02/22] WBT 1 --- .../TestAppScenarios/DebugLevelTests.cs | 39 +++++++++++++++++++ .../WasmBasicTestApp/App/wwwroot/main.js | 4 ++ 2 files changed, 43 insertions(+) create mode 100644 src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs new file mode 100644 index 00000000000000..b406c463c2cc3f --- /dev/null +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using Xunit; +using Xunit.Abstractions; + +#nullable enable + +namespace Wasm.Build.Tests.TestAppScenarios; + +public class DebugLevelTests : AppTestBase +{ + public DebugLevelTests(ITestOutputHelper output, SharedBuildPerTestClassFixture buildContext) + : base(output, buildContext) + { + } + + [Theory] + [InlineData("Debug")] + [InlineData("Release")] + public async Task BuildWithDefaultLevel(string configuration) + { + CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_BuildWithDefaultLevel"); + + var result = await RunSdkStyleApp(new( + Configuration: configuration, + TestScenario: "DebugLevelTest" + )); + Assert.Collection( + result.TestOutput, + m => Assert.Equal("WasmDebugLevel: -1", m) + ); + } +} \ No newline at end of file diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js index 076f37a62a6d87..e5073a01f1b459 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js @@ -94,6 +94,10 @@ try { case "DownloadResourceProgressTest": exit(0); break; + case "DebugLevelTest": + testOutput("WasmDebugLevel: " + config.debugLevel); + exit(0); + break; default: console.error(`Unknown test case: ${testCase}`); exit(3); From 7bb059f151c3239fc744ccade2d01f1d48be4931 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 19 Jan 2024 15:00:58 +0100 Subject: [PATCH 03/22] Fix build --- .../GenerateWasmBootJson.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index f95bd47de5d0ef..182724768ca8a8 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -327,15 +327,11 @@ public void WriteBootJson(Stream output, string entryAssemblyName) return; } } - + if (IsTargeting80OrLater()) { - // If user didn't gave us a value, check if we have any PDB. - var debugLevel = ParseOptionalInt(DebugLevel); - if (debugLevel == null) - debugLevel = Resources?.pdb?.Count > 0 ? -1 : 0; - - result.debugLevel = debugLevel; + // If user didn't give us a value, check if we have any PDB. + result.debugLevel = ParseOptionalInt(DebugLevel) ?? (result.resources?.pdb?.Count > 0 ? -1 : 0); } if (ConfigurationFiles != null) From 9871731c9be8c7f992e7b7dcef05d260a717ed80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 24 Jan 2024 15:46:10 +0100 Subject: [PATCH 04/22] Build project. Register tests --- eng/testing/scenarios/BuildWasmAppsJobsList.txt | 1 + .../wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/eng/testing/scenarios/BuildWasmAppsJobsList.txt b/eng/testing/scenarios/BuildWasmAppsJobsList.txt index 3315a5b7fe35cf..5519c03e6ef7db 100644 --- a/eng/testing/scenarios/BuildWasmAppsJobsList.txt +++ b/eng/testing/scenarios/BuildWasmAppsJobsList.txt @@ -44,3 +44,4 @@ Wasm.Build.Tests.WasmTemplateTests Wasm.Build.Tests.WorkloadTests Wasm.Build.Tests.TestAppScenarios.DownloadResourceProgressTests Wasm.Build.Tests.MT.Blazor.SimpleMultiThreadedTests +Wasm.Build.Tests.TestAppScenarios.DebugLevelTests diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs index b406c463c2cc3f..f3d06bdd215600 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs @@ -26,6 +26,7 @@ public DebugLevelTests(ITestOutputHelper output, SharedBuildPerTestClassFixture public async Task BuildWithDefaultLevel(string configuration) { CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_BuildWithDefaultLevel"); + BuildProject(configuration); var result = await RunSdkStyleApp(new( Configuration: configuration, From 2639ec84b7c39ac0e82f932a565b019e81e1a979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 24 Jan 2024 16:00:47 +0100 Subject: [PATCH 05/22] Remove default to -1 from common props. Use separate build and publish private props --- .../Microsoft.NET.Sdk.WebAssembly.Browser.targets | 11 ++++++----- src/mono/wasm/build/WasmApp.Common.targets | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 53a534a9d9a646..6e649bc668f698 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -203,7 +203,6 @@ Copyright (c) .NET Foundation. All rights reserved. <_BlazorWebAssemblyStartupMemoryCache>$(BlazorWebAssemblyStartupMemoryCache) <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter) <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) - <_WasmDebugLevel>$(WasmDebugLevel) $(OutputPath)$(PublishDirName)\ @@ -334,7 +333,8 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json - <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == ''">-1 + <_WasmBuildDebugLevel>$(WasmDebugLevel) + <_WasmBuildDebugLevel Condition="'$(_WasmBuildDebugLevel)' == ''">-1 @@ -363,7 +363,7 @@ Copyright (c) .NET Foundation. All rights reserved. AssemblyPath="@(IntermediateAssembly)" Resources="@(_WasmOutputWithHash)" DebugBuild="true" - DebugLevel="$(_WasmDebugLevel)" + DebugLevel="$(_WasmBuildDebugLevel)" LinkerEnabled="false" CacheBootResources="$(BlazorCacheBootResources)" OutputPath="$(_WasmBuildBootJsonPath)" @@ -533,7 +533,8 @@ Copyright (c) .NET Foundation. All rights reserved. - <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == ''">0 + <_WasmPublishDebugLevel>$(WasmDebugLevel) + <_WasmPublishDebugLevel Condition="'$(_WasmPublishDebugLevel)' == ''">0 @@ -569,7 +570,7 @@ Copyright (c) .NET Foundation. All rights reserved. AssemblyPath="@(IntermediateAssembly)" Resources="@(_WasmPublishBootResourceWithHash)" DebugBuild="false" - DebugLevel="$(_WasmDebugLevel)" + DebugLevel="$(_WasmPublishDebugLevel)" LinkerEnabled="$(PublishTrimmed)" CacheBootResources="$(BlazorCacheBootResources)" OutputPath="$(IntermediateOutputPath)blazor.publish.boot.json" diff --git a/src/mono/wasm/build/WasmApp.Common.targets b/src/mono/wasm/build/WasmApp.Common.targets index 3f3a97fff9b3fd..b7559090dcdbd4 100644 --- a/src/mono/wasm/build/WasmApp.Common.targets +++ b/src/mono/wasm/build/WasmApp.Common.targets @@ -173,7 +173,7 @@ false - -1 + -1 false From ff8622be5700e45e28b8040af00994e28afe9f55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 25 Jan 2024 11:43:24 +0100 Subject: [PATCH 06/22] Switching between build and publish for run --- .../TestAppScenarios/AppSettingsTests.cs | 2 +- .../TestAppScenarios/AppTestBase.cs | 16 +++++++++++----- .../TestAppScenarios/DebugLevelTests.cs | 2 +- .../DownloadResourceProgressTests.cs | 2 +- .../TestAppScenarios/LazyLoadingTests.cs | 4 ++-- .../TestAppScenarios/LibraryInitializerTests.cs | 4 ++-- .../TestAppScenarios/SatelliteLoadingTests.cs | 2 +- 7 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppSettingsTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppSettingsTests.cs index aa39b1a376bc8a..5be6d7fda24572 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppSettingsTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppSettingsTests.cs @@ -29,7 +29,7 @@ public async Task LoadAppSettingsBasedOnApplicationEnvironment(string applicatio CopyTestAsset("WasmBasicTestApp", "AppSettingsTests"); PublishProject("Debug"); - var result = await RunSdkStyleApp(new( + var result = await RunSdkStyleAppForPublish(new( Configuration: "Debug", TestScenario: "AppSettingsTest", BrowserQueryString: new Dictionary { ["applicationEnvironment"] = applicationEnvironment } diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs index dc6fb9b490e7f3..8d791e65b177bf 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs @@ -36,15 +36,15 @@ protected void CopyTestAsset(string assetName, string generatedProjectNamePrefix _projectDir = Path.Combine(_projectDir!, "App"); } - protected void BuildProject(string configuration) + protected void BuildProject(string configuration, params string[] extraArgs) { - (CommandResult result, _) = BlazorBuild(new BlazorBuildOptions(Id, configuration)); + (CommandResult result, _) = BlazorBuild(new BlazorBuildOptions(Id, configuration), extraArgs); result.EnsureSuccessful(); } - protected void PublishProject(string configuration) + protected void PublishProject(string configuration, params string[] extraArgs) { - (CommandResult result, _) = BlazorPublish(new BlazorBuildOptions(Id, configuration)); + (CommandResult result, _) = BlazorPublish(new BlazorBuildOptions(Id, configuration), extraArgs); result.EnsureSuccessful(); } @@ -52,7 +52,13 @@ protected void PublishProject(string configuration) .WithWorkingDirectory(_projectDir!) .WithEnvironmentVariable("NUGET_PACKAGES", _nugetPackagesDir); - protected async Task RunSdkStyleApp(RunOptions options) + protected Task RunSdkStyleAppForBuild(RunOptions options) + => RunSdkStyleApp(options, BlazorRunHost.DotnetRun); + + protected Task RunSdkStyleAppForPublish(RunOptions options) + => RunSdkStyleApp(options, BlazorRunHost.WebServer); + + private async Task RunSdkStyleApp(RunOptions options, BlazorRunHost host = BlazorRunHost.DotnetRun) { string queryString = "?test=" + options.TestScenario; if (options.BrowserQueryString != null) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs index f3d06bdd215600..69eb947975d4fb 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs @@ -28,7 +28,7 @@ public async Task BuildWithDefaultLevel(string configuration) CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_BuildWithDefaultLevel"); BuildProject(configuration); - var result = await RunSdkStyleApp(new( + var result = await RunSdkStyleAppForBuild(new( Configuration: configuration, TestScenario: "DebugLevelTest" )); diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index 5088a2e6a1160e..79beb58b093d37 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -29,7 +29,7 @@ public async Task DownloadProgressFinishes(bool failAssemblyDownload) CopyTestAsset("WasmBasicTestApp", $"DownloadResourceProgressTests_{failAssemblyDownload}"); PublishProject("Debug"); - var result = await RunSdkStyleApp(new( + var result = await RunSdkStyleAppForPublish(new( Configuration: "Debug", TestScenario: "DownloadResourceProgressTest", BrowserQueryString: new Dictionary { ["failAssemblyDownload"] = failAssemblyDownload.ToString().ToLowerInvariant() } diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs index 1603fff79e0b26..da57f46cfbd81e 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs @@ -27,7 +27,7 @@ public async Task LoadLazyAssemblyBeforeItIsNeeded() CopyTestAsset("WasmBasicTestApp", "LazyLoadingTests"); PublishProject("Debug"); - var result = await RunSdkStyleApp(new(Configuration: "Debug", TestScenario: "LazyLoadingTest")); + var result = await RunSdkStyleAppForPublish(new(Configuration: "Debug", TestScenario: "LazyLoadingTest")); Assert.True(result.TestOutput.Any(m => m.Contains("FirstName")), "The lazy loading test didn't emit expected message with JSON"); } @@ -38,7 +38,7 @@ public async Task FailOnMissingLazyAssembly() CopyTestAsset("WasmBasicTestApp", "LazyLoadingTests"); PublishProject("Debug"); - var result = await RunSdkStyleApp(new( + var result = await RunSdkStyleAppForPublish(new( Configuration: "Debug", TestScenario: "LazyLoadingTest", BrowserQueryString: new Dictionary { ["loadRequiredAssembly"] = "false" }, diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LibraryInitializerTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LibraryInitializerTests.cs index 2227c05f19498a..2aac33de9347ae 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LibraryInitializerTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LibraryInitializerTests.cs @@ -30,7 +30,7 @@ public async Task LoadLibraryInitializer() CopyTestAsset("WasmBasicTestApp", "LibraryInitializerTests_LoadLibraryInitializer"); PublishProject("Debug"); - var result = await RunSdkStyleApp(new(Configuration: "Debug", TestScenario: "LibraryInitializerTest")); + var result = await RunSdkStyleAppForPublish(new(Configuration: "Debug", TestScenario: "LibraryInitializerTest")); Assert.Collection( result.TestOutput, m => Assert.Equal("LIBRARY_INITIALIZER_TEST = 1", m) @@ -44,7 +44,7 @@ public async Task AbortStartupOnError() CopyTestAsset("WasmBasicTestApp", "LibraryInitializerTests_AbortStartupOnError"); PublishProject("Debug"); - var result = await RunSdkStyleApp(new( + var result = await RunSdkStyleAppForPublish(new( Configuration: "Debug", TestScenario: "LibraryInitializerTest", BrowserQueryString: new Dictionary { ["throwError"] = "true" }, diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs index b82fae815234ec..32b1b91659311b 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs @@ -30,7 +30,7 @@ public async Task LoadSatelliteAssembly() CopyTestAsset("WasmBasicTestApp", "SatelliteLoadingTests"); BuildProject("Debug"); - var result = await RunSdkStyleApp(new(Configuration: "Debug", TestScenario: "SatelliteAssembliesTest")); + var result = await RunSdkStyleAppForPublish(new(Configuration: "Debug", TestScenario: "SatelliteAssembliesTest")); Assert.Collection( result.TestOutput, m => Assert.Equal("default: hello", m), From 30595a777482d86b874dc0529ba71bfcac49f605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 25 Jan 2024 11:43:30 +0100 Subject: [PATCH 07/22] More tests --- .../TestAppScenarios/DebugLevelTests.cs | 62 +++++++++++++++++-- 1 file changed, 58 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs index 69eb947975d4fb..bc3bc79c95bc08 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs @@ -20,6 +20,14 @@ public DebugLevelTests(ITestOutputHelper output, SharedBuildPerTestClassFixture { } + private void AssertDebugLevel(RunResult result, int value) + { + Assert.Collection( + result.TestOutput, + m => Assert.Equal($"WasmDebugLevel: {value}", m) + ); + } + [Theory] [InlineData("Debug")] [InlineData("Release")] @@ -32,9 +40,55 @@ public async Task BuildWithDefaultLevel(string configuration) Configuration: configuration, TestScenario: "DebugLevelTest" )); - Assert.Collection( - result.TestOutput, - m => Assert.Equal("WasmDebugLevel: -1", m) - ); + AssertDebugLevel(result, -1); + } + + [Theory] + [InlineData("Debug", 1)] + [InlineData("Release", 1)] + [InlineData("Debug", 0)] + [InlineData("Release", 0)] + public async Task BuildWithExplicitValue(string configuration, int debugLevel) + { + CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_BuildWithExplicitValue"); + BuildProject(configuration, $"-p:WasmDebugLevel={debugLevel}"); + + var result = await RunSdkStyleAppForBuild(new( + Configuration: configuration, + TestScenario: "DebugLevelTest" + )); + AssertDebugLevel(result, debugLevel); + } + + [Theory] + [InlineData("Debug")] + [InlineData("Release")] + public async Task PublishWithDefaultLevel(string configuration) + { + CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_PublishWithDefaultLevel"); + PublishProject(configuration); + + var result = await RunSdkStyleAppForPublish(new( + Configuration: configuration, + TestScenario: "DebugLevelTest" + )); + AssertDebugLevel(result, 0); + } + + [Theory] + [InlineData("Debug", 1)] + [InlineData("Release", 1)] + [InlineData("Debug", -1)] + [InlineData("Release", -1)] + public async Task PublishWithExplicitValue(string configuration, int debugLevel) + { + CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_PublishWithExplicitValue"); + PublishProject(configuration, $"-p:WasmDebugLevel={debugLevel}"); + + var result = await RunSdkStyleAppForPublish(new( + Configuration: configuration, + TestScenario: "DebugLevelTest" + )); + AssertDebugLevel(result, debugLevel); } } \ No newline at end of file From 3affa888faceb1b0ef8c344476ea7267e09b897f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 25 Jan 2024 14:11:51 +0100 Subject: [PATCH 08/22] Remove WasmDebugLevel defaults from WasmApp.Common.targets. Create similar behavior for WASI --- src/mono/wasi/build/WasiApp.targets | 8 +++++++- src/mono/wasm/build/WasmApp.Common.targets | 3 --- src/tasks/WasmAppBuilder/WasmAppBuilder.cs | 1 + src/tasks/WasmAppBuilder/WasmAppBuilderBaseTask.cs | 1 - src/tasks/WasmAppBuilder/wasi/WasiAppBuilder.cs | 3 ++- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/mono/wasi/build/WasiApp.targets b/src/mono/wasi/build/WasiApp.targets index e54fbe4f89ac1a..e0bad6142986cd 100644 --- a/src/mono/wasi/build/WasiApp.targets +++ b/src/mono/wasi/build/WasiApp.targets @@ -66,6 +66,12 @@ Outputs="$(WasmAppDir)\.stamp" Condition="'$(WasmGenerateAppBundle)' == 'true'"> + + <_WasmOutputSymbolsToAppBundle Condition="'$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(_IsPublishing)' == 'true'">true + <_WasmOutputSymbolsToAppBundle Condition="'$(_WasmOutputSymbolsToAppBundle)' == '' and '$(_IsPublishing)' == 'true'">false + <_WasmOutputSymbolsToAppBundle Condition="'$(_WasmOutputSymbolsToAppBundle)' == ''">false + + diff --git a/src/mono/wasm/build/WasmApp.Common.targets b/src/mono/wasm/build/WasmApp.Common.targets index b7559090dcdbd4..f0c0d4be6946ab 100644 --- a/src/mono/wasm/build/WasmApp.Common.targets +++ b/src/mono/wasm/build/WasmApp.Common.targets @@ -172,9 +172,6 @@ --> false - - -1 - false false diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs index e8a52724b38a40..a82c73e21b2565 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.cs @@ -28,6 +28,7 @@ public class WasmAppBuilder : WasmAppBuilderBaseTask public string? WasmIcuDataFileName { get; set; } public string? RuntimeAssetsLocation { get; set; } public bool CacheBootResources { get; set; } + public int DebugLevel { get; set; } private static readonly JsonSerializerOptions s_jsonOptions = new JsonSerializerOptions { diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilderBaseTask.cs b/src/tasks/WasmAppBuilder/WasmAppBuilderBaseTask.cs index c580fcd80eff18..97bae1eaf37314 100644 --- a/src/tasks/WasmAppBuilder/WasmAppBuilderBaseTask.cs +++ b/src/tasks/WasmAppBuilder/WasmAppBuilderBaseTask.cs @@ -38,7 +38,6 @@ public abstract class WasmAppBuilderBaseTask : Task // https://github.com/dotnet/icu/tree/maint/maint-67/icu-filters public string[] IcuDataFileNames { get; set; } = Array.Empty(); - public int DebugLevel { get; set; } public ITaskItem[] SatelliteAssemblies { get; set; } = Array.Empty(); public bool HybridGlobalization { get; set; } public bool InvariantGlobalization { get; set; } diff --git a/src/tasks/WasmAppBuilder/wasi/WasiAppBuilder.cs b/src/tasks/WasmAppBuilder/wasi/WasiAppBuilder.cs index 59c737db14e2c7..8575ea6bf8ad9e 100644 --- a/src/tasks/WasmAppBuilder/wasi/WasiAppBuilder.cs +++ b/src/tasks/WasmAppBuilder/wasi/WasiAppBuilder.cs @@ -12,6 +12,7 @@ namespace Microsoft.WebAssembly.Build.Tasks; public class WasiAppBuilder : WasmAppBuilderBaseTask { public bool IsSingleFileBundle { get; set; } + public bool OutputSymbolsToAppBundle { get; set; } protected override bool ValidateArguments() { @@ -66,7 +67,7 @@ protected override bool ExecuteInternal() { FileCopyChecked(assembly, Path.Combine(asmRootPath, Path.GetFileName(assembly)), "Assemblies"); - if (DebugLevel != 0) + if (OutputSymbolsToAppBundle) { string pdb = Path.ChangeExtension(assembly, ".pdb"); if (File.Exists(pdb)) From 0ffcdfe193b786d0fdcdfa55a9542ded5910c23c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 26 Jan 2024 11:52:07 +0100 Subject: [PATCH 09/22] Add configuration to generated project name --- .../Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs index bc3bc79c95bc08..60247757e9e1e9 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs @@ -33,7 +33,7 @@ private void AssertDebugLevel(RunResult result, int value) [InlineData("Release")] public async Task BuildWithDefaultLevel(string configuration) { - CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_BuildWithDefaultLevel"); + CopyTestAsset("WasmBasicTestApp", $"DebugLevelTests_BuildWithDefaultLevel_{configuration}"); BuildProject(configuration); var result = await RunSdkStyleAppForBuild(new( @@ -50,7 +50,7 @@ public async Task BuildWithDefaultLevel(string configuration) [InlineData("Release", 0)] public async Task BuildWithExplicitValue(string configuration, int debugLevel) { - CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_BuildWithExplicitValue"); + CopyTestAsset("WasmBasicTestApp", $"DebugLevelTests_BuildWithExplicitValue_{configuration}"); BuildProject(configuration, $"-p:WasmDebugLevel={debugLevel}"); var result = await RunSdkStyleAppForBuild(new( @@ -65,7 +65,7 @@ public async Task BuildWithExplicitValue(string configuration, int debugLevel) [InlineData("Release")] public async Task PublishWithDefaultLevel(string configuration) { - CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_PublishWithDefaultLevel"); + CopyTestAsset("WasmBasicTestApp", $"DebugLevelTests_PublishWithDefaultLevel_{configuration}"); PublishProject(configuration); var result = await RunSdkStyleAppForPublish(new( @@ -82,7 +82,7 @@ public async Task PublishWithDefaultLevel(string configuration) [InlineData("Release", -1)] public async Task PublishWithExplicitValue(string configuration, int debugLevel) { - CopyTestAsset("WasmBasicTestApp", "DebugLevelTests_PublishWithExplicitValue"); + CopyTestAsset("WasmBasicTestApp", $"DebugLevelTests_PublishWithExplicitValue_{configuration}"); PublishProject(configuration, $"-p:WasmDebugLevel={debugLevel}"); var result = await RunSdkStyleAppForPublish(new( From 39191f6f2dcc48ac444d5a084a23e247c32974c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 26 Jan 2024 12:15:37 +0100 Subject: [PATCH 10/22] Expect relinked files when doing publish in Release --- .../wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs index a5d01c2d883865..5617375f213c8a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs @@ -63,7 +63,13 @@ public string CreateBlazorWasmTemplateProject(string id) (CommandResult res, string logPath) = BlazorBuildInternal(options.Id, options.Config, publish: false, setWasmDevel: false, expectSuccess: options.ExpectSuccess, extraArgs); if (options.ExpectSuccess && options.AssertAppBundle) + { + // Because we do relink in Release build by default + if (options.Config == "Release") + options = options with { ExpectedFileType = NativeFilesType.Relinked }; + AssertBundle(res.Output, options with { IsPublish = false }); + } return (res, logPath); } @@ -77,6 +83,10 @@ public string CreateBlazorWasmTemplateProject(string id) if (options.ExpectSuccess && options.AssertAppBundle) { + // Because we do relink in Release build by default + if (options.Config == "Release") + options = options with { ExpectedFileType = NativeFilesType.Relinked }; + AssertBundle(res.Output, options with { IsPublish = true }); } From fa5c5b132953afcc05fb9e51f766e47aa2de3dfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 7 Feb 2024 14:14:19 +0100 Subject: [PATCH 11/22] Auto relink only in publish --- src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs index 5617375f213c8a..2e3491374c7d91 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs @@ -64,10 +64,6 @@ public string CreateBlazorWasmTemplateProject(string id) if (options.ExpectSuccess && options.AssertAppBundle) { - // Because we do relink in Release build by default - if (options.Config == "Release") - options = options with { ExpectedFileType = NativeFilesType.Relinked }; - AssertBundle(res.Output, options with { IsPublish = false }); } @@ -83,7 +79,7 @@ public string CreateBlazorWasmTemplateProject(string id) if (options.ExpectSuccess && options.AssertAppBundle) { - // Because we do relink in Release build by default + // Because we do relink in Release publish by default if (options.Config == "Release") options = options with { ExpectedFileType = NativeFilesType.Relinked }; From 550df3154f62839e492d405f3f871afbce569bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Wed, 7 Feb 2024 14:14:38 +0100 Subject: [PATCH 12/22] Switch between dotnet run and webserver for hosting Blazor WBT --- .../wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs index 8d791e65b177bf..771daff1f5d469 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppTestBase.cs @@ -73,9 +73,10 @@ private async Task RunSdkStyleApp(RunOptions options, BlazorRunHost h CheckCounter: false, Config: options.Configuration, OnConsoleMessage: OnConsoleMessage, - QueryString: queryString); + QueryString: queryString, + Host: host); - await BlazorRunForBuildWithDotnetRun(blazorRunOptions); + await BlazorRunTest(blazorRunOptions); void OnConsoleMessage(IConsoleMessage msg) { From 78f54035edc3aafb03a33dad8c5c264c2d94e00a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 8 Feb 2024 11:41:19 +0100 Subject: [PATCH 13/22] Fix using run for build in SatelliteLoadingTests --- .../Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs index 2cdf1b340dd3c7..2088e1522ad73b 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/SatelliteLoadingTests.cs @@ -29,7 +29,7 @@ public async Task LoadSatelliteAssembly() CopyTestAsset("WasmBasicTestApp", "SatelliteLoadingTests"); BuildProject("Debug"); - var result = await RunSdkStyleAppForPublish(new(Configuration: "Debug", TestScenario: "SatelliteAssembliesTest")); + var result = await RunSdkStyleAppForBuild(new(Configuration: "Debug", TestScenario: "SatelliteAssembliesTest")); Assert.Collection( result.TestOutput, m => Assert.Equal("default: hello", m), From 2dcf7139e45449faff7a0cb83b0a4c19467ffe8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Thu, 8 Feb 2024 18:22:17 +0100 Subject: [PATCH 14/22] Explicitly set debug level to 0 to trigger tiering --- src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs index 203ad80fc4dc77..8264b9c0bacbe0 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs @@ -74,7 +74,7 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config) using var runCommand = new RunCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!); await using var runner = new BrowserRunner(_testOutput); - var url = await runner.StartServerAndGetUrlAsync(runCommand, $"run --no-silent -c {config} --no-build --project \"{projectFile}\" --forward-console"); + var url = await runner.StartServerAndGetUrlAsync(runCommand, $"run --no-silent -c {config} -p:WasmDebugLevel=0 --no-build --project \"{projectFile}\" --forward-console"); IBrowser browser = await runner.SpawnBrowserAsync(url); IBrowserContext context = await browser.NewContextAsync(); From 713719f87679394beafd73042ddb5c449ee8378f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 9 Feb 2024 09:28:11 +0100 Subject: [PATCH 15/22] Explicitly set debug level to 0 to trigger tiering (put debug level into csproj + print debug level on runtime) --- src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs | 5 +++-- src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs index 8264b9c0bacbe0..4fe88ee8daca3d 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs @@ -34,7 +34,7 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config) string id = $"browser_{config}_{GetRandomId()}"; _testOutput.WriteLine("/// Creating project"); - string projectFile = CreateWasmTemplateProject(id, "wasmbrowser"); + string projectFile = CreateWasmTemplateProject(id, "wasmbrowser", extraProperties: "0"); _testOutput.WriteLine("/// Updating JS"); UpdateBrowserMainJs((js) => { @@ -53,6 +53,7 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config) // then call INTERNAL.interp_pgo_save_data() to save the interp PGO table js = js.Replace( "const text = exports.MyClass.Greeting();", + "console.log(`WASM debug level ${getConfig().debugLevel}`);\n" + "let text = '';\n" + $"for (let i = 0; i < {iterationCount}; i++) {{ text = exports.MyClass.Greeting(); }};\n" + "await INTERNAL.interp_pgo_save_data();" @@ -74,7 +75,7 @@ public async Task FirstRunGeneratesTableAndSecondRunLoadsIt(string config) using var runCommand = new RunCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!); await using var runner = new BrowserRunner(_testOutput); - var url = await runner.StartServerAndGetUrlAsync(runCommand, $"run --no-silent -c {config} -p:WasmDebugLevel=0 --no-build --project \"{projectFile}\" --forward-console"); + var url = await runner.StartServerAndGetUrlAsync(runCommand, $"run --no-silent -c {config} --no-build --project \"{projectFile}\" --forward-console"); IBrowser browser = await runner.SpawnBrowserAsync(url); IBrowserContext context = await browser.NewContextAsync(); diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs index 38037f7d96f141..9c923799221553 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTestBase.cs @@ -22,7 +22,7 @@ protected WasmTemplateTestBase(ITestOutputHelper output, SharedBuildPerTestClass _provider.BundleDirName = "AppBundle"; } - public string CreateWasmTemplateProject(string id, string template = "wasmbrowser", string extraArgs = "", bool runAnalyzers = true, bool addFrameworkArg = false) + public string CreateWasmTemplateProject(string id, string template = "wasmbrowser", string extraArgs = "", bool runAnalyzers = true, bool addFrameworkArg = false, string? extraProperties = null) { InitPaths(id); InitProjectDir(_projectDir, addNuGetSourceForLocalPackages: true); @@ -49,7 +49,10 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse .EnsureSuccessful(); string projectfile = Path.Combine(_projectDir!, $"{id}.csproj"); - string extraProperties = string.Empty; + + if (extraProperties == null) + extraProperties = string.Empty; + extraProperties += "true"; if (runAnalyzers) extraProperties += "true"; From 9d27cf4908839c77dce46d4326d8f23845c2715a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 9 Feb 2024 09:40:43 +0100 Subject: [PATCH 16/22] Be sure not to fail download twice for the same asset --- src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js index e5073a01f1b459..2e1b7ff8c84fe3 100644 --- a/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js +++ b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js @@ -33,6 +33,7 @@ switch (testCase) { Math.floor(Math.random() * 5) + 5, Math.floor(Math.random() * 5) + 10 ]; + let alreadyFailed = []; dotnet.withDiagnosticTracing(true).withResourceLoader((type, name, defaultUri, integrity, behavior) => { if (type === "dotnetjs") { // loadBootResource could return string with unqualified name of resource. @@ -45,9 +46,10 @@ switch (testCase) { } assemblyCounter++; - if (!failAtAssemblyNumbers.includes(assemblyCounter)) + if (!failAtAssemblyNumbers.includes(assemblyCounter) || alreadyFailed.includes(defaultUri)) return defaultUri; + alreadyFailed.push(defaultUri); testOutput("Throw error instead of downloading resource"); const error = new Error("Simulating a failed fetch"); error.silent = true; From 2f8c92be288eff4f56257add76ef7ea687065e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 9 Feb 2024 19:29:09 +0100 Subject: [PATCH 17/22] Don't let missing debugger support override debug level used for logging --- src/mono/browser/runtime/lazyLoading.ts | 2 +- src/mono/browser/runtime/loader/assets.ts | 2 +- src/mono/browser/runtime/loader/config.ts | 5 ----- src/mono/browser/runtime/loader/globals.ts | 3 ++- src/mono/browser/runtime/startup.ts | 3 +++ src/mono/browser/runtime/types/internal.ts | 1 + 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/mono/browser/runtime/lazyLoading.ts b/src/mono/browser/runtime/lazyLoading.ts index 235ca9110e1b5b..85058f89819b7c 100644 --- a/src/mono/browser/runtime/lazyLoading.ts +++ b/src/mono/browser/runtime/lazyLoading.ts @@ -26,7 +26,7 @@ export async function loadLazyAssembly(assemblyNameToLoad: string): Promise Promise, libraryInitializers?: { scriptName: string, exports: any }[]; + isDebuggingSupported(): boolean, isChromium: boolean, isFirefox: boolean From bb287205ab0ab3e10d67f5e48b4d232b396a95fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Fri, 9 Feb 2024 20:31:49 +0100 Subject: [PATCH 18/22] Fallback to count of pdbs --- ...icrosoft.NET.Sdk.WebAssembly.Browser.targets | 17 ++++++----------- .../TestAppScenarios/DebugLevelTests.cs | 17 ++++++++++++++++- .../GenerateWasmBootJson.cs | 12 +++++++++++- 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets index 6e649bc668f698..f54c84ae9ad829 100644 --- a/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets +++ b/src/mono/nuget/Microsoft.NET.Sdk.WebAssembly.Pack/build/Microsoft.NET.Sdk.WebAssembly.Browser.targets @@ -333,8 +333,6 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmBuildBootJsonPath>$(IntermediateOutputPath)blazor.boot.json - <_WasmBuildDebugLevel>$(WasmDebugLevel) - <_WasmBuildDebugLevel Condition="'$(_WasmBuildDebugLevel)' == ''">-1 @@ -363,7 +361,7 @@ Copyright (c) .NET Foundation. All rights reserved. AssemblyPath="@(IntermediateAssembly)" Resources="@(_WasmOutputWithHash)" DebugBuild="true" - DebugLevel="$(_WasmBuildDebugLevel)" + DebugLevel="$(WasmDebugLevel)" LinkerEnabled="false" CacheBootResources="$(BlazorCacheBootResources)" OutputPath="$(_WasmBuildBootJsonPath)" @@ -379,7 +377,8 @@ Copyright (c) .NET Foundation. All rights reserved. Extensions="@(WasmBootConfigExtension)" TargetFrameworkVersion="$(TargetFrameworkVersion)" ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)" - ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" /> + ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" + IsPublish="false" /> @@ -532,11 +531,6 @@ Copyright (c) .NET Foundation. All rights reserved. - - <_WasmPublishDebugLevel>$(WasmDebugLevel) - <_WasmPublishDebugLevel Condition="'$(_WasmPublishDebugLevel)' == ''">0 - - <_WasmPublishAsset Include="@(StaticWebAsset)" @@ -570,7 +564,7 @@ Copyright (c) .NET Foundation. All rights reserved. AssemblyPath="@(IntermediateAssembly)" Resources="@(_WasmPublishBootResourceWithHash)" DebugBuild="false" - DebugLevel="$(_WasmPublishDebugLevel)" + DebugLevel="$(WasmDebugLevel)" LinkerEnabled="$(PublishTrimmed)" CacheBootResources="$(BlazorCacheBootResources)" OutputPath="$(IntermediateOutputPath)blazor.publish.boot.json" @@ -586,7 +580,8 @@ Copyright (c) .NET Foundation. All rights reserved. Extensions="@(WasmBootConfigExtension)" TargetFrameworkVersion="$(TargetFrameworkVersion)" ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)" - ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" /> + ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" + IsPublish="true" /> diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs index 60247757e9e1e9..3dfe4c467f79f7 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs @@ -91,4 +91,19 @@ public async Task PublishWithExplicitValue(string configuration, int debugLevel) )); AssertDebugLevel(result, debugLevel); } -} \ No newline at end of file + + [Theory] + [InlineData("Debug")] + [InlineData("Release")] + public async Task PublishWithDefaultLevelAndPdbs(string configuration) + { + CopyTestAsset("WasmBasicTestApp", $"DebugLevelTests_PublishWithDefaultLevelAndPdbs_{configuration}"); + PublishProject(configuration, $"-p:CopyOutputSymbolsToPublishDirectory=true"); + + var result = await RunSdkStyleAppForPublish(new( + Configuration: configuration, + TestScenario: "DebugLevelTest" + )); + AssertDebugLevel(result, -1); + } +} diff --git a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs index 182724768ca8a8..d5dc83e4252df0 100644 --- a/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs +++ b/src/tasks/Microsoft.NET.Sdk.WebAssembly.Pack.Tasks/GenerateWasmBootJson.cs @@ -71,6 +71,8 @@ public class GenerateWasmBootJson : Task public ITaskItem[] LazyLoadedAssemblies { get; set; } + public bool IsPublish { get; set; } + public override bool Execute() { using var fileStream = File.Create(OutputPath); @@ -330,8 +332,16 @@ public void WriteBootJson(Stream output, string entryAssemblyName) if (IsTargeting80OrLater()) { + int? debugLevel = ParseOptionalInt(DebugLevel); + // If user didn't give us a value, check if we have any PDB. - result.debugLevel = ParseOptionalInt(DebugLevel) ?? (result.resources?.pdb?.Count > 0 ? -1 : 0); + if (debugLevel == null && result.resources?.pdb?.Count > 0) + debugLevel = -1; + + // Fallback to -1 for build, or 0 for publish + debugLevel ??= IsPublish ? 0 : -1; + + result.debugLevel = debugLevel.Value; } if (ConfigurationFiles != null) From 9401db892f797f20f9fa7823360c7d1b5f5a14ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Sat, 10 Feb 2024 10:31:46 +0100 Subject: [PATCH 19/22] Update src/mono/wasi/build/WasiApp.targets Co-authored-by: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> --- src/mono/wasi/build/WasiApp.targets | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mono/wasi/build/WasiApp.targets b/src/mono/wasi/build/WasiApp.targets index e0bad6142986cd..b31c573ea349b5 100644 --- a/src/mono/wasi/build/WasiApp.targets +++ b/src/mono/wasi/build/WasiApp.targets @@ -68,7 +68,6 @@ <_WasmOutputSymbolsToAppBundle Condition="'$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(_IsPublishing)' == 'true'">true - <_WasmOutputSymbolsToAppBundle Condition="'$(_WasmOutputSymbolsToAppBundle)' == '' and '$(_IsPublishing)' == 'true'">false <_WasmOutputSymbolsToAppBundle Condition="'$(_WasmOutputSymbolsToAppBundle)' == ''">false From 67c562e22a59c4f8fe64b43f52f4c499235386de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 12 Feb 2024 09:24:23 +0100 Subject: [PATCH 20/22] Feedback --- src/mono/browser/runtime/startup.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index 9d7306d9254790..da30a7b50a5bb8 100644 --- a/src/mono/browser/runtime/startup.ts +++ b/src/mono/browser/runtime/startup.ts @@ -3,7 +3,7 @@ import WasmEnableThreads from "consts:wasmEnableThreads"; -import { DotnetModuleInternal, CharPtrNull } from "./types/internal"; +import { DotnetModuleInternal, CharPtrNull, MonoConfigInternal } from "./types/internal"; import { ENVIRONMENT_IS_NODE, exportedRuntimeAPI, INTERNAL, loaderHelpers, Module, runtimeHelpers, createPromiseController, mono_assert, ENVIRONMENT_IS_WORKER } from "./globals"; import cwraps, { init_c_exports, threads_c_functions as tcwraps } from "./cwraps"; import { mono_wasm_raise_debug_event, mono_wasm_runtime_ready } from "./debug"; @@ -515,7 +515,7 @@ async function start_runtime() { if (runtimeHelpers.config.browserProfilerOptions) mono_wasm_init_browser_profiler(runtimeHelpers.config.browserProfilerOptions); - mono_wasm_load_runtime("unused", runtimeHelpers.config.debugLevel); + mono_wasm_load_runtime(runtimeHelpers.config); if (runtimeHelpers.config.interpreterPgo) setTimeout(maybeSaveInterpPgoTable, (runtimeHelpers.config.interpreterPgoSaveDelay || 15) * 1000); @@ -534,20 +534,21 @@ async function maybeSaveInterpPgoTable() { await interp_pgo_save_data(); } -export function mono_wasm_load_runtime(unused?: string, debugLevel?: number): void { +export function mono_wasm_load_runtime(config: MonoConfigInternal): void { mono_log_debug("mono_wasm_load_runtime"); try { const mark = startMeasure(); + let debugLevel = config.debugLevel; if (debugLevel == undefined) { debugLevel = 0; if (runtimeHelpers.config.debugLevel) { debugLevel = 0 + debugLevel; } } - if (!loaderHelpers.isDebuggingSupported()) { + if (!loaderHelpers.isDebuggingSupported() || !config.resources!.pdb) { debugLevel = 0; } - cwraps.mono_wasm_load_runtime(unused || "unused", debugLevel); + cwraps.mono_wasm_load_runtime("unused", debugLevel); endMeasure(mark, MeasuredBlock.loadRuntime); } catch (err: any) { From 300d782dd4a8081e6e1c8b1e053a06f1c59548f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 12 Feb 2024 18:30:46 +0100 Subject: [PATCH 21/22] Feedback --- src/mono/browser/runtime/cwraps.ts | 2 +- src/mono/browser/runtime/driver.c | 2 +- src/mono/browser/runtime/startup.ts | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mono/browser/runtime/cwraps.ts b/src/mono/browser/runtime/cwraps.ts index 29d384f65795b0..71fbf7202342a4 100644 --- a/src/mono/browser/runtime/cwraps.ts +++ b/src/mono/browser/runtime/cwraps.ts @@ -166,7 +166,7 @@ export interface t_Cwraps { mono_wasm_load_icu_data(offset: VoidPtr): number; mono_wasm_add_assembly(name: string, data: VoidPtr, size: number): number; mono_wasm_add_satellite_assembly(name: string, culture: string, data: VoidPtr, size: number): void; - mono_wasm_load_runtime(unused: string, debugLevel: number): void; + mono_wasm_load_runtime(debugLevel: number): void; mono_wasm_change_debugger_log_level(value: number): void; mono_wasm_assembly_load(name: string): MonoAssembly; diff --git a/src/mono/browser/runtime/driver.c b/src/mono/browser/runtime/driver.c index a7bd6f5966e0b0..eea015cb0ea5a9 100644 --- a/src/mono/browser/runtime/driver.c +++ b/src/mono/browser/runtime/driver.c @@ -181,7 +181,7 @@ cleanup_runtime_config (MonovmRuntimeConfigArguments *args, void *user_data) } EMSCRIPTEN_KEEPALIVE void -mono_wasm_load_runtime (const char *unused, int debug_level) +mono_wasm_load_runtime (int debug_level) { const char *interp_opts = ""; diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index da30a7b50a5bb8..a2611aab33279c 100644 --- a/src/mono/browser/runtime/startup.ts +++ b/src/mono/browser/runtime/startup.ts @@ -515,7 +515,7 @@ async function start_runtime() { if (runtimeHelpers.config.browserProfilerOptions) mono_wasm_init_browser_profiler(runtimeHelpers.config.browserProfilerOptions); - mono_wasm_load_runtime(runtimeHelpers.config); + mono_wasm_load_runtime(); if (runtimeHelpers.config.interpreterPgo) setTimeout(maybeSaveInterpPgoTable, (runtimeHelpers.config.interpreterPgoSaveDelay || 15) * 1000); @@ -534,21 +534,21 @@ async function maybeSaveInterpPgoTable() { await interp_pgo_save_data(); } -export function mono_wasm_load_runtime(config: MonoConfigInternal): void { +export function mono_wasm_load_runtime(): void { mono_log_debug("mono_wasm_load_runtime"); try { const mark = startMeasure(); - let debugLevel = config.debugLevel; + let debugLevel = runtimeHelpers.config.debugLevel; if (debugLevel == undefined) { debugLevel = 0; if (runtimeHelpers.config.debugLevel) { debugLevel = 0 + debugLevel; } } - if (!loaderHelpers.isDebuggingSupported() || !config.resources!.pdb) { + if (!loaderHelpers.isDebuggingSupported() || !runtimeHelpers.config.resources!.pdb) { debugLevel = 0; } - cwraps.mono_wasm_load_runtime("unused", debugLevel); + cwraps.mono_wasm_load_runtime(debugLevel); endMeasure(mark, MeasuredBlock.loadRuntime); } catch (err: any) { From 8e8d10037059539ce8d03cbd5a82d9d9221e5198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Fi=C5=A1era?= Date: Mon, 12 Feb 2024 18:41:00 +0100 Subject: [PATCH 22/22] Fix build --- src/mono/browser/runtime/startup.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index a2611aab33279c..a1f6b95dd1814b 100644 --- a/src/mono/browser/runtime/startup.ts +++ b/src/mono/browser/runtime/startup.ts @@ -3,7 +3,7 @@ import WasmEnableThreads from "consts:wasmEnableThreads"; -import { DotnetModuleInternal, CharPtrNull, MonoConfigInternal } from "./types/internal"; +import { DotnetModuleInternal, CharPtrNull } from "./types/internal"; import { ENVIRONMENT_IS_NODE, exportedRuntimeAPI, INTERNAL, loaderHelpers, Module, runtimeHelpers, createPromiseController, mono_assert, ENVIRONMENT_IS_WORKER } from "./globals"; import cwraps, { init_c_exports, threads_c_functions as tcwraps } from "./cwraps"; import { mono_wasm_raise_debug_event, mono_wasm_runtime_ready } from "./debug";