Skip to content

Commit 3afc4e7

Browse files
authored
Use ArtifactsPath (#2676)
* Use ArtifactsPath in sdk 8+ instead of IntermediateOutputPath. Pass PublishDir property to dotnet. * Removed IntermediateOutputPath, always use ArtifactsPath. Updated DotNetSdkValidator. * Fix BenchmarkRunnerClean skip non-critical validation errors. * Force older DotNetCli partitions to build sequentially. Revert sdk validator. * Use `DotNetSdkValidator.GetSdkVersionFromMoniker`. * Moved `DotNetSdkValidator.GetSdkVersionFromMoniker` to `RuntimeMonikerExtensions.GetRuntimeVersion`. Check all configs of each partition instead of only representative. * Updated exception message. * Use Except to not double-compute each partition. * Pass buildPartitions directly to event processor.
1 parent 0a5c828 commit 3afc4e7

File tree

11 files changed

+85
-98
lines changed

11 files changed

+85
-98
lines changed

src/BenchmarkDotNet/Extensions/RuntimeMonikerExtensions.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,51 @@ internal static Runtime GetRuntime(this RuntimeMoniker runtimeMoniker)
7575
throw new ArgumentOutOfRangeException(nameof(runtimeMoniker), runtimeMoniker, "Runtime Moniker not supported");
7676
}
7777
}
78+
79+
internal static Version GetRuntimeVersion(this RuntimeMoniker runtimeMoniker) => runtimeMoniker switch
80+
{
81+
RuntimeMoniker.Net461 => new Version(4, 6, 1),
82+
RuntimeMoniker.Net462 => new Version(4, 6, 2),
83+
RuntimeMoniker.Net47 => new Version(4, 7),
84+
RuntimeMoniker.Net471 => new Version(4, 7, 1),
85+
RuntimeMoniker.Net472 => new Version(4, 7, 2),
86+
RuntimeMoniker.Net48 => new Version(4, 8),
87+
RuntimeMoniker.Net481 => new Version(4, 8, 1),
88+
RuntimeMoniker.NetCoreApp20 => new Version(2, 0),
89+
RuntimeMoniker.NetCoreApp21 => new Version(2, 1),
90+
RuntimeMoniker.NetCoreApp22 => new Version(2, 2),
91+
RuntimeMoniker.NetCoreApp30 => new Version(3, 0),
92+
RuntimeMoniker.NetCoreApp31 => new Version(3, 1),
93+
RuntimeMoniker.Net50 => new Version(5, 0),
94+
RuntimeMoniker.Net60 => new Version(6, 0),
95+
RuntimeMoniker.Net70 => new Version(7, 0),
96+
RuntimeMoniker.Net80 => new Version(8, 0),
97+
RuntimeMoniker.Net90 => new Version(9, 0),
98+
RuntimeMoniker.Net10_0 => new Version(10, 0),
99+
RuntimeMoniker.NativeAot60 => new Version(6, 0),
100+
RuntimeMoniker.NativeAot70 => new Version(7, 0),
101+
RuntimeMoniker.NativeAot80 => new Version(8, 0),
102+
RuntimeMoniker.NativeAot90 => new Version(9, 0),
103+
RuntimeMoniker.NativeAot10_0 => new Version(10, 0),
104+
RuntimeMoniker.Mono60 => new Version(6, 0),
105+
RuntimeMoniker.Mono70 => new Version(7, 0),
106+
RuntimeMoniker.Mono80 => new Version(8, 0),
107+
RuntimeMoniker.Mono90 => new Version(9, 0),
108+
RuntimeMoniker.Mono10_0 => new Version(10, 0),
109+
RuntimeMoniker.Wasm => Portability.RuntimeInformation.IsNetCore && CoreRuntime.TryGetVersion(out var version) ? version : new Version(5, 0),
110+
RuntimeMoniker.WasmNet50 => new Version(5, 0),
111+
RuntimeMoniker.WasmNet60 => new Version(6, 0),
112+
RuntimeMoniker.WasmNet70 => new Version(7, 0),
113+
RuntimeMoniker.WasmNet80 => new Version(8, 0),
114+
RuntimeMoniker.WasmNet90 => new Version(9, 0),
115+
RuntimeMoniker.WasmNet10_0 => new Version(10, 0),
116+
RuntimeMoniker.MonoAOTLLVM => Portability.RuntimeInformation.IsNetCore && CoreRuntime.TryGetVersion(out var version) ? version : new Version(6, 0),
117+
RuntimeMoniker.MonoAOTLLVMNet60 => new Version(6, 0),
118+
RuntimeMoniker.MonoAOTLLVMNet70 => new Version(7, 0),
119+
RuntimeMoniker.MonoAOTLLVMNet80 => new Version(8, 0),
120+
RuntimeMoniker.MonoAOTLLVMNet90 => new Version(9, 0),
121+
RuntimeMoniker.MonoAOTLLVMNet10_0 => new Version(10, 0),
122+
_ => throw new NotImplementedException($"{nameof(GetRuntimeVersion)} not implemented for {runtimeMoniker}")
123+
};
78124
}
79125
}

src/BenchmarkDotNet/Running/BenchmarkRunnerClean.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using BenchmarkDotNet.Mathematics;
2222
using BenchmarkDotNet.Reports;
2323
using BenchmarkDotNet.Toolchains;
24+
using BenchmarkDotNet.Toolchains.DotNetCli;
2425
using BenchmarkDotNet.Toolchains.Parameters;
2526
using BenchmarkDotNet.Toolchains.Results;
2627
using BenchmarkDotNet.Validators;
@@ -81,17 +82,21 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
8182
compositeLogger.WriteLineHeader($"// ***** Found {totalBenchmarkCount} benchmark(s) in total *****");
8283
var globalChronometer = Chronometer.Start();
8384

85+
var buildPartitions = BenchmarkPartitioner.CreateForBuild(supportedBenchmarks, resolver);
86+
eventProcessor.OnStartBuildStage(buildPartitions);
8487

85-
var parallelBuildBenchmarks = supportedBenchmarks.Where(x => !x.Config.Options.IsSet(ConfigOptions.DisableParallelBuild)).ToArray();
86-
var parallelBuildPartitions = BenchmarkPartitioner.CreateForBuild(parallelBuildBenchmarks, resolver);
87-
88-
var sequentialBuildBenchmarks = supportedBenchmarks.Where(x => x.Config.Options.IsSet(ConfigOptions.DisableParallelBuild)).ToArray();
89-
var sequentialBuildPartitions = BenchmarkPartitioner.CreateForBuild(sequentialBuildBenchmarks, resolver);
90-
91-
eventProcessor.OnStartBuildStage([.. parallelBuildPartitions, .. sequentialBuildPartitions]);
88+
var sequentialBuildPartitions = buildPartitions.Where(partition =>
89+
partition.Benchmarks.Any(x => x.Config.Options.IsSet(ConfigOptions.DisableParallelBuild))
90+
// .Net SDK 8+ supports ArtifactsPath for proper parallel builds.
91+
// Older SDKs may produce builds with incorrect bindings if more than 1 partition is built in parallel.
92+
|| (partition.RepresentativeBenchmarkCase.GetToolchain().Generator is DotNetCliGenerator
93+
&& partition.RepresentativeBenchmarkCase.GetRuntime().RuntimeMoniker.GetRuntimeVersion().Major < 8)
94+
)
95+
.ToArray();
96+
var parallelBuildPartitions = buildPartitions.Except(sequentialBuildPartitions).ToArray();
9297

9398
var buildResults = new Dictionary<BuildPartition, BuildResult>();
94-
if (parallelBuildBenchmarks.Length > 0)
99+
if (parallelBuildPartitions.Length > 0)
95100
{
96101
var results = BuildInParallel(compositeLogger, rootArtifactsFolderPath, parallelBuildPartitions, in globalChronometer, eventProcessor);
97102
foreach (var kvp in results)
@@ -100,7 +105,7 @@ internal static Summary[] Run(BenchmarkRunInfo[] benchmarkRunInfos)
100105
}
101106
}
102107

103-
if (sequentialBuildBenchmarks.Length > 0)
108+
if (sequentialBuildPartitions.Length > 0)
104109
{
105110
var results = BuildSequential(compositeLogger, rootArtifactsFolderPath, sequentialBuildPartitions, in globalChronometer, eventProcessor);
106111
foreach (var kvp in results)
@@ -644,7 +649,7 @@ private static (BenchmarkRunInfo[], List<ValidationError>) GetSupportedBenchmark
644649

645650
validationErrors.AddRange(errors);
646651

647-
return errors.Length == 0;
652+
return !errors.Any(error => error.IsCritical);
648653
})
649654
.ToArray();
650655

src/BenchmarkDotNet/Templates/WasmCsProj.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
1616
<TargetFramework>$TFM$</TargetFramework>
1717
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
18-
<AppDir>$(MSBuildThisFileDirectory)\bin\$TFM$\browser-wasm\publish</AppDir>
18+
<AppDir>$(PublishDir)</AppDir>
1919
<AssemblyName>$PROGRAMNAME$</AssemblyName>
2020
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
2121
<SuppressTrimAnalysisWarnings>true</SuppressTrimAnalysisWarnings>
@@ -50,8 +50,8 @@
5050

5151
<Target Name="PrepareForWasmBuild" AfterTargets="Publish">
5252
<ItemGroup>
53-
<WasmAssembliesToBundle Include="$(TargetDir)publish\*.dll" Condition="'$(RunAOTCompilation)' != 'true'" />
54-
<WasmAssembliesToBundle Include="$(TargetDir)publish\*.dll" Exclude="$(TargetDir)publish\KernelTraceControl.dll" Condition="'$(RunAOTCompilation)' == 'true'" />
53+
<WasmAssembliesToBundle Include="$(PublishDir)*.dll" Condition="'$(RunAOTCompilation)' != 'true'" />
54+
<WasmAssembliesToBundle Include="$(PublishDir)*.dll" Exclude="$(PublishDir)KernelTraceControl.dll" Condition="'$(RunAOTCompilation)' == 'true'" />
5555
</ItemGroup>
5656
</Target>
5757

src/BenchmarkDotNet/Toolchains/ArtifactsPaths.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class ArtifactsPaths
99
[PublicAPI] public string RootArtifactsFolderPath { get; }
1010
[PublicAPI] public string BuildArtifactsDirectoryPath { get; }
1111
[PublicAPI] public string BinariesDirectoryPath { get; }
12-
[PublicAPI] public string IntermediateDirectoryPath { get; }
12+
[PublicAPI] public string PublishDirectoryPath { get; }
1313
[PublicAPI] public string ProgramCodePath { get; }
1414
[PublicAPI] public string AppConfigPath { get; }
1515
[PublicAPI] public string NuGetConfigPath { get; }
@@ -23,7 +23,7 @@ public ArtifactsPaths(
2323
string rootArtifactsFolderPath,
2424
string buildArtifactsDirectoryPath,
2525
string binariesDirectoryPath,
26-
string intermediateDirectoryPath,
26+
string publishDirectoryPath,
2727
string programCodePath,
2828
string appConfigPath,
2929
string nuGetConfigPath,
@@ -36,7 +36,7 @@ public ArtifactsPaths(
3636
RootArtifactsFolderPath = rootArtifactsFolderPath;
3737
BuildArtifactsDirectoryPath = buildArtifactsDirectoryPath;
3838
BinariesDirectoryPath = binariesDirectoryPath;
39-
IntermediateDirectoryPath = intermediateDirectoryPath;
39+
PublishDirectoryPath = publishDirectoryPath;
4040
ProgramCodePath = programCodePath;
4141
AppConfigPath = appConfigPath;
4242
NuGetConfigPath = nuGetConfigPath;

src/BenchmarkDotNet/Toolchains/CsProj/CsProjGenerator.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ protected override string GetProjectFilePath(string buildArtifactsDirectoryPath)
6464
protected override string GetBinariesDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
6565
=> Path.Combine(buildArtifactsDirectoryPath, "bin", configuration, TargetFrameworkMoniker);
6666

67-
protected override string GetIntermediateDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
68-
=> Path.Combine(buildArtifactsDirectoryPath, "obj", configuration, TargetFrameworkMoniker);
69-
7067
[SuppressMessage("ReSharper", "StringLiteralTypo")] // R# complains about $variables$
7168
protected override void GenerateProject(BuildPartition buildPartition, ArtifactsPaths artifactsPaths, ILogger logger)
7269
{

src/BenchmarkDotNet/Toolchains/DotNetCli/DotNetCliCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Text;
66
using BenchmarkDotNet.Characteristics;
7+
using BenchmarkDotNet.Environments;
78
using BenchmarkDotNet.Extensions;
89
using BenchmarkDotNet.Jobs;
910
using BenchmarkDotNet.Loggers;
@@ -262,10 +263,11 @@ internal static StringBuilder MaybeAppendOutputPaths(this StringBuilder stringBu
262263
? stringBuilder
263264
: stringBuilder
264265
// Use AltDirectorySeparatorChar so it's not interpreted as an escaped quote `\"`.
265-
.AppendArgument($"/p:IntermediateOutputPath=\"{artifactsPaths.IntermediateDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
266+
.AppendArgument($"/p:ArtifactsPath=\"{artifactsPaths.BuildArtifactsDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
266267
.AppendArgument($"/p:OutDir=\"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
267268
// OutputPath is legacy, per-project version of OutDir. We set both just in case. https://github.com/dotnet/msbuild/issues/87
268269
.AppendArgument($"/p:OutputPath=\"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
270+
.AppendArgument($"/p:PublishDir=\"{artifactsPaths.PublishDirectoryPath}{Path.AltDirectorySeparatorChar}\"")
269271
.AppendArgument(isRestore ? string.Empty : $"--output \"{artifactsPaths.BinariesDirectoryPath}{Path.AltDirectorySeparatorChar}\"");
270272
}
271273
}

src/BenchmarkDotNet/Toolchains/GeneratorBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ [PublicAPI] protected virtual string GetBinariesDirectoryPath(string buildArtifa
5151
=> buildArtifactsDirectoryPath;
5252

5353
/// <summary>
54-
/// returns a path where intermediate files should be found after the build (usually \obj)
54+
/// returns a path where the publish directory should be found after the build (usually \publish)
5555
/// </summary>
5656
[PublicAPI]
57-
protected virtual string GetIntermediateDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
58-
=> string.Empty;
57+
protected virtual string GetPublishDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
58+
=> Path.Combine(buildArtifactsDirectoryPath, "publish");
5959

6060
/// <summary>
6161
/// returns OS-specific executable extension
@@ -138,7 +138,7 @@ private ArtifactsPaths GetArtifactsPaths(BuildPartition buildPartition, string r
138138
rootArtifactsFolderPath: rootArtifactsFolderPath,
139139
buildArtifactsDirectoryPath: buildArtifactsDirectoryPath,
140140
binariesDirectoryPath: binariesDirectoryPath,
141-
intermediateDirectoryPath: GetIntermediateDirectoryPath(buildArtifactsDirectoryPath, buildPartition.BuildConfiguration),
141+
publishDirectoryPath: GetPublishDirectoryPath(buildArtifactsDirectoryPath, buildPartition.BuildConfiguration),
142142
programCodePath: Path.Combine(buildArtifactsDirectoryPath, $"{programName}{codeFileExtension}"),
143143
appConfigPath: $"{executablePath}.config",
144144
nuGetConfigPath: Path.Combine(buildArtifactsDirectoryPath, "NuGet.config"),

src/BenchmarkDotNet/Toolchains/InProcess/Emit/InProcessEmitArtifactsPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public InProcessEmitArtifactsPath(
1212
baseArtifacts.RootArtifactsFolderPath,
1313
baseArtifacts.BuildArtifactsDirectoryPath,
1414
baseArtifacts.BinariesDirectoryPath,
15-
baseArtifacts.IntermediateDirectoryPath,
15+
baseArtifacts.PublishDirectoryPath,
1616
baseArtifacts.ProgramCodePath,
1717
baseArtifacts.AppConfigPath,
1818
baseArtifacts.NuGetConfigPath,

src/BenchmarkDotNet/Toolchains/InProcess/Emit/InProcessEmitGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ private ArtifactsPaths GetArtifactsPaths(BuildPartition buildPartition, string r
4747
rootArtifactsFolderPath: rootArtifactsFolderPath,
4848
buildArtifactsDirectoryPath: buildArtifactsDirectoryPath,
4949
binariesDirectoryPath: binariesDirectoryPath,
50-
intermediateDirectoryPath: null,
50+
publishDirectoryPath: null,
5151
programCodePath: null,
5252
appConfigPath: null,
5353
nuGetConfigPath: null,

src/BenchmarkDotNet/Toolchains/MonoAotLLVM/MonoAotLLVMGenerator.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ protected override void GenerateProject(BuildPartition buildPartition, Artifacts
5353
File.WriteAllText(artifactsPaths.ProjectFilePath, content);
5454
}
5555

56+
protected override string GetPublishDirectoryPath(string buildArtifactsDirectoryPath, string configuration)
57+
=> Path.Combine(GetBinariesDirectoryPath(buildArtifactsDirectoryPath, configuration), "publish");
58+
5659
protected override string GetExecutablePath(string binariesDirectoryPath, string programName)
5760
=> OsDetector.IsWindows()
5861
? Path.Combine(binariesDirectoryPath, "publish", $"{programName}.exe")

0 commit comments

Comments
 (0)