Skip to content

Commit

Permalink
trying to parallelize build steps
Browse files Browse the repository at this point in the history
  • Loading branch information
aishwaryabh committed Sep 25, 2024
1 parent 9aa82fa commit d10ef5c
Showing 1 changed file with 49 additions and 17 deletions.
66 changes: 49 additions & 17 deletions build/BuildSteps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Colors.Net;
using Colors.Net.StringColorExtensions;
using Microsoft.WindowsAzure.Storage;
Expand Down Expand Up @@ -110,23 +111,29 @@ public static void DotnetPack()

public static void DotnetPublishForZips()
{
foreach (var runtime in Settings.TargetRuntimes)
// Get the unique rids, so that we can parallelize the publish process.
Dictionary<string, IList<string>> ridsToRuntimes = BuildRuntimeIdsToRuntimeMapping();
Parallel.ForEach(ridsToRuntimes.Keys, rid =>
{
var isMinVersion = runtime.StartsWith(Settings.MinifiedVersionPrefix);
var outputPath = Path.Combine(Settings.OutputDir, runtime);
var rid = GetRuntimeId(runtime);

ExecuteDotnetPublish(outputPath, rid, "net8.0", skipLaunchingNet8ChildProcess: isMinVersion);
if (isMinVersion)
// We can only parallize the rid level.
var runtimesInThisGroup = ridsToRuntimes[rid];
foreach (var runtime in runtimesInThisGroup)
{
RemoveLanguageWorkers(outputPath);
}
var isMinVersion = runtime.StartsWith(Settings.MinifiedVersionPrefix);
var outputPath = Path.Combine(Settings.OutputDir, runtime);

// Publish net8 version of the artifact as well.
var outputPathNet8 = BuildNet8ArtifactFullPath(runtime);
ExecuteDotnetPublish(outputPathNet8, rid, "net8.0", skipLaunchingNet8ChildProcess: true);
RemoveLanguageWorkers(outputPathNet8);
}
ExecuteDotnetPublish(outputPath, rid, "net8.0", skipLaunchingNet8ChildProcess: isMinVersion);
if (isMinVersion)
{
RemoveLanguageWorkers(outputPath);
}

// Publish net8 version of the artifact as well.
var outputPathNet8 = BuildNet8ArtifactFullPath(runtime);
ExecuteDotnetPublish(outputPathNet8, rid, "net8.0", skipLaunchingNet8ChildProcess: true);
RemoveLanguageWorkers(outputPathNet8);
}
});

if (!string.IsNullOrEmpty(Settings.IntegrationBuildNumber) && (_integrationManifest != null))
{
Expand Down Expand Up @@ -465,12 +472,12 @@ public static void TestSignedArtifacts()
{
string[] zipFiles = Directory.GetFiles(Settings.OutputDir, "*.zip");

foreach (string zipFilePath in zipFiles)
Parallel.ForEach(zipFiles, zipFilePath =>
{
if (zipFilePath.Contains("osx"))
{
// sigcheck.exe does not work for mac signatures
continue;
return;
}

bool isSignedRuntime = Settings.SignInfo.RuntimesToSign.Any(r => zipFilePath.Contains(r));
Expand All @@ -488,7 +495,7 @@ public static void TestSignedArtifacts()
throw new Exception($"sigcheck.exe test failed. Following files are unsigned: {Environment.NewLine}{missingSignature}");
}
}
}
});
}

public static List<string> GetUnsignedBinaries(string targetDir)
Expand Down Expand Up @@ -829,5 +836,30 @@ private static PackageInfo NewPackageInfo(string packageInfo)

return new PackageInfo(Name: parts[0], Version: parts[1]);
}

/// <summary>
/// Builds a dictionary of runtimeIds to runtimes.
/// Key will be rid and value will be an array of runtimes for that rid.
/// ex entry: "win-x64": ["win-x64", "min.win-x64"]
/// </summary>
private static Dictionary<string, IList<string>> BuildRuntimeIdsToRuntimeMapping()
{
var ridsToRuntimesMap = new Dictionary<string, IList<string>>();
foreach (var runtime in Settings.TargetRuntimes)
{
var rid = GetRuntimeId(runtime);

if (!ridsToRuntimesMap.ContainsKey(rid))
{
ridsToRuntimesMap[rid] = new List<string> { runtime };
}
else
{
ridsToRuntimesMap[rid].Add(runtime);
}
}

return ridsToRuntimesMap;
}
}
}

0 comments on commit d10ef5c

Please sign in to comment.