diff --git a/.github/workflows/run-tests.yaml b/.github/workflows/run-tests.yaml index 34290061e1..5243ee47be 100644 --- a/.github/workflows/run-tests.yaml +++ b/.github/workflows/run-tests.yaml @@ -62,6 +62,14 @@ jobs: platform: x64 - name: Set up zlib-static run: sudo apt-get install -y libkrb5-dev + - name: Set up node + uses: actions/setup-node@v4 + with: + node-version: "20" + - name: Set up v8 + run: npm install jsvu -g && jsvu --os=linux64 --engines=v8 && echo "$HOME/.jsvu/bin" >> $GITHUB_PATH + - name: Install wasm-tools workload + run: ./build.cmd install-wasm-tools - name: Run task 'build' run: ./build.cmd build - name: Run task 'unit-tests' @@ -79,6 +87,14 @@ jobs: runs-on: macos-13 steps: - uses: actions/checkout@v3 + - name: Set up node + uses: actions/setup-node@v4 + with: + node-version: "20" + - name: Set up v8 + run: npm install jsvu -g && jsvu --os=mac64 --engines=v8 && echo "$HOME/.jsvu/bin" >> $GITHUB_PATH + - name: Install wasm-tools workload + run: ./build.cmd install-wasm-tools - name: Run task 'build' run: ./build.cmd build - name: Run task 'unit-tests' diff --git a/build/BenchmarkDotNet.Build/Program.cs b/build/BenchmarkDotNet.Build/Program.cs index 7e8e1d1d85..51dd875fbd 100644 --- a/build/BenchmarkDotNet.Build/Program.cs +++ b/build/BenchmarkDotNet.Build/Program.cs @@ -56,6 +56,26 @@ public HelpInfo GetHelp() } } +[TaskName(Name)] +[TaskDescription("Install wasm-tools workload")] +public class InstallWasmToolsWorkload : FrostingTask, IHelpProvider +{ + private const string Name = "install-wasm-tools"; + + public override void Run(BuildContext context) => context.BuildRunner.InstallWorkload("wasm-tools"); + + public HelpInfo GetHelp() + { + return new HelpInfo + { + Examples = new[] + { + new Example(Name) + } + }; + } +} + [TaskName(Name)] [TaskDescription("Run unit tests (fast)")] [IsDependentOn(typeof(BuildTask))] diff --git a/build/BenchmarkDotNet.Build/Runners/BuildRunner.cs b/build/BenchmarkDotNet.Build/Runners/BuildRunner.cs index 01c490fce3..a38ce7e79d 100644 --- a/build/BenchmarkDotNet.Build/Runners/BuildRunner.cs +++ b/build/BenchmarkDotNet.Build/Runners/BuildRunner.cs @@ -5,6 +5,7 @@ using Cake.Common.Tools.DotNet.Build; using Cake.Common.Tools.DotNet.Pack; using Cake.Common.Tools.DotNet.Restore; +using Cake.Common.Tools.DotNet.Workload.Install; using Cake.Core; using Cake.Core.IO; @@ -28,6 +29,16 @@ public void Restore() }); } + public void InstallWorkload(string workloadId) + { + context.DotNetWorkloadInstall(workloadId, + new DotNetWorkloadInstallSettings + { + IncludePreviews = true, + NoCache = true + }); + } + public void Build() { context.Information("BuildSystemProvider: " + context.BuildSystem().Provider); diff --git a/tests/BenchmarkDotNet.IntegrationTests/AppBundle/test-main.js b/tests/BenchmarkDotNet.IntegrationTests/AppBundle/test-main.js new file mode 100644 index 0000000000..c9f705d547 --- /dev/null +++ b/tests/BenchmarkDotNet.IntegrationTests/AppBundle/test-main.js @@ -0,0 +1,9 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +import { dotnet } from './_framework/dotnet.js' + +await dotnet + .withDiagnosticTracing(false) + .withApplicationArguments(...arguments) + .run() diff --git a/tests/BenchmarkDotNet.IntegrationTests/BenchmarkDotNet.IntegrationTests.csproj b/tests/BenchmarkDotNet.IntegrationTests/BenchmarkDotNet.IntegrationTests.csproj index e147194cbc..8949cce2c0 100644 --- a/tests/BenchmarkDotNet.IntegrationTests/BenchmarkDotNet.IntegrationTests.csproj +++ b/tests/BenchmarkDotNet.IntegrationTests/BenchmarkDotNet.IntegrationTests.csproj @@ -56,6 +56,7 @@ + diff --git a/tests/BenchmarkDotNet.IntegrationTests/WasmTests.cs b/tests/BenchmarkDotNet.IntegrationTests/WasmTests.cs new file mode 100644 index 0000000000..3eac9d5d74 --- /dev/null +++ b/tests/BenchmarkDotNet.IntegrationTests/WasmTests.cs @@ -0,0 +1,51 @@ +using System; +using System.IO; +using BenchmarkDotNet.Attributes; +using BenchmarkDotNet.Configs; +using BenchmarkDotNet.Environments; +using BenchmarkDotNet.Jobs; +using BenchmarkDotNet.Portability; +using BenchmarkDotNet.Tests.Loggers; +using BenchmarkDotNet.Tests.XUnit; +using BenchmarkDotNet.Toolchains.DotNetCli; +using BenchmarkDotNet.Toolchains.MonoWasm; +using Xunit.Abstractions; + +namespace BenchmarkDotNet.IntegrationTests +{ + public class WasmTests : BenchmarkTestExecutor + { + public WasmTests(ITestOutputHelper output) : base(output) { } + + [FactEnvSpecific("WASM is only supported on Unix", EnvRequirement.NonWindows)] + public void WasmIsSupported() + { + var dotnetVersion = "net8.0"; + var logger = new OutputLogger(Output); + var netCoreAppSettings = new NetCoreAppSettings(dotnetVersion, null, "Wasm"); + var mainJsPath = Path.Combine(AppContext.BaseDirectory, "AppBundle", "test-main.js"); + + var config = ManualConfig.CreateEmpty() + .AddLogger(logger) + .AddJob(Job.Dry + .WithArguments([new MsBuildArgument($"/p:WasmMainJSPath={mainJsPath}")]) + .WithRuntime(new WasmRuntime(dotnetVersion, moniker: RuntimeMoniker.WasmNet80, javaScriptEngineArguments: "--expose_wasm --module")) + .WithToolchain(WasmToolchain.From(netCoreAppSettings))) + .WithOption(ConfigOptions.GenerateMSBuildBinLog, true); + + CanExecute(config); + } + + public class WasmBenchmark + { + [Benchmark] + public void Check() + { + if (!RuntimeInformation.IsWasm) + { + throw new Exception("Incorrect runtime detection"); + } + } + } + } +}