Skip to content

Commit 3a18b18

Browse files
authored
use PublishAot and don't reference ILCompiler in explicit way (#2095)
1 parent 188c11c commit 3a18b18

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

src/BenchmarkDotNet/ConsoleArguments/ConfigParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ private static Job CreateJobForGivenRuntime(Job baseJob, string runtimeId, Comma
392392
case RuntimeMoniker.NativeAot60:
393393
return CreateAotJob(baseJob, options, runtimeMoniker, "6.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json");
394394
case RuntimeMoniker.NativeAot70:
395-
return CreateAotJob(baseJob, options, runtimeMoniker, "7.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json");
395+
return CreateAotJob(baseJob, options, runtimeMoniker, "", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json");
396396
case RuntimeMoniker.Wasm:
397397
return MakeWasmJob(baseJob, options, RuntimeInformation.IsNetCore ? CoreRuntime.GetCurrentVersion().MsBuildMoniker : "net5.0", runtimeMoniker);
398398
case RuntimeMoniker.WasmNet50:

src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ private string GenerateProjectForNuGetBuild(BuildPartition buildPartition, Artif
132132
<UseSharedCompilation>false</UseSharedCompilation>
133133
<Deterministic>true</Deterministic>
134134
<RunAnalyzers>false</RunAnalyzers>
135+
<PublishAot Condition="" '$(TargetFramework)' != 'net6.0' "">true</PublishAot>
135136
<IlcOptimizationPreference>{ilcOptimizationPreference}</IlcOptimizationPreference>
136137
{GetTrimmingSettings()}
137138
<IlcGenerateCompleteTypeMetadata>{ilcGenerateCompleteTypeMetadata}</IlcGenerateCompleteTypeMetadata>
@@ -146,14 +147,17 @@ private string GenerateProjectForNuGetBuild(BuildPartition buildPartition, Artif
146147
<Compile Include=""{Path.GetFileName(artifactsPaths.ProgramCodePath)}"" Exclude=""bin\**;obj\**;**\*.xproj;packages\**"" />
147148
</ItemGroup>
148149
<ItemGroup>
149-
<PackageReference Include=""Microsoft.DotNet.ILCompiler"" Version=""{ilCompilerVersion}"" />
150+
{GetILCompilerPackageReference()}
150151
<ProjectReference Include=""{GetProjectFilePath(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).FullName}"" />
151152
</ItemGroup>
152153
<ItemGroup>
153154
{string.Join(Environment.NewLine, GetRdXmlFiles(buildPartition.RepresentativeBenchmarkCase.Descriptor.Type, logger).Select(file => $"<RdXmlFile Include=\"{file}\" />"))}
154155
</ItemGroup>
155156
</Project>";
156157

158+
private string GetILCompilerPackageReference()
159+
=> string.IsNullOrEmpty(ilCompilerVersion) ? "" : $@"<PackageReference Include=""Microsoft.DotNet.ILCompiler"" Version=""{ilCompilerVersion}"" />";
160+
157161
private string GetTrimmingSettings()
158162
=> rootAllApplicationAssemblies
159163
? "" // use the defaults

src/BenchmarkDotNet/Toolchains/NativeAot/NativeAotToolchain.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ public class NativeAotToolchain : Toolchain
1414
.ToToolchain();
1515

1616
/// <summary>
17-
/// 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
17+
/// 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
1818
/// </summary>
1919
public static readonly IToolchain Net70 = CreateBuilder()
20-
.UseNuGet("7.0.0-*", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json")
20+
.UseNuGet("", "https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json")
2121
.TargetFrameworkMoniker("net7.0")
2222
.ToToolchain();
2323

src/BenchmarkDotNet/Toolchains/NativeAot/NativeAotToolchainBuilder.cs

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

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

37+
DisplayName(string.IsNullOrEmpty(ilCompilerVersion) ? "Latest ILCompiler" : $"ILCompiler {ilCompilerVersion}");
38+
3739
isIlCompilerConfigured = true;
3840

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

5861
isIlCompilerConfigured = true;
5962

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

150153
return new NativeAotToolchain(
151-
displayName: displayName ?? (ilCompilerVersion != null ? $"ILCompiler {ilCompilerVersion}" : "local ILCompiler build"),
154+
displayName: displayName,
152155
ilCompilerVersion: ilCompilerVersion,
153156
runtimeFrameworkVersion: runtimeFrameworkVersion,
154157
targetFrameworkMoniker: GetTargetFrameworkMoniker(),

0 commit comments

Comments
 (0)