Skip to content

Commit 2e585aa

Browse files
authored
[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.
1 parent dd6840d commit 2e585aa

File tree

8 files changed

+56
-18
lines changed

8 files changed

+56
-18
lines changed

src/mono/browser/runtime/cwraps.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const fn_signatures: SigLine[] = [
6767
[true, "mono_wasm_set_main_args", "void", ["number", "number"]],
6868
// These two need to be lazy because they may be missing
6969
[() => !runtimeHelpers.emscriptenBuildOptions.enableAotProfiler, "mono_wasm_profiler_init_aot", "void", ["string"]],
70-
[() => !runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler, "mono_wasm_profiler_init_aot", "void", ["string"]],
70+
[() => !runtimeHelpers.emscriptenBuildOptions.enableBrowserProfiler, "mono_wasm_profiler_init_browser", "void", ["string"]],
7171
[true, "mono_wasm_profiler_init_browser", "void", ["number"]],
7272
[false, "mono_wasm_exec_regression", "number", ["number", "string"]],
7373
[false, "mono_wasm_invoke_jsexport", "void", ["number", "number"]],

src/mono/wasi/Wasi.Build.Tests/WasiTemplateTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public void ConsoleBuildThenRunThenPublish(string config, bool singleFileBundle,
9696
CreateProject: false,
9797
Publish: true,
9898
TargetFramework: BuildTestBase.DefaultTargetFramework,
99-
UseCache: false));
99+
UseCache: false,
100+
ExpectSuccess: !(config == "Debug" && aot)));
100101
}
101102

102103
[Theory]

src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,20 @@ public async Task DefaultTemplate_WithoutWorkload(string config)
4242
public static TheoryData<string, bool> TestDataForDefaultTemplate_WithWorkload(bool isAot)
4343
{
4444
var data = new TheoryData<string, bool>();
45-
data.Add("Debug", false);
46-
data.Add("Release", false); // Release relinks by default
47-
// [ActiveIssue("https://github.com/dotnet/runtime/issues/83497", TestPlatforms.Windows)]
48-
if (!isAot || !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
45+
if (!isAot)
4946
{
50-
data.Add("Debug", true); // for aot:true on Windows, it fails
47+
// AOT does not support managed debugging, is disabled by design
48+
data.Add("Debug", false);
5149
}
50+
data.Add("Release", false); // Release relinks by default
5251

5352
// [ActiveIssue("https://github.com/dotnet/runtime/issues/83497", TestPlatforms.Windows)]
5453
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
5554
{
55+
if (!isAot)
56+
{
57+
data.Add("Debug", true);
58+
}
5659
data.Add("Release", true);
5760
}
5861
return data;
@@ -197,4 +200,18 @@ public async Task Test_WasmStripILAfterAOT(string stripILAfterAOT, bool expectIL
197200

198201
WasmTemplateTests.TestWasmStripILAfterAOTOutput(objBuildDir, frameworkDir, expectILStripping, _testOutput);
199202
}
203+
204+
[Theory]
205+
[InlineData("Debug")]
206+
public void BlazorWasm_CannotAOT_InDebug(string config)
207+
{
208+
string id = $"blazorwasm_{config}_aot_{GetRandomId()}";
209+
CreateBlazorWasmTemplateProject(id);
210+
AddItemsPropertiesToProject(Path.Combine(_projectDir!, $"{id}.csproj"),
211+
extraItems: null,
212+
extraProperties: "<RunAOTCompilation>true</RunAOTCompilation>");
213+
214+
(CommandResult res, _) = BlazorPublish(new BlazorBuildOptions(id, config, ExpectSuccess: false));
215+
Assert.Contains("AOT is not supported in debug configuration", res.Output);
216+
}
200217
}

src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ public void NativeBuild_WithDeployOnBuild_UsedByVS(string config, bool nativeRel
5353
}
5454

5555
[Theory]
56-
[InlineData("Debug")]
5756
[InlineData("Release")]
5857
public void DefaultTemplate_AOT_InProjectFile(string config)
5958
{

src/mono/wasm/Wasm.Build.Tests/Blazor/SimpleRunTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ public async Task BlazorBuildAndRunForDifferentOutputPaths(string config, bool a
7878

7979
[Theory]
8080
[InlineData("Debug", false)]
81-
[InlineData("Debug", true)]
8281
[InlineData("Release", false)]
8382
[InlineData("Release", true)]
8483
public async Task BlazorPublishRunTest(string config, bool aot)

src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@ public BuildPublishTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur
2121
{
2222
}
2323

24+
[Theory]
25+
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Debug")]
26+
public void Wasm_CannotAOT_InDebug(BuildArgs buildArgs, RunHost _, string id)
27+
{
28+
string projectName = GetTestProjectPath(prefix: "no_aot_in_debug", config: buildArgs.Config);
29+
buildArgs = buildArgs with { ProjectName = projectName };
30+
buildArgs = ExpandBuildArgs(buildArgs);
31+
(string projectDir, string buildOutput) = BuildProject(buildArgs,
32+
id: id,
33+
new BuildProjectOptions(
34+
InitProject: () => File.WriteAllText(Path.Combine(_projectDir!, "Program.cs"), s_mainReturns42),
35+
DotnetWasmFromRuntimePack: true,
36+
CreateProject: true,
37+
Publish: true,
38+
ExpectSuccess: false
39+
));
40+
41+
Console.WriteLine($"buildOutput={buildOutput}");
42+
43+
Assert.Contains("AOT is not supported in debug configuration", buildOutput);
44+
}
45+
2446
[Theory]
2547
[BuildAndRun(host: RunHost.Chrome, aot: false, config: "Release")]
2648
[BuildAndRun(host: RunHost.Chrome, aot: false, config: "Debug")]
@@ -71,7 +93,6 @@ void Run() => RunAndTestWasmApp(
7193

7294
[Theory]
7395
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Release")]
74-
[BuildAndRun(host: RunHost.Chrome, aot: true, config: "Debug")]
7596
public void BuildThenPublishWithAOT(BuildArgs buildArgs, RunHost host, string id)
7697
{
7798
bool testUnicode = true;

src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public WasmTemplateTests(ITestOutputHelper output, SharedBuildPerTestClassFixtur
2121
{
2222
}
2323

24-
private string StringReplaceWithAssert(string oldContent, string oldValue, string newValue)
24+
private string StringReplaceWithAssert(string oldContent, string oldValue, string newValue)
2525
{
2626
string newContent = oldContent.Replace(oldValue, newValue);
2727
if (oldValue != newValue && oldContent == newContent)
@@ -57,11 +57,11 @@ private void UpdateConsoleProgramCs()
5757
private void UpdateBrowserMainJs(string targetFramework, string runtimeAssetsRelativePath = DefaultRuntimeAssetsRelativePath)
5858
{
5959
base.UpdateBrowserMainJs(
60-
(mainJsContent) =>
60+
(mainJsContent) =>
6161
{
6262
// .withExitOnUnhandledError() is available only only >net7.0
6363
mainJsContent = StringReplaceWithAssert(
64-
mainJsContent,
64+
mainJsContent,
6565
".create()",
6666
(targetFramework == "net8.0" || targetFramework == "net9.0")
6767
? ".withConsoleForwarding().withElementOnExit().withExitCodeLogging().withExitOnUnhandledError().create()"
@@ -75,8 +75,8 @@ private void UpdateBrowserMainJs(string targetFramework, string runtimeAssetsRel
7575
mainJsContent = StringReplaceWithAssert(mainJsContent, "from './_framework/dotnet.js'", $"from '{runtimeAssetsRelativePath}dotnet.js'");
7676

7777
return mainJsContent;
78-
},
79-
targetFramework,
78+
},
79+
targetFramework,
8080
runtimeAssetsRelativePath
8181
);
8282
}
@@ -121,7 +121,7 @@ public void BrowserBuildThenPublish(string config)
121121

122122
var buildArgs = new BuildArgs(projectName, config, false, id, null);
123123

124-
AddItemsPropertiesToProject(projectFile,
124+
AddItemsPropertiesToProject(projectFile,
125125
atTheEnd:
126126
"""
127127
<Target Name="CheckLinkedFiles" AfterTargets="ILLink">
@@ -389,7 +389,6 @@ public static TheoryData<string, bool, bool> TestDataForConsolePublishAndRun()
389389
// [ActiveIssue("https://github.com/dotnet/runtime/issues/71887", TestPlatforms.Windows)]
390390
if (!OperatingSystem.IsWindows())
391391
{
392-
data.Add("Debug", true, false);
393392
data.Add("Release", true, false);
394393
}
395394

src/mono/wasm/build/WasmApp.Common.targets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@
247247
<ItemGroup>
248248
<UpToDateCheckInput Include="@(NativeFileReference)" />
249249
</ItemGroup>
250-
250+
251251
<PropertyGroup>
252252
<_WasmDebuggerSupport Condition="'$(WasmDebugLevel)' != '' and '$(WasmDebugLevel)' != '0'">true</_WasmDebuggerSupport>
253253
<_WasmDebuggerSupport Condition="'$(WasmDebugLevel)' != '' and '$(WasmDebugLevel)' == '0'">false</_WasmDebuggerSupport>
@@ -621,6 +621,8 @@
621621

622622
<Error Condition="'$(RunAOTCompilation)' == 'true' and '$(PublishTrimmed)' != 'true'"
623623
Text="AOT is not supported without IL trimming (PublishTrimmed=true required)." />
624+
<Error Condition="'$(RunAOTCompilation)' == 'true' and '$(Configuration)' == 'Debug'"
625+
Text="AOT is not supported in debug configuration (Configuration=Release required)." />
624626
<Error Condition="'@(_WasmAssembliesInternal)' == ''" Text="Item _WasmAssembliesInternal is empty" />
625627
<Error Condition="'$(_IsToolchainMissing)' == 'true'"
626628
Text="$(_ToolchainMissingErrorMessage) SDK is required for AOT'ing assemblies." />

0 commit comments

Comments
 (0)