Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/BenchmarkDotNet/Templates/R2RCsProj.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<StartupObject>BenchmarkDotNet.Autogenerated.UniqueProgramName</StartupObject>
<!-- workaround for 'Found multiple publish output files with the same relative path.' error -->
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
<!-- Shorten obj path to work around https://github.com/dotnet/runtime/issues/103625. -->
<IntermediateOutputPath>$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', 'o'))</IntermediateOutputPath>
</PropertyGroup>

<PropertyGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/BenchmarkDotNet/Toolchains/NativeAot/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected override async ValueTask GenerateProjectAsync(BuildPartition buildPart
await GenerateReflectionFileAsync(artifactsPaths, cancellationToken).ConfigureAwait(false);
}

private string GenerateProjectForNuGetBuild(string projectFilePath, BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger) => $"""
internal string GenerateProjectForNuGetBuild(string projectFilePath, BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger) => $"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -159,6 +159,8 @@ private string GenerateProjectForNuGetBuild(string projectFilePath, BuildPartiti
<EnsureNETCoreAppRuntime>false</EnsureNETCoreAppRuntime> <!-- workaround for 'This runtime may not be supported by.NET Core.' error -->
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles> <!-- workaround for 'Found multiple publish output files with the same relative path.' error -->
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
<!-- Shorten obj path to work around https://github.com/dotnet/runtime/issues/103625. -->
<IntermediateOutputPath>$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', 'o'))</IntermediateOutputPath>
{GetInstructionSetSettings(buildPartition)}
</PropertyGroup>
{GetRuntimeSettings(buildPartition.RepresentativeBenchmarkCase.Job.Environment.Gc, buildPartition.Resolver)}
Expand Down
66 changes: 66 additions & 0 deletions tests/BenchmarkDotNet.Tests/AotProjectGeneratorTests.cs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I appreciate tests, but I don't think it's very useful in this case. The fix is just a workaround (not even a full fix, it just subtracts 12 characters from the length), not something we want to fix in place with tests.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Helpers;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Parameters;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Tests.Mocks;
using BenchmarkDotNet.Toolchains;
using BenchmarkDotNet.Toolchains.NativeAot;
using System.Xml.Linq;

namespace BenchmarkDotNet.Tests
{
public class AotProjectGeneratorTests
{
private const string ExpectedIntermediateOutputPath = "$([MSBuild]::NormalizeDirectory('$(MSBuildProjectDirectory)', 'o'))";

[Fact]
public void NativeAotProjectUsesShortBuildPaths()
{
var config = ManualConfig.CreateEmpty().CreateImmutableConfig();
var benchmark = BenchmarkCase.Create(
new Descriptor(MockFactory.MockType, MockFactory.MockMethodInfo),
Job.Default,
ParameterInstances.Empty,
config);
var buildPartition = new BuildPartition(
[new BenchmarkBuildInfo(benchmark, config, 0, new([]))],
BenchmarkRunnerClean.DefaultResolver);
var generator = new Generator(
ilCompilerVersion: "",
runtimeFrameworkVersion: "",
targetFrameworkMoniker: "net10.0",
cliPath: "",
runtimeIdentifier: "win-x64",
feeds: new Dictionary<string, string>(),
useNuGetClearTag: false,
useTempFolderForRestore: false,
packagesRestorePath: "",
rootAllApplicationAssemblies: false,
ilcGenerateStackTraceData: true,
ilcOptimizationPreference: "Speed",
ilcInstructionSet: "");

string project = generator.GenerateProjectForNuGetBuild(
"Benchmarks.csproj",
buildPartition,
ArtifactsPaths.Empty,
NullLogger.Instance);

AssertShortIntermediatePath(XDocument.Parse(project));
}

[Fact]
public void ReadyToRunProjectUsesShortBuildPaths()
{
AssertShortIntermediatePath(XDocument.Parse(ResourceHelper.LoadTemplate("R2RCsProj.txt")));
}

private static void AssertShortIntermediatePath(XDocument project)
{
Assert.Equal(ExpectedIntermediateOutputPath, project.Descendants("IntermediateOutputPath").Single().Value);
Assert.Empty(project.Descendants("BaseIntermediateOutputPath"));
}
}
}
Loading