Skip to content

Commit 554127b

Browse files
authored
Fix AppVeyor build (#1987)
* add Visual C++ toolset to $path so NativeAOT tests can build native executables * set Platform for Windows build * force the tool to not look for the .dll in platform-specific directory * don't run some of the very time consuming tests on AppVeyor as we hit 1h limit
1 parent 31de77d commit 554127b

File tree

8 files changed

+63
-31
lines changed

8 files changed

+63
-31
lines changed

appveyor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ os: Visual Studio 2022
2727
init:
2828
- git config --global core.autocrlf input
2929

30+
# add Visual C++ toolset to $path so NativeAOT tests can build native executables
31+
before_build:
32+
- call "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\Build\vcvars64.bat"
33+
3034
#---------------------------------#
3135
# build configuration #
3236
#---------------------------------#

build/Program.cs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using Cake.Common.IO;
99
using Cake.Common.Net;
1010
using Cake.Common.Tools.DotNet;
11+
using Cake.Common.Tools.DotNet.MSBuild;
12+
using Cake.Common.Tools.DotNet.Restore;
1113
using Cake.Common.Tools.DotNet.Run;
1214
using Cake.Common.Tools.DotNetCore.Build;
1315
using Cake.Common.Tools.DotNetCore.MSBuild;
@@ -93,18 +95,29 @@ public BuildContext(ICakeContext context)
9395
MaxCpuCount = 1
9496
};
9597
MsBuildSettings.WithProperty("UseSharedCompilation", "false");
98+
99+
// NativeAOT build requires VS C++ tools to be added to $path via vcvars64.bat
100+
// but once we do that, dotnet restore fails with:
101+
// "Please specify a valid solution configuration using the Configuration and Platform properties"
102+
if (context.IsRunningOnWindows())
103+
{
104+
MsBuildSettings.WithProperty("Platform", "Any CPU");
105+
}
96106
}
97107

98108
private DotNetCoreTestSettings GetTestSettingsParameters(FilePath logFile, string tfm)
99109
{
100-
return new DotNetCoreTestSettings
110+
var settings = new DotNetCoreTestSettings
101111
{
102112
Configuration = BuildConfiguration,
103113
Framework = tfm,
104114
NoBuild = true,
105115
NoRestore = true,
106116
Loggers = new[] { "trx", $"trx;LogFileName={logFile.FullPath}" }
107117
};
118+
// force the tool to not look for the .dll in platform-specific directory
119+
settings.EnvironmentVariables["Platform"] = "";
120+
return settings;
108121
}
109122

110123
public void RunTests(FilePath projectFile, string alias, string tfm)
@@ -260,7 +273,11 @@ public class RestoreTask : FrostingTask<BuildContext>
260273
{
261274
public override void Run(BuildContext context)
262275
{
263-
context.DotNetRestore(context.SolutionFile.FullPath);
276+
context.DotNetRestore(context.SolutionFile.FullPath,
277+
new DotNetRestoreSettings
278+
{
279+
MSBuildSettings = context.MsBuildSettings
280+
});
264281
}
265282
}
266283

@@ -349,12 +366,14 @@ public override void Run(BuildContext context)
349366
{
350367
Configuration = context.BuildConfiguration,
351368
OutputDirectory = context.ArtifactsDirectory.FullPath,
352-
ArgumentCustomization = args => args.Append("--include-symbols").Append("-p:SymbolPackageFormat=snupkg")
369+
ArgumentCustomization = args => args.Append("--include-symbols").Append("-p:SymbolPackageFormat=snupkg"),
370+
MSBuildSettings = context.MsBuildSettings
353371
};
354372
var settingsTemplate = new DotNetCorePackSettings
355373
{
356374
Configuration = context.BuildConfiguration,
357-
OutputDirectory = context.ArtifactsDirectory.FullPath
375+
OutputDirectory = context.ArtifactsDirectory.FullPath,
376+
MSBuildSettings = context.MsBuildSettings
358377
};
359378

360379
foreach (var project in context.AllPackableSrcProjects)

tests/BenchmarkDotNet.IntegrationTests/BuildTimeoutTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void WhenBuildTakesMoreTimeThanTheTimeoutTheBuildIsCancelled()
1919
{
2020
if (!RuntimeInformation.Is64BitPlatform()) // NativeAOT does not support 32bit yet
2121
return;
22-
if (GitHubActions.IsRunningOnWindows()) // no native dependencies installed
22+
if (ContinuousIntegration.IsGitHubActionsOnWindows()) // no native dependencies installed
2323
return;
2424

2525
// we use NativeAOT on purpose because it takes a LOT of time to build it
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using BenchmarkDotNet.Portability;
2+
using System;
3+
4+
namespace BenchmarkDotNet.IntegrationTests
5+
{
6+
internal static class ContinuousIntegration
7+
{
8+
internal static bool IsGitHubActionsOnWindows()
9+
=> RuntimeInformation.IsWindows() && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTION"));
10+
11+
internal static bool IsAppVeyorOnWindows()
12+
=> RuntimeInformation.IsWindows() && !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("APPVEYOR"));
13+
}
14+
}

tests/BenchmarkDotNet.IntegrationTests/GitHubActions.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,6 @@ public static IEnumerable<object[]> GetToolchains()
3838

3939
yield return new object[] { Job.Default.GetToolchain() };
4040
yield return new object[] { InProcessEmitToolchain.Instance };
41-
42-
#if !NETFRAMEWORK
43-
if (!GitHubActions.IsRunningOnWindows())
44-
{
45-
// we don't want to test NativeAOT twice (for .NET 4.6 and 5.0) when running the integration tests (these tests take a lot of time)
46-
// we test against specific version to keep this test stable
47-
yield return new object[] { NativeAotToolchain.CreateBuilder()
48-
.UseNuGet(
49-
"6.0.0-rc.1.21420.1",
50-
"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json").ToToolchain() };
51-
}
52-
#endif
5341
}
5442

5543
public class AccurateAllocations
@@ -76,6 +64,20 @@ public void MemoryDiagnoserIsAccurate(IToolchain toolchain)
7664
});
7765
}
7866

67+
[FactDotNetCoreOnly("We don't want to test NativeAOT twice (for .NET Framework 4.6.1 and .NET 6.0)")]
68+
public void MemoryDiagnoserSupportsNativeAOT()
69+
{
70+
if (ContinuousIntegration.IsGitHubActionsOnWindows())
71+
return;
72+
73+
MemoryDiagnoserIsAccurate(
74+
NativeAotToolchain.CreateBuilder()
75+
.UseNuGet(
76+
"6.0.0-rc.1.21420.1", // we test against specific version to keep this test stable
77+
"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json")
78+
.ToToolchain());
79+
}
80+
7981
public class AllocatingGlobalSetupAndCleanup
8082
{
8183
private List<int> list;

tests/BenchmarkDotNet.IntegrationTests/NativeAotTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ public void LatestNativeAotVersionIsSupported()
1818
{
1919
if (!RuntimeInformation.Is64BitPlatform()) // NativeAOT does not support 32bit yet
2020
return;
21-
if (GitHubActions.IsRunningOnWindows()) // no native dependencies installed
21+
if (ContinuousIntegration.IsGitHubActionsOnWindows()) // no native dependencies installed
22+
return;
23+
if (ContinuousIntegration.IsAppVeyorOnWindows()) // too time consuming for AppVeyor (1h limit)
2224
return;
2325

2426
var config = ManualConfig.CreateEmpty()

tests/BenchmarkDotNet.IntegrationTests/ThreadingDiagnoserTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@ public static IEnumerable<object[]> GetToolchains()
2929
{
3030
yield return new object[] { Job.Default.GetToolchain() };
3131

32-
if (!GitHubActions.IsRunningOnWindows())
32+
if (!ContinuousIntegration.IsGitHubActionsOnWindows() // no native dependencies
33+
&& !ContinuousIntegration.IsAppVeyorOnWindows()) // too time consuming for AppVeyor (1h limit)
34+
{
3335
yield return new object[]{ NativeAotToolchain.CreateBuilder()
3436
.UseNuGet(
3537
"6.0.0-rc.1.21420.1",
3638
"https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json").ToToolchain() };
39+
}
3740
// TODO: Support InProcessEmitToolchain.Instance
3841
// yield return new object[] { InProcessEmitToolchain.Instance };
3942
}

0 commit comments

Comments
 (0)