From 2e585aad5fb0a3c55a7e5f80af9e24f87fa9cfb4 Mon Sep 17 00:00:00 2001 From: Ilona Tomkowicz <32700855+ilonatommy@users.noreply.github.com> Date: Thu, 4 Jul 2024 09:36:13 +0000 Subject: [PATCH] [wasm] Disallow not useful configuration combinations (#104149) * Fix - aot doesn't support managed debugging * Debug + aot on linux should not be tested in this test. --- src/mono/browser/runtime/cwraps.ts | 2 +- .../Wasi.Build.Tests/WasiTemplateTests.cs | 3 ++- .../Blazor/BuildPublishTests.cs | 27 +++++++++++++++---- .../wasm/Wasm.Build.Tests/Blazor/MiscTests.cs | 1 - .../Wasm.Build.Tests/Blazor/SimpleRunTests.cs | 1 - .../Wasm.Build.Tests/BuildPublishTests.cs | 23 +++++++++++++++- .../Templates/WasmTemplateTests.cs | 13 +++++---- src/mono/wasm/build/WasmApp.Common.targets | 4 ++- 8 files changed, 56 insertions(+), 18 deletions(-) diff --git a/src/mono/browser/runtime/cwraps.ts b/src/mono/browser/runtime/cwraps.ts index 61ae0be40c768..794682b7e6c29 100644 --- a/src/mono/browser/runtime/cwraps.ts +++ b/src/mono/browser/runtime/cwraps.ts @@ -67,7 +67,7 @@ const fn_signatures: SigLine[] = [ [true, "mono_wasm_set_main_args", "void", ["number", "number"]], // These two need to be lazy because they may be missing [() => !runtimeHelpers.emscriptenBuildOptions.enableAotProfiler, "mono_wasm_profiler_init_aot", "void", ["string"]], - [() => !runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler, "mono_wasm_profiler_init_aot", "void", ["string"]], + [() => !runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler, "mono_wasm_profiler_init_browser", "void", ["string"]], [true, "mono_wasm_profiler_init_browser", "void", ["number"]], [false, "mono_wasm_exec_regression", "number", ["number", "string"]], [false, "mono_wasm_invoke_jsexport", "void", ["number", "number"]], diff --git a/src/mono/wasi/Wasi.Build.Tests/WasiTemplateTests.cs b/src/mono/wasi/Wasi.Build.Tests/WasiTemplateTests.cs index 82b8844c5cb6e..9b46e29d05fd4 100644 --- a/src/mono/wasi/Wasi.Build.Tests/WasiTemplateTests.cs +++ b/src/mono/wasi/Wasi.Build.Tests/WasiTemplateTests.cs @@ -96,7 +96,8 @@ public void ConsoleBuildThenRunThenPublish(string config, bool singleFileBundle, CreateProject: false, Publish: true, TargetFramework: BuildTestBase.DefaultTargetFramework, - UseCache: false)); + UseCache: false, + ExpectSuccess: !(config == "Debug" && aot))); } [Theory] diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs index fc22d03b303bc..9fe78d3df5072 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs @@ -42,17 +42,20 @@ public async Task DefaultTemplate_WithoutWorkload(string config) public static TheoryData TestDataForDefaultTemplate_WithWorkload(bool isAot) { var data = new TheoryData(); - data.Add("Debug", false); - data.Add("Release", false); // Release relinks by default - // [ActiveIssue("https://github.com/dotnet/runtime/issues/83497", TestPlatforms.Windows)] - if (!isAot || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!isAot) { - data.Add("Debug", true); // for aot:true on Windows, it fails + // AOT does not support managed debugging, is disabled by design + data.Add("Debug", false); } + data.Add("Release", false); // Release relinks by default // [ActiveIssue("https://github.com/dotnet/runtime/issues/83497", TestPlatforms.Windows)] if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { + if (!isAot) + { + data.Add("Debug", true); + } data.Add("Release", true); } return data; @@ -197,4 +200,18 @@ public async Task Test_WasmStripILAfterAOT(string stripILAfterAOT, bool expectIL WasmTemplateTests.TestWasmStripILAfterAOTOutput(objBuildDir, frameworkDir, expectILStripping, _testOutput); } + + [Theory] + [InlineData("Debug")] + public void BlazorWasm_CannotAOT_InDebug(string config) + { + string id = $"blazorwasm_{config}_aot_{GetRandomId()}"; + CreateBlazorWasmTemplateProject(id); + AddItemsPropertiesToProject(Path.Combine(_projectDir!, $"{id}.csproj"), + extraItems: null, + extraProperties: "true"); + + (CommandResult res, _) = BlazorPublish(new BlazorBuildOptions(id, config, ExpectSuccess: false)); + Assert.Contains("AOT is not supported in debug configuration", res.Output); + } } diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests.cs index e01a9f4f3e642..c93ec2c6af452 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests.cs @@ -53,7 +53,6 @@ public void NativeBuild_WithDeployOnBuild_UsedByVS(string config, bool nativeRel } [Theory] - [InlineData("Debug")] [InlineData("Release")] public void DefaultTemplate_AOT_InProjectFile(string config) { diff --git a/src/mono/wasm/Wasm.Build.Tests/Blazor/SimpleRunTests.cs b/src/mono/wasm/Wasm.Build.Tests/Blazor/SimpleRunTests.cs index fdce8ea756f84..433d77699c1c7 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Blazor/SimpleRunTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Blazor/SimpleRunTests.cs @@ -78,7 +78,6 @@ public async Task BlazorBuildAndRunForDifferentOutputPaths(string config, bool a [Theory] [InlineData("Debug", false)] - [InlineData("Debug", true)] [InlineData("Release", false)] [InlineData("Release", true)] public async Task BlazorPublishRunTest(string config, bool aot) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs b/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs index f287fa4574164..31807b6d54bb7 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs @@ -21,6 +21,28 @@ public BuildPublishTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur { } + [Theory] + [BuildAndRun(host: RunHost.Chrome, aot: true, config: "Debug")] + public void Wasm_CannotAOT_InDebug(BuildArgs buildArgs, RunHost _, string id) + { + string projectName = GetTestProjectPath(prefix: "no_aot_in_debug", config: buildArgs.Config); + buildArgs = buildArgs with { ProjectName = projectName }; + buildArgs = ExpandBuildArgs(buildArgs); + (string projectDir, string buildOutput) = BuildProject(buildArgs, + id: id, + new BuildProjectOptions( + InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_mainReturns42), + DotnetWasmFromRuntimePack: true, + CreateProject: true, + Publish: true, + ExpectSuccess: false + )); + + Console.WriteLine($"buildOutput={buildOutput}"); + + Assert.Contains("AOT is not supported in debug configuration", buildOutput); + } + [Theory] [BuildAndRun(host: RunHost.Chrome, aot: false, config: "Release")] [BuildAndRun(host: RunHost.Chrome, aot: false, config: "Debug")] @@ -71,7 +93,6 @@ void Run() => RunAndTestWasmApp( [Theory] [BuildAndRun(host: RunHost.Chrome, aot: true, config: "Release")] - [BuildAndRun(host: RunHost.Chrome, aot: true, config: "Debug")] public void BuildThenPublishWithAOT(BuildArgs buildArgs, RunHost host, string id) { bool testUnicode = true; diff --git a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs index ac20f6f784513..a17dc522988d2 100644 --- a/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs @@ -21,7 +21,7 @@ public WasmTemplateTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur { } - private string StringReplaceWithAssert(string oldContent, string oldValue, string newValue) + private string StringReplaceWithAssert(string oldContent, string oldValue, string newValue) { string newContent = oldContent.Replace(oldValue, newValue); if (oldValue != newValue && oldContent == newContent) @@ -57,11 +57,11 @@ private void UpdateConsoleProgramCs() private void UpdateBrowserMainJs(string targetFramework, string runtimeAssetsRelativePath = DefaultRuntimeAssetsRelativePath) { base.UpdateBrowserMainJs( - (mainJsContent) => + (mainJsContent) => { // .withExitOnUnhandledError() is available only only >net7.0 mainJsContent = StringReplaceWithAssert( - mainJsContent, + mainJsContent, ".create()", (targetFramework == "net8.0" || targetFramework == "net9.0") ? ".withConsoleForwarding().withElementOnExit().withExitCodeLogging().withExitOnUnhandledError().create()" @@ -75,8 +75,8 @@ private void UpdateBrowserMainJs(string targetFramework, string runtimeAssetsRel mainJsContent = StringReplaceWithAssert(mainJsContent, "from './_framework/dotnet.js'", $"from '{runtimeAssetsRelativePath}dotnet.js'"); return mainJsContent; - }, - targetFramework, + }, + targetFramework, runtimeAssetsRelativePath ); } @@ -121,7 +121,7 @@ public void BrowserBuildThenPublish(string config) var buildArgs = new BuildArgs(projectName, config, false, id, null); - AddItemsPropertiesToProject(projectFile, + AddItemsPropertiesToProject(projectFile, atTheEnd: """ @@ -389,7 +389,6 @@ public static TheoryData TestDataForConsolePublishAndRun() // [ActiveIssue("https://github.com/dotnet/runtime/issues/71887", TestPlatforms.Windows)] if (!OperatingSystem.IsWindows()) { - data.Add("Debug", true, false); data.Add("Release", true, false); } diff --git a/src/mono/wasm/build/WasmApp.Common.targets b/src/mono/wasm/build/WasmApp.Common.targets index 6aafca7d110a2..beccccae461df 100644 --- a/src/mono/wasm/build/WasmApp.Common.targets +++ b/src/mono/wasm/build/WasmApp.Common.targets @@ -247,7 +247,7 @@ - + <_WasmDebuggerSupport Condition="'$(WasmDebugLevel)' != '' and '$(WasmDebugLevel)' != '0'">true <_WasmDebuggerSupport Condition="'$(WasmDebugLevel)' != '' and '$(WasmDebugLevel)' == '0'">false @@ -621,6 +621,8 @@ +