From d10ef5c16754d0318c81cba6ab0619cbba7ff597 Mon Sep 17 00:00:00 2001 From: Aishwarya Bhandari Date: Wed, 25 Sep 2024 12:16:18 -0700 Subject: [PATCH] trying to parallelize build steps --- build/BuildSteps.cs | 66 +++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/build/BuildSteps.cs b/build/BuildSteps.cs index 5c4d13fe1..6127e8fff 100644 --- a/build/BuildSteps.cs +++ b/build/BuildSteps.cs @@ -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; @@ -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> 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)) { @@ -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)); @@ -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 GetUnsignedBinaries(string targetDir) @@ -829,5 +836,30 @@ private static PackageInfo NewPackageInfo(string packageInfo) return new PackageInfo(Name: parts[0], Version: parts[1]); } + + /// + /// 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"] + /// + private static Dictionary> BuildRuntimeIdsToRuntimeMapping() + { + var ridsToRuntimesMap = new Dictionary>(); + foreach (var runtime in Settings.TargetRuntimes) + { + var rid = GetRuntimeId(runtime); + + if (!ridsToRuntimesMap.ContainsKey(rid)) + { + ridsToRuntimesMap[rid] = new List { runtime }; + } + else + { + ridsToRuntimesMap[rid].Add(runtime); + } + } + + return ridsToRuntimesMap; + } } }