From 2581f0cdb9bcccb7846206b67ce10e5765f83496 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 23 Aug 2023 08:16:15 +0200 Subject: [PATCH 1/2] [release/7.0.3xx] [msbuild] Limit the number of concurrent AOT compilers to the number of processors. This might fix #17825, but even if it doesn't, it's a good thing to do to not overload machines. Ref: https://github.com/xamarin/xamarin-macios/issues/17825 Backport of #18793. --- .../Tasks/AOTCompileTaskBase.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs index beb864411e16..be7dd0997d9b 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs @@ -67,13 +67,13 @@ public override bool Execute () Directory.CreateDirectory (OutputDirectory); var aotAssemblyFiles = new List (); - var processes = new Task [Assemblies.Length]; var environment = new Dictionary { { "MONO_PATH", Path.GetFullPath (InputDirectory) }, }; var globalAotArguments = AotArguments?.Select (v => v.ItemSpec).ToList (); + var listOfArguments = new List<(IList Arguments, string Input)> (); for (var i = 0; i < Assemblies.Length; i++) { var asm = Assemblies [i]; var input = inputs [i]; @@ -103,16 +103,20 @@ public override bool Execute () arguments.AddRange (parsedProcessArguments); arguments.Add (input); - processes [i] = ExecuteAsync (AOTCompilerPath, arguments, environment: environment, sdkDevPath: SdkDevPath, showErrorIfFailure: false /* we show our own error below */) + listOfArguments.Add (new (arguments, input)); + } + + Parallel.ForEach (listOfArguments, (arg) => { + ExecuteAsync (AOTCompilerPath, arg.Arguments, environment: environment, sdkDevPath: SdkDevPath, showErrorIfFailure: false /* we show our own error below */) .ContinueWith ((v) => { if (v.Result.ExitCode != 0) Log.LogError ("Failed to AOT compile {0}, the AOT compiler exited with code {1}", Path.GetFileName (input), v.Result.ExitCode); return System.Threading.Tasks.Task.FromResult (v.Result); - }).Unwrap (); - } - - System.Threading.Tasks.Task.WaitAll (processes); + }) + .Unwrap () + .Wait (); + }); AssemblyFiles = aotAssemblyFiles.ToArray (); From ac3c99497cf2013a97ceb3e71851f667579c86c7 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 25 Aug 2023 08:54:24 +0200 Subject: [PATCH 2/2] Fix build. --- msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs b/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs index be7dd0997d9b..752b2606135d 100644 --- a/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs +++ b/msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs @@ -110,7 +110,7 @@ public override bool Execute () ExecuteAsync (AOTCompilerPath, arg.Arguments, environment: environment, sdkDevPath: SdkDevPath, showErrorIfFailure: false /* we show our own error below */) .ContinueWith ((v) => { if (v.Result.ExitCode != 0) - Log.LogError ("Failed to AOT compile {0}, the AOT compiler exited with code {1}", Path.GetFileName (input), v.Result.ExitCode); + Log.LogError ("Failed to AOT compile {0}, the AOT compiler exited with code {1}", Path.GetFileName (arg.Input), v.Result.ExitCode); return System.Threading.Tasks.Task.FromResult (v.Result); })