From 570b3f8720f889c30978e58570433b33f62591a0 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Sat, 24 Sep 2022 12:57:32 +0000 Subject: [PATCH 01/11] [wasm] Update templates to work for multiple versions --- .../browser/.template.config/template.json | 23 ++++++++++++++++--- .../console/.template.config/template.json | 21 ++++++++++++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/mono/wasm/templates/templates/browser/.template.config/template.json b/src/mono/wasm/templates/templates/browser/.template.config/template.json index 5fa2bac372a72f..902e5d4622b954 100644 --- a/src/mono/wasm/templates/templates/browser/.template.config/template.json +++ b/src/mono/wasm/templates/templates/browser/.template.config/template.json @@ -3,7 +3,10 @@ "author": "Microsoft", "classifications": [ "Web", "WebAssembly", "Browser" ], "generatorVersions": "[1.0.0.0-*)", - "identity": "WebAssembly.Browser", + "groupIdentity": "WebAssembly.Browser", + "precedence": 8000, + "identity": "WebAssembly.Browser.8.0", + "description": "WebAssembly Browser App", "name": "WebAssembly Browser App", "shortName": "wasmbrowser", "sourceName": "browser.0", @@ -20,7 +23,7 @@ "low": 5000, "high": 5300 }, - "replaces": "5000" + "replaces": "5000" }, "kestrelHttpsPortGenerated": { "type": "generated", @@ -29,7 +32,21 @@ "low": 7000, "high": 7300 }, - "replaces": "5001" + "replaces": "5001" + }, + "framework": { + "type": "parameter", + "description": "The target framework for the project.", + "datatype": "choice", + "choices": [ + { + "choice": "net8.0", + "description": "Target net8.0", + "displayName": ".NET 8.0" + } + ], + "defaultValue": "net8.0", + "displayName": "framework" } } } diff --git a/src/mono/wasm/templates/templates/console/.template.config/template.json b/src/mono/wasm/templates/templates/console/.template.config/template.json index 8ead39edc0f8c2..d2a453e1272211 100644 --- a/src/mono/wasm/templates/templates/console/.template.config/template.json +++ b/src/mono/wasm/templates/templates/console/.template.config/template.json @@ -2,7 +2,10 @@ "$schema": "http://json.schemastore.org/template", "author": "Microsoft", "classifications": [ "Web", "WebAssembly", "Console" ], - "identity": "WebAssembly.Console", + "groupIdentity": "WebAssembly.Console", + "precedence": 8000, + "identity": "WebAssembly.Console.8.0", + "description": "WebAssembly Console App", "name": "WebAssembly Console App", "shortName": "wasmconsole", "sourceName": "console.0", @@ -10,5 +13,21 @@ "tags": { "language": "C#", "type": "project" + }, + "symbols": { + "framework": { + "type": "parameter", + "description": "The target framework for the project.", + "datatype": "choice", + "choices": [ + { + "choice": "net8.0", + "description": "Target net8.0", + "displayName": ".NET 8.0" + } + ], + "defaultValue": "net8.0", + "displayName": "framework" + } } } From 298c107d5c456046abb42d12de04d7026639aa29 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Sat, 24 Sep 2022 14:37:02 +0000 Subject: [PATCH 02/11] [wasm] Add tests for templates creating with specific tfm --- .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 4 ++-- .../Wasm.Build.Tests/WasmTemplateTests.cs | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index e34917b222624f..91f9ef79ebb163 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -444,7 +444,7 @@ private static string GetNuGetConfigWithLocalPackagesPath(string templatePath, s return contents.Replace(s_nugetInsertionTag, $@""); } - public string CreateWasmTemplateProject(string id, string template = "wasmbrowser") + public string CreateWasmTemplateProject(string id, string template = "wasmbrowser", string extraArgs = "") { InitPaths(id); InitProjectDir(id); @@ -464,7 +464,7 @@ public string CreateWasmTemplateProject(string id, string template = "wasmbrowse new DotNetCommand(s_buildEnv, _testOutput, useDefaultArgs: false) .WithWorkingDirectory(_projectDir!) - .ExecuteWithCapturedOutput($"new {template}") + .ExecuteWithCapturedOutput($"new {template} {extraArgs}") .EnsureSuccessful(); return Path.Combine(_projectDir!, $"{id}.csproj"); diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index e96ed8b797e8c5..5855edff855b4a 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -185,10 +185,19 @@ public void ConsoleBuildThenPublish(string config) [InlineData("Debug", true)] [InlineData("Release", false)] [InlineData("Release", true)] - public void ConsoleBuildAndRun(string config, bool relinking) + public void ConsoleBuildAndRunDefault(string config, bool relinking) + => ConsoleBuildAndRun(config, relinking, string.Empty); + + [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] + // [InlineData("Debug", "-f net7.0")] FIXME: -- enable when updated template packages are available + [InlineData("Debug", "-f net8.0")] + public void ConsoleBuildAndRunForSpecificTFM(string config, string extraNewArgs) + => ConsoleBuildAndRun(config, false, extraNewArgs); + + private void ConsoleBuildAndRun(string config, bool relinking, string extraNewArgs) { string id = $"{config}_{Path.GetRandomFileName()}"; - string projectFile = CreateWasmTemplateProject(id, "wasmconsole"); + string projectFile = CreateWasmTemplateProject(id, "wasmconsole", extraNewArgs); string projectName = Path.GetFileNameWithoutExtension(projectFile); UpdateProgramCS(); @@ -432,12 +441,15 @@ public async Task BlazorRunTest() Assert.Equal("Current count: 1", txt); } - [ConditionalFact(typeof(BuildTestBase), nameof(IsUsingWorkloads))] - public async Task BrowserTest() + [ConditionalTheory(typeof(BuildTestBase), nameof(IsUsingWorkloads))] + [InlineData("")] + // [InlineData("-f net7.0")] FIXME: -- enable when updated template packages are available + [InlineData("-f net8.0")] + public async Task BrowserBuildAndRun(string extraNewArgs) { string config = "Debug"; string id = $"browser_{config}_{Path.GetRandomFileName()}"; - CreateWasmTemplateProject(id, "wasmbrowser"); + CreateWasmTemplateProject(id, "wasmbrowser", extraNewArgs); UpdateBrowserMainJs(DefaultTargetFramework); From 0af1380cacb1f95c725dd829bf163be6573b9cd0 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Sat, 24 Sep 2022 14:57:49 +0000 Subject: [PATCH 03/11] [wasm] Workaround for net7 workload manifest using 8.0 packages Use 7.0 package version for net7 templates, so it can differentiate from net8 ones. --- eng/Versions.props | 1 + ...crosoft.NET.Workload.Mono.Toolchain.net7.Manifest.pkgproj | 5 +++++ .../WorkloadManifest.json.in | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/eng/Versions.props b/eng/Versions.props index cbccaa36829570..83743bc41b2df6 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -9,6 +9,7 @@ 8.0.100 6.0.10 + 7.0.0-rc.2.22458.4 alpha 1 + <_WorkloadManifestValues Include="PackageVersionForTemplates7" Value="$(PackageVersionForTemplates7)" Condition="'$(PackageVersionNet7)' == ''" /> + <_WorkloadManifestValues Include="PackageVersionForTemplates7" Value="$(PackageVersionNet7)" Condition="'$(PackageVersionNet7)' != ''" /> + <_WorkloadManifestValues Include="EmscriptenVersion" Value="$(MicrosoftNETRuntimeEmscriptenVersion)" /> <_WorkloadManifestValues Include="NetCoreAppCurrent" Value="$(NetCoreAppCurrent)" /> diff --git a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest/WorkloadManifest.json.in b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest/WorkloadManifest.json.in index de062e613b417c..6ce2373bc0c988 100644 --- a/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest/WorkloadManifest.json.in +++ b/src/mono/nuget/Microsoft.NET.Workload.Mono.Toolchain.net7.Manifest/WorkloadManifest.json.in @@ -170,7 +170,7 @@ }, "Microsoft.NET.Runtime.WebAssembly.Templates.net7": { "kind": "template", - "version": "${PackageVersionNet7}", + "version": "${PackageVersionForTemplates7}", "alias-to": { "any": "Microsoft.NET.Runtime.WebAssembly.Templates" } From 9140c37cc0569aac2df3208365ab11040d315f39 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 27 Sep 2022 05:28:53 +0000 Subject: [PATCH 04/11] [wasm] WBT: include browser launch logs in test output --- .../wasm/Wasm.Build.Tests/BrowserRunner.cs | 10 +++++++--- .../wasm/Wasm.Build.Tests/BuildTestBase.cs | 18 +++++++++++++++--- .../wasm/Wasm.Build.Tests/WasmTemplateTests.cs | 8 ++++---- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs b/src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs index 13a4ff96ab761a..718e7f90a843df 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Microsoft.Playwright; using Wasm.Tests.Internal; +using Xunit.Abstractions; namespace Wasm.Build.Tests; @@ -29,6 +30,9 @@ internal class BrowserRunner : IAsyncDisposable public Task? RunTask { get; private set; } public IList OutputLines { get; private set; } = new List(); private TaskCompletionSource _exited = new(); + private readonly ITestOutputHelper _testOutput; + + public BrowserRunner(ITestOutputHelper testOutput) => _testOutput = testOutput; // FIXME: options public async Task RunAsync(ToolCommand cmd, string args, bool headless = true) @@ -78,7 +82,7 @@ public async Task RunAsync(ToolCommand cmd, string args, bool headless = var url = new Uri(urlAvailable.Task.Result); Playwright = await Microsoft.Playwright.Playwright.CreateAsync(); string[] chromeArgs = new[] { $"--explicitly-allowed-ports={url.Port}" }; - Console.WriteLine($"Launching chrome ('{s_chromePath.Value}') via playwright with args = {string.Join(',', chromeArgs)}"); + _testOutput.WriteLine($"Launching chrome ('{s_chromePath.Value}') via playwright with args = {string.Join(',', chromeArgs)}"); Browser = await Playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions{ ExecutablePath = s_chromePath.Value, Headless = headless, @@ -99,7 +103,7 @@ public async Task WaitForExitMessageAsync(TimeSpan timeout) await Task.WhenAny(RunTask!, _exited.Task, Task.Delay(timeout)); if (_exited.Task.IsCompleted) { - Console.WriteLine ($"Exited with {await _exited.Task}"); + _testOutput.WriteLine ($"Exited with {await _exited.Task}"); return; } @@ -114,7 +118,7 @@ public async Task WaitForProcessExitAsync(TimeSpan timeout) await Task.WhenAny(RunTask!, _exited.Task, Task.Delay(timeout)); if (RunTask.IsCanceled) { - Console.WriteLine ($"Exited with {(await RunTask).ExitCode}"); + _testOutput.WriteLine ($"Exited with {(await RunTask).ExitCode}"); return; } diff --git a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs index 91f9ef79ebb163..f4a73bdbb0fe5b 100644 --- a/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs +++ b/src/mono/wasm/Wasm.Build.Tests/BuildTestBase.cs @@ -290,13 +290,25 @@ protected void InitPaths(string id) Directory.CreateDirectory(_logPath); } - protected static void InitProjectDir(string dir) + protected static void InitProjectDir(string dir, bool addNuGetSourceForLocalPackages = false) { Directory.CreateDirectory(dir); File.WriteAllText(Path.Combine(dir, "Directory.Build.props"), s_buildEnv.DirectoryBuildPropsContents); File.WriteAllText(Path.Combine(dir, "Directory.Build.targets"), s_buildEnv.DirectoryBuildTargetsContents); - File.Copy(Path.Combine(BuildEnvironment.TestDataPath, NuGetConfigFileNameForDefaultFramework), Path.Combine(dir, "nuget.config")); + string targetNuGetConfigPath = Path.Combine(dir, "nuget.config"); + if (addNuGetSourceForLocalPackages) + { + File.WriteAllText(targetNuGetConfigPath, + GetNuGetConfigWithLocalPackagesPath( + Path.Combine(BuildEnvironment.TestDataPath, NuGetConfigFileNameForDefaultFramework), + s_buildEnv.BuiltNuGetsPath)); + } + else + { + File.Copy(Path.Combine(BuildEnvironment.TestDataPath, NuGetConfigFileNameForDefaultFramework), + targetNuGetConfigPath); + } Directory.CreateDirectory(Path.Combine(dir, ".nuget")); } @@ -447,7 +459,7 @@ private static string GetNuGetConfigWithLocalPackagesPath(string templatePath, s public string CreateWasmTemplateProject(string id, string template = "wasmbrowser", string extraArgs = "") { InitPaths(id); - InitProjectDir(id); + InitProjectDir(id, addNuGetSourceForLocalPackages: true); File.WriteAllText(Path.Combine(_projectDir, "Directory.Build.props"), ""); File.WriteAllText(Path.Combine(_projectDir, "Directory.Build.targets"), diff --git a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs index 5855edff855b4a..d49d1d01c5c0d6 100644 --- a/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs +++ b/src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs @@ -274,7 +274,7 @@ private async Task BrowserRunTwiceWithAndThenWithoutBuildAsync(string config, st using var runCommand = new RunCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(workingDir); - await using var runner = new BrowserRunner(); + await using var runner = new BrowserRunner(_testOutput); var page = await runner.RunAsync(runCommand, $"run -c {config} --project {projectFile} --forward-console"); await runner.WaitForExitMessageAsync(TimeSpan.FromMinutes(2)); Assert.Contains("Hello, Browser!", string.Join(Environment.NewLine, runner.OutputLines)); @@ -284,7 +284,7 @@ private async Task BrowserRunTwiceWithAndThenWithoutBuildAsync(string config, st using var runCommand = new RunCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(workingDir); - await using var runner = new BrowserRunner(); + await using var runner = new BrowserRunner(_testOutput); var page = await runner.RunAsync(runCommand, $"run -c {config} --no-build --project {projectFile} --forward-console"); await runner.WaitForExitMessageAsync(TimeSpan.FromMinutes(2)); Assert.Contains("Hello, Browser!", string.Join(Environment.NewLine, runner.OutputLines)); @@ -429,7 +429,7 @@ public async Task BlazorRunTest() using var runCommand = new RunCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!); - await using var runner = new BrowserRunner(); + await using var runner = new BrowserRunner(_testOutput); var page = await runner.RunAsync(runCommand, $"run -c {config} --no-build"); await page.Locator("text=Counter").ClickAsync(); @@ -461,7 +461,7 @@ public async Task BrowserBuildAndRun(string extraNewArgs) using var runCommand = new RunCommand(s_buildEnv, _testOutput) .WithWorkingDirectory(_projectDir!); - await using var runner = new BrowserRunner(); + await using var runner = new BrowserRunner(_testOutput); var page = await runner.RunAsync(runCommand, $"run -c {config} --no-build -r browser-wasm --forward-console"); await runner.WaitForExitMessageAsync(TimeSpan.FromMinutes(2)); Assert.Contains("Hello, Browser!", string.Join(Environment.NewLine, runner.OutputLines)); From ffc409215aa94e235e2baae43ef016afff12cff2 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Tue, 27 Sep 2022 05:31:21 +0000 Subject: [PATCH 05/11] [wasm] Update net7.0 templates to 7.0.0-rtm.22476.8, and enable the corresponding tests --- eng/Versions.props | 2 +- src/mono/wasm/Wasm.Build.Tests/WasmTemplateTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/eng/Versions.props b/eng/Versions.props index 83743bc41b2df6..c156052dd09503 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -9,7 +9,7 @@ 8.0.100 6.0.10 - 7.0.0-rc.2.22458.4 + 7.0.0-rtm.22476.8 alpha 1