Skip to content

Commit 886c6b2

Browse files
authored
Build improvements, dynamic Windows SDK resolution, bugfixes (#661)
* Build improvements & dynamic Windows SDK resolution (backport from 3.0) * Changes to some code formatting * Fix build errors * Fix build error * Enhanced typedef-powered renaming * Fix #652 * Marshal generic pointers in COM vtable wrapper functions * String generation improvements (fixes #630) * Sanity check, remove JetBrains.Annotations
1 parent 0f983ad commit 886c6b2

File tree

2 files changed

+80
-52
lines changed

2 files changed

+80
-52
lines changed

src/infrastructure/Silk.NET.NUKE/Build.cs

Lines changed: 74 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System.Linq;
55
using System.Runtime.InteropServices;
66
using System.Threading.Tasks;
7-
using JetBrains.Annotations;
7+
88
using Nuke.Common;
99
using Nuke.Common.Execution;
1010
using Nuke.Common.IO;
@@ -92,7 +92,7 @@ bool HasDesktopMsBuild
9292

9393
[Solution] readonly Solution Solution;
9494

95-
[CanBeNull] Dictionary<string, (Solution Solution, bool UseDesktopMSBuild)> SolutionsValue;
95+
Dictionary<string, (Solution Solution, bool UseDesktopMSBuild)>? SolutionsValue;
9696

9797
Dictionary<string, (Solution Solution, bool UseDesktopMSBuild)> Solutions
9898
=> SolutionsValue ??= Projects.ProcessSolution(Solution, FeatureSets, HasDesktopMsBuild);
@@ -157,7 +157,7 @@ Dictionary<string, object> ProcessedMsbuildProperties
157157
"extension) to the AllowedExclusions array in the NUKE Build.cs file."
158158
);
159159

160-
missedOut.Add(file);
160+
missedOut.Add(Path.GetRelativePath(RootDirectory, file));
161161
}
162162
}
163163

@@ -180,6 +180,7 @@ Dictionary<string, object> ProcessedMsbuildProperties
180180
(
181181
() =>
182182
{
183+
var outputs = Enumerable.Empty<Output>();
183184
if (!HasProcessedSolutions)
184185
{
185186
var slnDir = Path.Combine(Solution.Directory!, "build", "sln");
@@ -202,21 +203,27 @@ Dictionary<string, object> ProcessedMsbuildProperties
202203
Logger.Info($"Cleaning feature set \"{key}\" ({sln})");
203204
if (useDesktopMsBuild)
204205
{
205-
MSBuild
206+
outputs = outputs.Concat
206207
(
207-
s => s.SetTargets("Clean")
208-
.SetMaxCpuCount(Environment.ProcessorCount)
209-
.SetProperties(ProcessedMsbuildProperties)
210-
.SetTargetPath(sln)
208+
MSBuild
209+
(
210+
s => s.SetTargets("Clean")
211+
.SetMaxCpuCount(Environment.ProcessorCount)
212+
.SetProperties(ProcessedMsbuildProperties)
213+
.SetTargetPath(sln)
214+
)
211215
);
212216
}
213217
else
214218
{
215-
DotNetClean
219+
outputs = outputs.Concat
216220
(
217-
s => s.SetProject(sln)
218-
.SetConfiguration(Configuration)
219-
.SetProperties(ProcessedMsbuildProperties)
221+
DotNetClean
222+
(
223+
s => s.SetProject(sln)
224+
.SetConfiguration(Configuration)
225+
.SetProperties(ProcessedMsbuildProperties)
226+
)
220227
);
221228
}
222229
}
@@ -228,12 +235,21 @@ Dictionary<string, object> ProcessedMsbuildProperties
228235

229236
Directory.CreateDirectory(RootDirectory / "build" / "output_packages");
230237

231-
var silkDroid = SourceDirectory / "Windowing" / "Android" / "SilkDroid";
232-
using var process = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
233-
? StartProcess("bash", "-c \"./gradlew clean\"", silkDroid)
234-
: StartProcess("cmd", "/c \".\\gradlew clean\"", silkDroid);
235-
process.AssertZeroExitCode();
236-
return process.Output;
238+
if (FeatureSets.Any(x => x.Equals("native", StringComparison.OrdinalIgnoreCase)))
239+
{
240+
var silkDroid = SourceDirectory / "Windowing" / "Android" / "SilkDroid";
241+
using var process = RuntimeInformation.IsOSPlatform(OSPlatform.Linux)
242+
? StartProcess("bash", "-c \"./gradlew clean\"", silkDroid)
243+
: StartProcess("cmd", "/c \".\\gradlew clean\"", silkDroid);
244+
process.AssertZeroExitCode();
245+
outputs = outputs.Concat(process.Output);
246+
}
247+
else
248+
{
249+
Logger.Warn("Skipping gradlew clean as the \"native\" feature-set has not been specified.");
250+
}
251+
252+
return outputs;
237253
}
238254
);
239255

@@ -300,7 +316,7 @@ Dictionary<string, object> ProcessedMsbuildProperties
300316
s => s
301317
.SetProjectFile(sln)
302318
.SetConfiguration(Configuration)
303-
.SetNoRestore(true)
319+
.EnableNoRestore()
304320
.SetProperties(ProcessedMsbuildProperties)
305321
);
306322
}
@@ -357,6 +373,12 @@ Dictionary<string, object> ProcessedMsbuildProperties
357373
(
358374
() =>
359375
{
376+
if (!FeatureSets.Any(x => x.Equals("native", StringComparison.OrdinalIgnoreCase)))
377+
{
378+
Logger.Warn("Skipping gradlew build as the \"native\" feature-set has not been specified.");
379+
return Enumerable.Empty<Output>();
380+
}
381+
360382
var sdl = RootDirectory / "build" / "submodules" / "SDL";
361383
var silkDroid = SourceDirectory / "Windowing" / "Android" / "SilkDroid";
362384
var xcopy = new (string, string)[]
@@ -425,7 +447,7 @@ Dictionary<string, object> ProcessedMsbuildProperties
425447
s => s
426448
.SetProject(sln)
427449
.SetConfiguration(Configuration)
428-
.SetNoRestore(true)
450+
.EnableNoRestore()
429451
.SetProperties(ProcessedMsbuildProperties)
430452
);
431453
}
@@ -448,21 +470,25 @@ Dictionary<string, object> ProcessedMsbuildProperties
448470
static IEnumerable<string> Packages => Directory.GetFiles(PackageDirectory, "*.nupkg")
449471
.Where(x => Path.GetFileName(x).StartsWith("Silk.NET") || Path.GetFileName(x).StartsWith("Ultz.Native"));
450472

451-
async Task PushPackages()
473+
async Task<IEnumerable<Output>> PushPackages()
452474
{
475+
var outputs = Enumerable.Empty<Output>();
453476
const int rateLimit = 300;
454477
if (!string.IsNullOrWhiteSpace(SignUsername) && !string.IsNullOrWhiteSpace(SignPassword))
455478
{
456479
var basePath = RootDirectory / "build" / "codesigning";
457480
var execPath = basePath / "tool" / (OperatingSystem.IsWindows() ? "SignClient.exe" : "SignClient");
458481
if (!File.Exists(execPath))
459482
{
460-
DotNetToolInstall(s => s.SetToolInstallationPath(basePath / "tool").SetPackageName("SignClient"));
483+
outputs = outputs.Concat
484+
(
485+
DotNetToolInstall(s => s.SetToolInstallationPath(basePath / "tool").SetPackageName("SignClient"))
486+
);
461487
}
462488

463489
foreach (var pkg in Packages)
464490
{
465-
StartProcess
491+
var proc = StartProcess
466492
(
467493
execPath,
468494
"sign " +
@@ -475,7 +501,10 @@ async Task PushPackages()
475501
"--name \"Silk.NET\" " +
476502
"--description \"Silk.NET\" " +
477503
"--descriptionUrl \"https://github.com/dotnet/Silk.NET\""
478-
).AssertZeroExitCode();
504+
);
505+
506+
proc.AssertZeroExitCode();
507+
outputs = outputs.Concat(proc.Output);
479508
}
480509
}
481510

@@ -484,11 +513,6 @@ async Task PushPackages()
484513
.Select(x => x.Select(v => v.Value).ToList())
485514
.ToList();
486515
var first = true;
487-
var pushed = 0;
488-
var feed = NuGetInterface.OpenNuGetFeed(NugetFeed, NugetUsername, NugetPassword);
489-
var uploadResource = await NuGetInterface.GetUploadResourceAsync(feed);
490-
var symbolsResource = await NuGetInterface.GetSymbolsUploadResourceAsync(feed);
491-
var exceptions = new List<Exception>();
492516
Logger.Info($"Searching for packages in \"{RootDirectory / "build" / "output_packages"}\"...");
493517
foreach (var files in allFiles)
494518
{
@@ -501,33 +525,33 @@ async Task PushPackages()
501525
await Task.Delay(TimeSpan.FromHours(1));
502526
}
503527

504-
foreach (var file in files)
528+
var srcSettings = new DotNetNuGetAddSourceSettings().SetName("Silk-PushPackages").SetSource(NugetFeed);
529+
if (NugetUsername is not null || NugetPassword is not null)
505530
{
506-
try
507-
{
508-
await NuGetInterface.UploadPackageAsync
509-
(uploadResource, NugetNoServiceEndpoint, file, NugetApiKey, symbolsResource);
510-
pushed++;
511-
}
512-
catch (Exception ex)
531+
if (NugetUsername is null || NugetPassword is null)
513532
{
514-
if (file.Contains(".Native.")) // native packages have their own update cycle
515-
{
516-
Logger.Warn(ex);
517-
}
518-
else
519-
{
520-
exceptions.Add(new Exception($"Failed to push package \"{file}\"", ex));
521-
}
533+
ControlFlow.Fail
534+
(
535+
"Both \"NugetUsername\" and \"NugetPassword\" must be specified if either are used."
536+
);
522537
}
538+
539+
srcSettings = srcSettings.SetUsername(NugetUsername).SetPassword(NugetPassword);
523540
}
524-
}
541+
542+
outputs = outputs.Concat(DotNetNuGetAddSource(srcSettings));
525543

526-
Logger.Success($"Successfully pushed {pushed} packages.");
544+
foreach (var pushSettings in files.Select(file => new DotNetNuGetPushSettings()
545+
.SetNoServiceEndpoint(NugetNoServiceEndpoint)
546+
.EnableSkipDuplicate()
547+
.SetTargetPath(file)))
548+
{
549+
outputs = outputs.Concat(DotNetNuGetPush(pushSettings));
550+
}
527551

528-
if (exceptions.Count > 0)
529-
{
530-
throw new AggregateException(exceptions);
552+
outputs = outputs.Concat(DotNet($"dotnet nuget remove source \"Silk-PushPackages\""));
531553
}
554+
555+
return outputs;
532556
}
533557
}

src/infrastructure/Silk.NET.NUKE/Projects.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using System.Collections.Generic;
66
using System.IO;
77
using System.Linq;
8-
using JetBrains.Annotations;
8+
99
using Nuke.Common;
1010
using Nuke.Common.IO;
1111
using Nuke.Common.ProjectModel;
@@ -65,7 +65,11 @@ bool hasDesktopMsBuild
6565
}
6666

6767
var sln = ParseSolution(originalSolutionPath);
68-
featureSetSpecificSolutions[featureSet.Name] = (sln, featureSet.RequiresDesktopMsBuild);
68+
if (featureSetUsed)
69+
{
70+
featureSetSpecificSolutions[featureSet.Name] = (sln, featureSet.RequiresDesktopMsBuild);
71+
}
72+
6973
foreach (var removal in rm)
7074
{
7175
sln.RemoveProject(sln.GetProject(removal));

0 commit comments

Comments
 (0)