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/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/lazyLoading.ts b/src/mono/browser/runtime/lazyLoading.ts index 55bcfd67101e8c..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 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 (BuildConfiguration === "Debug" && config.diagnosticTracing === undefined) { config.diagnosticTracing = true; } @@ -264,14 +257,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 1b77c5510c3c54..6c54e219ca60b3 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_log_error, set_thread_prefix, setup_proxy_console } from "./logging"; import { invokeLibraryInitializers } from "./libraryInitializers"; -import { deep_merge_config, hasDebuggingEnabled } from "./config"; +import { deep_merge_config, isDebuggingSupported } 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,9 +118,9 @@ export function setLoaderGlobals( purgeUnusedCacheEntriesAsync, installUnhandledErrorHandler, - hasDebuggingEnabled, retrieve_asset_download, invokeLibraryInitializers, + isDebuggingSupported, // from wasm-feature-detect npm package exceptions, diff --git a/src/mono/browser/runtime/startup.ts b/src/mono/browser/runtime/startup.ts index 24ad5786e6afbd..a1f6b95dd1814b 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("unused", runtimeHelpers.config.debugLevel); + mono_wasm_load_runtime(); if (runtimeHelpers.config.interpreterPgo) setTimeout(maybeSaveInterpPgoTable, (runtimeHelpers.config.interpreterPgoSaveDelay || 15) * 1000); @@ -534,17 +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(): void { mono_log_debug("mono_wasm_load_runtime"); try { const mark = startMeasure(); + let debugLevel = runtimeHelpers.config.debugLevel; if (debugLevel == undefined) { debugLevel = 0; if (runtimeHelpers.config.debugLevel) { debugLevel = 0 + debugLevel; } } - cwraps.mono_wasm_load_runtime(unused || "unused", debugLevel); + if (!loaderHelpers.isDebuggingSupported() || !runtimeHelpers.config.resources!.pdb) { + debugLevel = 0; + } + cwraps.mono_wasm_load_runtime(debugLevel); endMeasure(mark, MeasuredBlock.loadRuntime); } catch (err: any) { diff --git a/src/mono/browser/runtime/types/internal.ts b/src/mono/browser/runtime/types/internal.ts index 9b5af8831e43cf..a9f2f9aadcbfab 100644 --- a/src/mono/browser/runtime/types/internal.ts +++ b/src/mono/browser/runtime/types/internal.ts @@ -155,7 +155,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; @@ -166,6 +165,7 @@ export type LoaderHelpers = { invokeLibraryInitializers: (functionName: string, args: any[]) => Promise, libraryInitializers?: { scriptName: string, exports: any }[]; + isDebuggingSupported(): boolean, isChromium: boolean, isFirefox: boolean 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..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 @@ -203,9 +203,6 @@ Copyright (c) .NET Foundation. All rights reserved. <_BlazorWebAssemblyStartupMemoryCache>$(BlazorWebAssemblyStartupMemoryCache) <_BlazorWebAssemblyJiterpreter>$(BlazorWebAssemblyJiterpreter) <_BlazorWebAssemblyRuntimeOptions>$(BlazorWebAssemblyRuntimeOptions) - <_WasmDebugLevel>$(WasmDebugLevel) - <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == ''">0 - <_WasmDebugLevel Condition="'$(_WasmDebugLevel)' == '0' and ('$(DebuggerSupport)' == 'true' or '$(Configuration)' == 'Debug')">-1 $(OutputPath)$(PublishDirName)\ @@ -364,7 +361,7 @@ Copyright (c) .NET Foundation. All rights reserved. AssemblyPath="@(IntermediateAssembly)" Resources="@(_WasmOutputWithHash)" DebugBuild="true" - DebugLevel="$(_WasmDebugLevel)" + DebugLevel="$(WasmDebugLevel)" LinkerEnabled="false" CacheBootResources="$(BlazorCacheBootResources)" OutputPath="$(_WasmBuildBootJsonPath)" @@ -380,7 +377,8 @@ Copyright (c) .NET Foundation. All rights reserved. Extensions="@(WasmBootConfigExtension)" TargetFrameworkVersion="$(TargetFrameworkVersion)" ModuleAfterConfigLoaded="@(WasmModuleAfterConfigLoaded)" - ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" /> + ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" + IsPublish="false" /> @@ -533,7 +531,6 @@ Copyright (c) .NET Foundation. All rights reserved. - <_WasmPublishAsset Include="@(StaticWebAsset)" @@ -549,7 +546,6 @@ Copyright (c) .NET Foundation. All rights reserved. <_WasmPublishAsset Remove="@(_BlazorExtensionsCandidatesForPublish)" /> - + ModuleAfterRuntimeReady="@(WasmModuleAfterRuntimeReady)" + IsPublish="true" /> diff --git a/src/mono/wasi/build/WasiApp.targets b/src/mono/wasi/build/WasiApp.targets index e54fbe4f89ac1a..b31c573ea349b5 100644 --- a/src/mono/wasi/build/WasiApp.targets +++ b/src/mono/wasi/build/WasiApp.targets @@ -66,6 +66,11 @@ Outputs="$(WasmAppDir)\.stamp" Condition="'$(WasmGenerateAppBundle)' == 'true'"> + + <_WasmOutputSymbolsToAppBundle Condition="'$(CopyOutputSymbolsToPublishDirectory)' == 'true' and '$(_IsPublishing)' == 'true'">true + <_WasmOutputSymbolsToAppBundle Condition="'$(_WasmOutputSymbolsToAppBundle)' == ''">false + + diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs index a5d01c2d883865..2e3491374c7d91 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BlazorWasmTestBase.cs @@ -63,7 +63,9 @@ 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) + { AssertBundle(res.Output, options with { IsPublish = false }); + } return (res, logPath); } @@ -77,6 +79,10 @@ public string CreateBlazorWasmTemplateProject(string id) if (options.ExpectSuccess && options.AssertAppBundle) { + // Because we do relink in Release publish by default + if (options.Config == "Release") + options = options with { ExpectedFileType = NativeFilesType.Relinked }; + AssertBundle(res.Output, options with { IsPublish = true }); } diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/InterpPgoTests.cs index 203ad80fc4dc77..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();" diff --git a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppSettingsTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppSettingsTests.cs index 96f2c4ebd6a1bf..5d028cc238909a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppSettingsTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/AppSettingsTests.cs @@ -28,7 +28,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..771daff1f5d469 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) @@ -67,9 +73,10 @@ protected async Task RunSdkStyleApp(RunOptions options) CheckCounter: false, Config: options.Configuration, OnConsoleMessage: OnConsoleMessage, - QueryString: queryString); + QueryString: queryString, + Host: host); - await BlazorRunForBuildWithDotnetRun(blazorRunOptions); + await BlazorRunTest(blazorRunOptions); void OnConsoleMessage(IConsoleMessage msg) { 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..3dfe4c467f79f7 --- /dev/null +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DebugLevelTests.cs @@ -0,0 +1,109 @@ +// 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) + { + } + + private void AssertDebugLevel(RunResult result, int value) + { + Assert.Collection( + result.TestOutput, + m => Assert.Equal($"WasmDebugLevel: {value}", m) + ); + } + + [Theory] + [InlineData("Debug")] + [InlineData("Release")] + public async Task BuildWithDefaultLevel(string configuration) + { + CopyTestAsset("WasmBasicTestApp", $"DebugLevelTests_BuildWithDefaultLevel_{configuration}"); + BuildProject(configuration); + + var result = await RunSdkStyleAppForBuild(new( + Configuration: configuration, + TestScenario: "DebugLevelTest" + )); + 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_{configuration}"); + 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_{configuration}"); + 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_{configuration}"); + PublishProject(configuration, $"-p:WasmDebugLevel={debugLevel}"); + + var result = await RunSdkStyleAppForPublish(new( + Configuration: configuration, + TestScenario: "DebugLevelTest" + )); + AssertDebugLevel(result, debugLevel); + } + + [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/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs index 70f9b4f1507d28..7cc55ebd07ae20 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/DownloadResourceProgressTests.cs @@ -28,7 +28,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 8f37a47e18860a..cf16a0536a38da 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LazyLoadingTests.cs @@ -26,7 +26,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"); } @@ -36,7 +36,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 6f68a96ad1d61a..e985ad23d89a0b 100644 --- a/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LibraryInitializerTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/TestAppScenarios/LibraryInitializerTests.cs @@ -29,7 +29,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) @@ -42,7 +42,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 31dcb65582869e..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 RunSdkStyleApp(new(Configuration: "Debug", TestScenario: "SatelliteAssembliesTest")); + var result = await RunSdkStyleAppForBuild(new(Configuration: "Debug", TestScenario: "SatelliteAssembliesTest")); Assert.Collection( result.TestOutput, m => Assert.Equal("default: hello", m), 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"; diff --git a/src/mono/wasm/build/WasmApp.Common.targets b/src/mono/wasm/build/WasmApp.Common.targets index 3f3a97fff9b3fd..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/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js b/src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js index 076f37a62a6d87..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; @@ -94,6 +96,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); 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 ef42b6fa952f10..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); @@ -101,7 +103,6 @@ public void WriteBootJson(Stream output, string entryAssemblyName) if (IsTargeting80OrLater()) { - result.debugLevel = ParseOptionalInt(DebugLevel) ?? (DebugBuild ? 1 : 0); result.mainAssemblyName = entryAssemblyName; result.globalizationMode = GetGlobalizationMode().ToString().ToLowerInvariant(); @@ -329,6 +330,20 @@ 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. + 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) { foreach (var configFile in ConfigurationFiles) 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))