-
-
Notifications
You must be signed in to change notification settings - Fork 978
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement MonoVM toolchain for net6.0 and net7.0 monikers (#2142) fixes
#2064 Co-authored-by: Adam Sitnik <[email protected]>
- Loading branch information
1 parent
7d83758
commit 64c3a3c
Showing
14 changed files
with
209 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using BenchmarkDotNet.Characteristics; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Toolchains.CsProj; | ||
|
||
namespace BenchmarkDotNet.Toolchains.Mono | ||
{ | ||
public class MonoGenerator : CsProjGenerator | ||
{ | ||
public MonoGenerator(string targetFrameworkMoniker, string cliPath, string packagesPath, string runtimeFrameworkVersion) : base(targetFrameworkMoniker, cliPath, packagesPath, runtimeFrameworkVersion, true) | ||
{ | ||
} | ||
|
||
protected override string GetRuntimeSettings(GcMode gcMode, IResolver resolver) | ||
{ | ||
// Workaround for 'Found multiple publish output files with the same relative path' error | ||
return base.GetRuntimeSettings(gcMode, resolver) + "<PropertyGroup><ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles></PropertyGroup>"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Loggers; | ||
using BenchmarkDotNet.Running; | ||
using BenchmarkDotNet.Toolchains.DotNetCli; | ||
using BenchmarkDotNet.Toolchains.Results; | ||
|
||
namespace BenchmarkDotNet.Toolchains.Mono | ||
{ | ||
public class MonoPublisher : IBuilder | ||
{ | ||
public MonoPublisher(string customDotNetCliPath) | ||
{ | ||
CustomDotNetCliPath = customDotNetCliPath; | ||
var runtimeIdentifier = CustomDotNetCliToolchainBuilder.GetPortableRuntimeIdentifier(); | ||
|
||
// /p:RuntimeIdentifiers is set explicitly here because --self-contained requires it, see https://github.com/dotnet/sdk/issues/10566 | ||
ExtraArguments = $"--self-contained -r {runtimeIdentifier} /p:UseMonoRuntime=true /p:RuntimeIdentifiers={runtimeIdentifier}"; | ||
} | ||
|
||
private string CustomDotNetCliPath { get; } | ||
|
||
private string ExtraArguments { get; } | ||
|
||
private IReadOnlyList<EnvironmentVariable> EnvironmentVariables { get; } | ||
|
||
public BuildResult Build(GenerateResult generateResult, BuildPartition buildPartition, ILogger logger) | ||
=> new DotNetCliCommand( | ||
CustomDotNetCliPath, | ||
ExtraArguments, | ||
generateResult, | ||
logger, | ||
buildPartition, | ||
EnvironmentVariables, | ||
buildPartition.Timeout) | ||
.Publish().ToBuildResult(generateResult); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using BenchmarkDotNet.Toolchains.CsProj; | ||
using BenchmarkDotNet.Toolchains.DotNetCli; | ||
using JetBrains.Annotations; | ||
using System; | ||
|
||
namespace BenchmarkDotNet.Toolchains.Mono | ||
{ | ||
[PublicAPI] | ||
public class MonoToolchain : CsProjCoreToolchain, IEquatable<MonoToolchain> | ||
{ | ||
[PublicAPI] public static readonly IToolchain Mono60 = From(new NetCoreAppSettings("net6.0", null, "mono60")); | ||
[PublicAPI] public static readonly IToolchain Mono70 = From(new NetCoreAppSettings("net7.0", null, "mono70")); | ||
|
||
private MonoToolchain(string name, IGenerator generator, IBuilder builder, IExecutor executor, string customDotNetCliPath) | ||
: base(name, generator, builder, executor, customDotNetCliPath) | ||
{ | ||
} | ||
|
||
[PublicAPI] | ||
public static new IToolchain From(NetCoreAppSettings settings) | ||
{ | ||
return new MonoToolchain(settings.Name, | ||
new MonoGenerator(settings.TargetFrameworkMoniker, settings.CustomDotNetCliPath, settings.PackagesPath, settings.RuntimeFrameworkVersion), | ||
new MonoPublisher(settings.CustomDotNetCliPath), | ||
new DotNetCliExecutor(settings.CustomDotNetCliPath), | ||
settings.CustomDotNetCliPath); | ||
} | ||
|
||
public override bool Equals(object obj) => obj is MonoToolchain typed && Equals(typed); | ||
|
||
public bool Equals(MonoToolchain other) => Generator.Equals(other.Generator); | ||
|
||
public override int GetHashCode() => Generator.GetHashCode(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using BenchmarkDotNet.Attributes; | ||
using BenchmarkDotNet.Configs; | ||
using BenchmarkDotNet.Environments; | ||
using BenchmarkDotNet.Jobs; | ||
using BenchmarkDotNet.Tests.XUnit; | ||
|
||
namespace BenchmarkDotNet.IntegrationTests | ||
{ | ||
public class MonoTests : BenchmarkTestExecutor | ||
{ | ||
[FactDotNetCoreOnly("UseMonoRuntime option is available in .NET Core only starting from .NET 6")] | ||
public void Mono60IsSupported() | ||
{ | ||
var config = ManualConfig.CreateEmpty().AddJob(Job.Dry.WithRuntime(MonoRuntime.Mono60)); | ||
CanExecute<MonoBenchmark>(config); | ||
} | ||
|
||
public class MonoBenchmark | ||
{ | ||
[Benchmark] | ||
public void Check() | ||
{ | ||
if (Type.GetType("Mono.RuntimeStructs") == null) | ||
{ | ||
throw new Exception("This is not Mono runtime"); | ||
} | ||
} | ||
} | ||
} | ||
} |