Skip to content

Commit 5e62756

Browse files
authored
when Host process is not .NET Core, CoreRunToolchain should use latests available tfm (#2006)
as it's used only by dotnet/runtime contributors
1 parent a798816 commit 5e62756

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

src/BenchmarkDotNet.Annotations/Jobs/RuntimeMoniker.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,5 @@ public enum RuntimeMoniker
139139
/// Mono with the Ahead of Time LLVM Compiler backend and .net7.0
140140
/// </summary>
141141
MonoAOTLLVMNet70
142-
143142
}
144143
}

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,6 @@ private static bool Validate(CommandLineOptions options, ILogger logger)
163163
return false;
164164
}
165165

166-
if (!options.CoreRunPaths.IsNullOrEmpty() && !RuntimeInformation.IsNetCore)
167-
{
168-
logger.WriteLineError("CoreRun path can be used only for .NET Core host processes.");
169-
return false;
170-
}
171-
172166
if (options.HardwareCounters.Count() > 3)
173167
{
174168
logger.WriteLineError("You can't use more than 3 HardwareCounters at the same time.");
@@ -505,7 +499,10 @@ private static Job CreateCoreRunJob(Job baseJob, CommandLineOptions options, Fil
505499
.WithToolchain(new CoreRunToolchain(
506500
coreRunPath,
507501
createCopy: true,
508-
targetFrameworkMoniker: RuntimeInformation.GetCurrentRuntime().MsBuildMoniker,
502+
targetFrameworkMoniker:
503+
RuntimeInformation.IsNetCore
504+
? RuntimeInformation.GetCurrentRuntime().MsBuildMoniker
505+
: CoreRuntime.Latest.MsBuildMoniker, // use most recent tfm, as the toolchain is being used only by dotnet/runtime contributors
509506
customDotNetCliPath: options.CliPath,
510507
restorePath: options.RestorePath,
511508
displayName: GetCoreRunToolchainDisplayName(options.CoreRunPaths, coreRunPath)));

src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class CoreRuntime : Runtime
2020
public static readonly CoreRuntime Core60 = new CoreRuntime(RuntimeMoniker.Net60, "net6.0", ".NET 6.0");
2121
public static readonly CoreRuntime Core70 = new CoreRuntime(RuntimeMoniker.Net70, "net7.0", ".NET 7.0");
2222

23+
public static CoreRuntime Latest => Core70; // when dotnet/runtime branches for 8.0, this will need to get updated
24+
2325
private CoreRuntime(RuntimeMoniker runtimeMoniker, string msBuildMoniker, string displayName)
2426
: base(runtimeMoniker, msBuildMoniker, displayName)
2527
{

tests/BenchmarkDotNet.Tests/ConfigParserTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,16 @@ public void CoreRunConfigParsedCorrectlyWhenRuntimeNotSpecified()
151151
}
152152

153153
[FactClassicDotNetOnly("It's impossible to determine TFM for CoreRunToolchain if host process is not .NET (Core) process")]
154-
public void SpecifyingCoreRunWithFullFrameworkHostGivesError()
154+
public void SpecifyingCoreRunWithFullFrameworkTargetsMostRecentTfm()
155155
{
156156
var fakePath = typeof(object).Assembly.Location;
157-
Assert.False(ConfigParser.Parse(new[] { "--corerun", fakePath }, new OutputLogger(Output)).isSuccess);
157+
var config = ConfigParser.Parse(new[] { "--corerun", fakePath }, new OutputLogger(Output)).config;
158+
159+
Job coreRunJob = config.GetJobs().Single();
160+
161+
CoreRunToolchain coreRunToolchain = (CoreRunToolchain)coreRunJob.GetToolchain();
162+
DotNetCliGenerator generator = (DotNetCliGenerator)coreRunToolchain.Generator;
163+
Assert.Equal("net7.0", generator.TargetFrameworkMoniker);
158164
}
159165

160166
[FactDotNetCoreOnly("It's impossible to determine TFM for CoreRunToolchain if host process is not .NET (Core) process")]

0 commit comments

Comments
 (0)