Skip to content

Commit

Permalink
[wasm] Disallow not useful configuration combinations (#104149)
Browse files Browse the repository at this point in the history
* Fix - aot doesn't support managed debugging

* Debug + aot on linux should not be tested in this test.
  • Loading branch information
ilonatommy committed Jul 4, 2024
1 parent dd6840d commit 2e585aa
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/mono/browser/runtime/cwraps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]],
Expand Down
3 changes: 2 additions & 1 deletion src/mono/wasi/Wasi.Build.Tests/WasiTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
27 changes: 22 additions & 5 deletions src/mono/wasm/Wasm.Build.Tests/Blazor/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ public async Task DefaultTemplate_WithoutWorkload(string config)
public static TheoryData<string, bool> TestDataForDefaultTemplate_WithWorkload(bool isAot)
{
var data = new TheoryData<string, bool>();
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;
Expand Down Expand Up @@ -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: "<RunAOTCompilation>true</RunAOTCompilation>");

(CommandResult res, _) = BlazorPublish(new BlazorBuildOptions(id, config, ExpectSuccess: false));
Assert.Contains("AOT is not supported in debug configuration", res.Output);
}
}
1 change: 0 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/Blazor/MiscTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/Blazor/SimpleRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 22 additions & 1 deletion src/mono/wasm/Wasm.Build.Tests/BuildPublishTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 6 additions & 7 deletions src/mono/wasm/Wasm.Build.Tests/Templates/WasmTemplateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()"
Expand All @@ -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
);
}
Expand Down Expand Up @@ -121,7 +121,7 @@ public void BrowserBuildThenPublish(string config)

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

AddItemsPropertiesToProject(projectFile,
AddItemsPropertiesToProject(projectFile,
atTheEnd:
"""
<Target Name="CheckLinkedFiles" AfterTargets="ILLink">
Expand Down Expand Up @@ -389,7 +389,6 @@ public static TheoryData<string, bool, bool> TestDataForConsolePublishAndRun()
// [ActiveIssue("https://github.com/dotnet/runtime/issues/71887", TestPlatforms.Windows)]
if (!OperatingSystem.IsWindows())
{
data.Add("Debug", true, false);
data.Add("Release", true, false);
}

Expand Down
4 changes: 3 additions & 1 deletion src/mono/wasm/build/WasmApp.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
<ItemGroup>
<UpToDateCheckInput Include="@(NativeFileReference)" />
</ItemGroup>

<PropertyGroup>
<_WasmDebuggerSupport Condition="'$(WasmDebugLevel)' != '' and '$(WasmDebugLevel)' != '0'">true</_WasmDebuggerSupport>
<_WasmDebuggerSupport Condition="'$(WasmDebugLevel)' != '' and '$(WasmDebugLevel)' == '0'">false</_WasmDebuggerSupport>
Expand Down Expand Up @@ -621,6 +621,8 @@

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

0 comments on commit 2e585aa

Please sign in to comment.