Skip to content

Commit a5176a7

Browse files
authored
Add net7.0 runtime support (#1816)
1 parent 2731137 commit a5176a7

File tree

10 files changed

+47
-8
lines changed

10 files changed

+47
-8
lines changed

src/BenchmarkDotNet.Annotations/Jobs/RuntimeMoniker.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ public enum RuntimeMoniker
8888
/// <summary>
8989
/// .NET 6.0
9090
/// </summary>
91-
Net60, // it's after NetCoreApp50 and Net50 in the enum definition because the value of enumeration is used for framework version comparison using > < operators
91+
Net60,
92+
93+
/// <summary>
94+
/// .NET 7.0
95+
/// </summary>
96+
Net70,
9297

9398
/// <summary>
9499
/// CoreRT compiled as netcoreapp2.0
@@ -125,6 +130,11 @@ public enum RuntimeMoniker
125130
/// </summary>
126131
CoreRt60,
127132

133+
/// <summary>
134+
/// CoreRT compiled as net7.0
135+
/// </summary>
136+
CoreRt70,
137+
128138
/// <summary>
129139
/// WebAssembly with default .Net version
130140
/// </summary>
@@ -140,6 +150,11 @@ public enum RuntimeMoniker
140150
/// </summary>
141151
WasmNet60,
142152

153+
/// <summary>
154+
/// WebAssembly with .net7.0
155+
/// </summary>
156+
WasmNet70,
157+
143158
/// <summary>
144159
/// Mono with the Ahead of Time LLVM Compiler backend
145160
/// </summary>

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ private static Job CreateJobForGivenRuntime(Job baseJob, string runtimeId, Comma
352352
#pragma warning restore CS0618 // Type or member is obsolete
353353
case RuntimeMoniker.Net50:
354354
case RuntimeMoniker.Net60:
355+
case RuntimeMoniker.Net70:
355356
return baseJob
356357
.WithRuntime(runtimeMoniker.GetRuntime())
357358
.WithToolchain(CsProjCoreToolchain.From(new NetCoreAppSettings(runtimeId, null, runtimeId, options.CliPath?.FullName, options.RestorePath?.FullName, timeOut)));
@@ -364,6 +365,7 @@ private static Job CreateJobForGivenRuntime(Job baseJob, string runtimeId, Comma
364365
case RuntimeMoniker.CoreRt31:
365366
case RuntimeMoniker.CoreRt50:
366367
case RuntimeMoniker.CoreRt60:
368+
case RuntimeMoniker.CoreRt70:
367369
var builder = CoreRtToolchain.CreateBuilder();
368370

369371
if (options.CliPath != null)
@@ -391,6 +393,8 @@ private static Job CreateJobForGivenRuntime(Job baseJob, string runtimeId, Comma
391393
return MakeWasmJob(baseJob, options, timeOut, "net5.0");
392394
case RuntimeMoniker.WasmNet60:
393395
return MakeWasmJob(baseJob, options, timeOut, "net6.0");
396+
case RuntimeMoniker.WasmNet70:
397+
return MakeWasmJob(baseJob, options, timeOut, "net7.0");
394398
case RuntimeMoniker.MonoAOTLLVM:
395399
var monoAotLLVMRuntime = new MonoAotLLVMRuntime(aotCompilerPath: options.AOTCompilerPath);
396400

src/BenchmarkDotNet/Environments/Runtimes/CoreRtRuntime.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ public class CoreRtRuntime : Runtime
3434
/// <summary>
3535
/// CoreRT compiled as net6.0
3636
/// </summary>
37-
public static readonly CoreRtRuntime CoreRt60 = new CoreRtRuntime(RuntimeMoniker.CoreRt50, "net6.0", "CoreRT 6.0");
37+
public static readonly CoreRtRuntime CoreRt60 = new CoreRtRuntime(RuntimeMoniker.CoreRt60, "net6.0", "CoreRT 6.0");
38+
/// <summary>
39+
/// CoreRT compiled as net7.0
40+
/// </summary>
41+
public static readonly CoreRtRuntime CoreRt70 = new CoreRtRuntime(RuntimeMoniker.CoreRt70, "net7.0", "CoreRT 7.0");
3842

3943
private CoreRtRuntime(RuntimeMoniker runtimeMoniker, string msBuildMoniker, string displayName)
4044
: base(runtimeMoniker, msBuildMoniker, displayName)
@@ -62,6 +66,7 @@ public static CoreRtRuntime GetCurrentVersion()
6266
case Version v when v.Major == 3 && v.Minor == 1: return CoreRt31;
6367
case Version v when v.Major == 5 && v.Minor == 0: return CoreRt50;
6468
case Version v when v.Major == 6 && v.Minor == 0: return CoreRt60;
69+
case Version v when v.Major == 7 && v.Minor == 0: return CoreRt70;
6570
default:
6671
return new CoreRtRuntime(RuntimeMoniker.NotRecognized, $"net{version.Major}.{version.Minor}", $"CoreRT {version.Major}.{version.Minor}");
6772
}

src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class CoreRuntime : Runtime
1818
public static readonly CoreRuntime Core31 = new CoreRuntime(RuntimeMoniker.NetCoreApp31, "netcoreapp3.1", ".NET Core 3.1");
1919
public static readonly CoreRuntime Core50 = new CoreRuntime(RuntimeMoniker.Net50, "net5.0", ".NET 5.0");
2020
public static readonly CoreRuntime Core60 = new CoreRuntime(RuntimeMoniker.Net60, "net6.0", ".NET 6.0");
21+
public static readonly CoreRuntime Core70 = new CoreRuntime(RuntimeMoniker.Net70, "net7.0", ".NET 7.0");
2122

2223
private CoreRuntime(RuntimeMoniker runtimeMoniker, string msBuildMoniker, string displayName)
2324
: base(runtimeMoniker, msBuildMoniker, displayName)
@@ -66,6 +67,7 @@ internal static CoreRuntime FromVersion(Version version)
6667
case Version v when v.Major == 3 && v.Minor == 1: return Core31;
6768
case Version v when v.Major == 5 && v.Minor == 0: return GetPlatformSpecific(Core50);
6869
case Version v when v.Major == 6 && v.Minor == 0: return GetPlatformSpecific(Core60);
70+
case Version v when v.Major == 7 && v.Minor == 0: return GetPlatformSpecific(Core70);
6971
default:
7072
return CreateForNewVersion($"net{version.Major}.{version.Minor}", $".NET {version.Major}.{version.Minor}");
7173
}

src/BenchmarkDotNet/Extensions/RuntimeMonikerExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ internal static Runtime GetRuntime(this RuntimeMoniker runtimeMoniker)
3939
return CoreRuntime.Core50;
4040
case RuntimeMoniker.Net60:
4141
return CoreRuntime.Core60;
42+
case RuntimeMoniker.Net70:
43+
return CoreRuntime.Core70;
4244
case RuntimeMoniker.Mono:
4345
return MonoRuntime.Default;
4446
case RuntimeMoniker.CoreRt20:
@@ -55,6 +57,8 @@ internal static Runtime GetRuntime(this RuntimeMoniker runtimeMoniker)
5557
return CoreRtRuntime.CoreRt50;
5658
case RuntimeMoniker.CoreRt60:
5759
return CoreRtRuntime.CoreRt60;
60+
case RuntimeMoniker.CoreRt70:
61+
return CoreRtRuntime.CoreRt70;
5862
default:
5963
throw new ArgumentOutOfRangeException(nameof(runtimeMoniker), runtimeMoniker, "Runtime Moniker not supported");
6064
}

src/BenchmarkDotNet/Toolchains/CoreRt/CoreRtToolchain.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public class CoreRtToolchain : Toolchain
3535
/// compiled as net6.0, targets latest (6.0.0-*) CoreRT build from the new feed: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json
3636
/// </summary>
3737
public static readonly IToolchain Core60 = CreateBuilder().UseCoreRtNuGet().TargetFrameworkMoniker("net6.0").ToToolchain();
38+
/// </summary>
39+
public static readonly IToolchain Core70 = CreateBuilder().UseCoreRtNuGet().TargetFrameworkMoniker("net7.0").ToToolchain();
3840

3941
internal CoreRtToolchain(string displayName,
4042
string coreRtVersion, string ilcPath, bool useCppCodeGenerator,
@@ -65,4 +67,4 @@ private static string GetExtraArguments(bool useCppCodeGenerator, string runtime
6567
private static IReadOnlyList<EnvironmentVariable> GetEnvironmentVariables(string ilcPath)
6668
=> ilcPath == null ? Array.Empty<EnvironmentVariable>() : new[] { new EnvironmentVariable("IlcPath", ilcPath) };
6769
}
68-
}
70+
}

src/BenchmarkDotNet/Toolchains/CsProj/CsProjCoreToolchain.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class CsProjCoreToolchain : Toolchain, IEquatable<CsProjCoreToolchain>
2121
[PublicAPI] public static readonly IToolchain NetCoreApp31 = From(NetCoreAppSettings.NetCoreApp31);
2222
[PublicAPI] public static readonly IToolchain NetCoreApp50 = From(NetCoreAppSettings.NetCoreApp50);
2323
[PublicAPI] public static readonly IToolchain NetCoreApp60 = From(NetCoreAppSettings.NetCoreApp60);
24+
[PublicAPI] public static readonly IToolchain NetCoreApp70 = From(NetCoreAppSettings.NetCoreApp70);
2425

2526
private CsProjCoreToolchain(string name, IGenerator generator, IBuilder builder, IExecutor executor, string customDotNetCliPath)
2627
: base(name, generator, builder, executor)
@@ -78,4 +79,4 @@ public override bool IsSupported(BenchmarkCase benchmarkCase, ILogger logger, IR
7879

7980
public override int GetHashCode() => Generator.GetHashCode();
8081
}
81-
}
82+
}

src/BenchmarkDotNet/Toolchains/DotNetCli/NetCoreAppSettings.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class NetCoreAppSettings
2020
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp31 = new NetCoreAppSettings("netcoreapp3.1", null, ".NET Core 3.1");
2121
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp50 = new NetCoreAppSettings("net5.0", null, ".NET 5.0");
2222
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp60 = new NetCoreAppSettings("net6.0", null, ".NET 6.0");
23+
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp70 = new NetCoreAppSettings("net7.0", null, ".NET 7.0");
2324

2425
/// <summary>
2526
/// <param name="targetFrameworkMoniker">
@@ -115,4 +116,4 @@ public NetCoreAppSettings WithCustomPackagesRestorePath(string packagesPath, str
115116
public NetCoreAppSettings WithTimeout(TimeSpan? timeOut)
116117
=> new NetCoreAppSettings(TargetFrameworkMoniker, RuntimeFrameworkVersion, Name, CustomDotNetCliPath, PackagesPath, timeOut ?? Timeout);
117118
}
118-
}
119+
}

src/BenchmarkDotNet/Toolchains/ToolchainExtensions.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ private static IToolchain GetToolchain(RuntimeMoniker runtimeMoniker)
106106
return CsProjCoreToolchain.NetCoreApp50;
107107
case RuntimeMoniker.Net60:
108108
return CsProjCoreToolchain.NetCoreApp60;
109+
case RuntimeMoniker.Net70:
110+
return CsProjCoreToolchain.NetCoreApp70;
109111
case RuntimeMoniker.CoreRt20:
110112
return CoreRtToolchain.Core20;
111113
case RuntimeMoniker.CoreRt21:
@@ -120,9 +122,11 @@ private static IToolchain GetToolchain(RuntimeMoniker runtimeMoniker)
120122
return CoreRtToolchain.Core50;
121123
case RuntimeMoniker.CoreRt60:
122124
return CoreRtToolchain.Core60;
125+
case RuntimeMoniker.CoreRt70:
126+
return CoreRtToolchain.Core70;
123127
default:
124128
throw new ArgumentOutOfRangeException(nameof(runtimeMoniker), runtimeMoniker, "RuntimeMoniker not supported");
125129
}
126130
}
127131
}
128-
}
132+
}

tests/BenchmarkDotNet.Tests/ConfigParserTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ public void NetFrameworkMonikerParsedCorrectly(string tfm)
309309
[Theory]
310310
[InlineData("net50")]
311311
[InlineData("net60")]
312-
public void Net50AndNet60MonikersAreRecognizedAsNetCoreMonikers(string tfm)
312+
[InlineData("net70")]
313+
public void NetMonikersAreRecognizedAsNetCoreMonikers(string tfm)
313314
{
314315
var config = ConfigParser.Parse(new[] { "-r", tfm }, new OutputLogger(Output)).config;
315316

@@ -482,4 +483,4 @@ public void InvalidEnvVarAreRecognized()
482483
Assert.False(ConfigParser.Parse(new[] { "--envVars", "INVALID_NO_SEPARATOR" }, new OutputLogger(Output)).isSuccess);
483484
}
484485
}
485-
}
486+
}

0 commit comments

Comments
 (0)