Skip to content

Commit

Permalink
use PublishAot and don't reference ILCompiler in explicit way (#2095)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik committed Sep 6, 2022
1 parent 188c11c commit 3a18b18
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private static Job CreateJobForGivenRuntime(Job baseJob, string runtimeId, Comma
case RuntimeMoniker.NativeAot60:
return CreateAotJob(baseJob, options, runtimeMoniker, "6.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json");
case RuntimeMoniker.NativeAot70:
return CreateAotJob(baseJob, options, runtimeMoniker, "7.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json");
return CreateAotJob(baseJob, options, runtimeMoniker, "", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json");
case RuntimeMoniker.Wasm:
return MakeWasmJob(baseJob, options, RuntimeInformation.IsNetCore ? CoreRuntime.GetCurrentVersion().MsBuildMoniker : "net5.0", runtimeMoniker);
case RuntimeMoniker.WasmNet50:
Expand Down
6 changes: 5 additions & 1 deletion src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private string GenerateProjectForNuGetBuild(BuildPartition buildPartition, Artif
<UseSharedCompilation>false</UseSharedCompilation>
<Deterministic>true</Deterministic>
<RunAnalyzers>false</RunAnalyzers>
<PublishAot Condition="" '$(TargetFramework)' != 'net6.0' "">true</PublishAot>
<IlcOptimizationPreference>{ilcOptimizationPreference}</IlcOptimizationPreference>
{GetTrimmingSettings()}
<IlcGenerateCompleteTypeMetadata>{ilcGenerateCompleteTypeMetadata}</IlcGenerateCompleteTypeMetadata>
Expand All @@ -146,14 +147,17 @@ private string GenerateProjectForNuGetBuild(BuildPartition buildPartition, Artif
<Compile Include=""{Path.GetFileName(artifactsPaths.ProgramCodePath)}"" Exclude=""bin\**;obj\**;**\*.xproj;packages\**"" />
</ItemGroup>
<ItemGroup>
<PackageReference Include=""Microsoft.DotNet.ILCompiler"" Version=""{ilCompilerVersion}"" />
{GetILCompilerPackageReference()}
<ProjectReference Include=""{GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).FullName}"" />
</ItemGroup>
<ItemGroup>
{string.Join(Environment.NewLine, GetRdXmlFiles(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).Select(file => $"<RdXmlFile Include=\"{file}\" />"))}
</ItemGroup>
</Project>";

private string GetILCompilerPackageReference()
=> string.IsNullOrEmpty(ilCompilerVersion) ? "" : $@"<PackageReference Include=""Microsoft.DotNet.ILCompiler"" Version=""{ilCompilerVersion}"" />";

private string GetTrimmingSettings()
=> rootAllApplicationAssemblies
? "" // use the defaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ public class NativeAotToolchain : Toolchain
.ToToolchain();

/// <summary>
/// compiled as net7.0, targets latest (7.0.0-*) NativeAOT build from the .NET 7 feed: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json
/// compiled as net7.0, targets latest NativeAOT build from the .NET 7 feed: https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json
/// </summary>
public static readonly IToolchain Net70 = CreateBuilder()
.UseNuGet("7.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json")
.UseNuGet("", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json")
.TargetFrameworkMoniker("net7.0")
.ToToolchain();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ public class NativeAotToolchainBuilder : CustomDotNetCliToolchainBuilder
/// creates a NativeAOT toolchain targeting NuGet build of Microsoft.DotNet.ILCompiler
/// Based on https://github.com/dotnet/runtimelab/blob/d0a37893a67c125f9b0cd8671846ff7d867df241/samples/HelloWorld/README.md#add-corert-to-your-project
/// </summary>
/// <param name="microsoftDotNetILCompilerVersion">the version of Microsoft.DotNet.ILCompiler which should be used. The default is: "7.0.0-*"</param>
/// <param name="microsoftDotNetILCompilerVersion">the version of Microsoft.DotNet.ILCompiler which should be used. The default is empty which maps to latest version.</param>
/// <param name="nuGetFeedUrl">url to NuGet feed, The default is: "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json"</param>
[PublicAPI]
public NativeAotToolchainBuilder UseNuGet(string microsoftDotNetILCompilerVersion = "7.0.0-*", string nuGetFeedUrl = "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json")
public NativeAotToolchainBuilder UseNuGet(string microsoftDotNetILCompilerVersion = "", string nuGetFeedUrl = "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json")
{
ilCompilerVersion = microsoftDotNetILCompilerVersion ?? throw new ArgumentNullException(nameof(microsoftDotNetILCompilerVersion));
ilCompilerVersion = microsoftDotNetILCompilerVersion;

Feeds[Generator.NativeAotNuGetFeed] = nuGetFeedUrl ?? throw new ArgumentNullException(nameof(nuGetFeedUrl));

DisplayName(string.IsNullOrEmpty(ilCompilerVersion) ? "Latest ILCompiler" : $"ILCompiler {ilCompilerVersion}");

isIlCompilerConfigured = true;

return this;
Expand All @@ -54,6 +56,7 @@ public NativeAotToolchainBuilder UseLocalBuild(DirectoryInfo ilcPackages)
ilCompilerVersion = "7.0.0-dev";
Feeds["dotnet7"] = "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json";
useTempFolderForRestore = true;
DisplayName("local ILCompiler build");

isIlCompilerConfigured = true;

Expand Down Expand Up @@ -148,7 +151,7 @@ public override IToolchain ToToolchain()
throw new InvalidOperationException("You need to use UseNuGet or UseLocalBuild methods to tell us which ILCompiler to use.");

return new NativeAotToolchain(
displayName: displayName ?? (ilCompilerVersion != null ? $"ILCompiler {ilCompilerVersion}" : "local ILCompiler build"),
displayName: displayName,
ilCompilerVersion: ilCompilerVersion,
runtimeFrameworkVersion: runtimeFrameworkVersion,
targetFrameworkMoniker: GetTargetFrameworkMoniker(),
Expand Down

0 comments on commit 3a18b18

Please sign in to comment.