Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[msbuild] Limit the number of concurrent AOT compilers to the number of processors. #18793

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[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: #17825
  • Loading branch information
rolfbjarne committed Aug 23, 2023
commit 19d89cf206f517a11c4ddd735bdd297c156d6701
18 changes: 11 additions & 7 deletions msbuild/Xamarin.MacDev.Tasks/Tasks/AOTCompileTaskBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,13 @@ public override bool Execute ()
Directory.CreateDirectory (OutputDirectory);

var aotAssemblyFiles = new List<ITaskItem> ();
var processes = new Task<Execution> [assembliesToAOT.Length];

var environment = new Dictionary<string, string?> {
{ "MONO_PATH", Path.GetFullPath (InputDirectory) },
};

var globalAotArguments = AotArguments?.Select (v => v.ItemSpec).ToList ();
var listOfArguments = new List<(IList<string> Arguments, string Input)> ();
for (var i = 0; i < assembliesToAOT.Length; i++) {
var asm = assembliesToAOT [i];
var input = asm.GetMetadata ("Input");
Expand Down Expand Up @@ -212,16 +212,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 (MSBStrings.E7118 /* Failed to AOT compile {0}, the AOT compiler exited with code {1} */, Path.GetFileName (input), v.Result.ExitCode);
Log.LogError (MSBStrings.E7118 /* 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<Execution> (v.Result);
}).Unwrap ();
}

System.Threading.Tasks.Task.WaitAll (processes);
})
.Unwrap ()
.Wait ();
});

AssemblyFiles = aotAssemblyFiles.ToArray ();

Expand Down