-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[IBuildEngine callbacks] Stage 2: RequestCores/ReleaseCores #13306
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
Merged
JanProvaznik
merged 7 commits into
dotnet:main
from
JanProvaznik:ibuildengine-callbacks-stage2
Mar 2, 2026
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c05e655
Add TaskHostCoresRequest/Response packets for RequestCores/ReleaseCores
JanProvaznik 48f88d7
Implement RequestCores/ReleaseCores in OutOfProcTaskHostNode
JanProvaznik 8b5c6ca
Handle RequestCores/ReleaseCores requests in TaskHostTask
JanProvaznik 0292ea0
Add RequestCoresTask and E2E test project for cross-runtime testing
JanProvaznik 89594d2
Add tests for RequestCores/ReleaseCores callback
JanProvaznik f348df1
Update src/Build.UnitTests/TestAssets/ExampleNetTask/TestNetTaskResou…
JanProvaznik 7138fac
Merge branch 'main' into ibuildengine-callbacks-stage2
JanProvaznik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.Utilities; | ||
|
|
||
| namespace Microsoft.Build.UnitTests.BackEnd | ||
| { | ||
| /// <summary> | ||
| /// A test task that calls IBuildEngine9.RequestCores and optionally ReleaseCores. | ||
| /// Used by TaskHostCallback_Tests (in-process) and NetTaskHost_E2E_Tests (cross-runtime). | ||
| /// The E2E project includes this file via linked compile to avoid duplication. | ||
| /// </summary> | ||
| public class RequestCoresTask : Task | ||
| { | ||
| /// <summary> | ||
| /// Number of cores to request. Defaults to 1. | ||
| /// </summary> | ||
| public int CoreCount { get; set; } = 1; | ||
|
|
||
| /// <summary> | ||
| /// Whether to release the granted cores after requesting them. | ||
| /// </summary> | ||
| public bool ReleaseAfter { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Number of cores granted by the build engine. | ||
| /// </summary> | ||
| [Output] | ||
| public int GrantedCores { get; set; } | ||
|
|
||
| public override bool Execute() | ||
| { | ||
| if (BuildEngine is IBuildEngine9 engine9) | ||
| { | ||
| GrantedCores = engine9.RequestCores(CoreCount); | ||
| Log.LogMessage(MessageImportance.High, $"RequestCores({CoreCount}) = {GrantedCores}"); | ||
|
|
||
| if (ReleaseAfter && GrantedCores > 0) | ||
| { | ||
| engine9.ReleaseCores(GrantedCores); | ||
| Log.LogMessage(MessageImportance.High, $"ReleaseCores({GrantedCores}) completed"); | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| Log.LogError("BuildEngine does not implement IBuildEngine9"); | ||
| return false; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
.../TestAssets/ExampleNetTask/TestNetTaskResourceCallback/TestNetTaskResourceCallback.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>$(LatestDotNetCoreForMSBuild)</TargetFramework> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <TestProjectFolder>$([System.IO.Path]::GetFullPath('$([System.IO.Path]::Combine('$(MSBuildThisFileDirectory)', '..', '..', '..', '..'))'))</TestProjectFolder> | ||
| <ExampleTaskPath>$([System.IO.Path]::Combine('$(TestProjectFolder)', '$(TargetFramework)', 'ExampleTask.dll'))</ExampleTaskPath> | ||
| </PropertyGroup> | ||
|
|
||
| <UsingTask | ||
| TaskName="Microsoft.Build.UnitTests.BackEnd.RequestCoresTask" | ||
| AssemblyFile="$(ExampleTaskPath)" | ||
| TaskFactory="TaskHostFactory" | ||
| Runtime="NET"/> | ||
|
|
||
| <Target Name="TestTask" BeforeTargets="Build"> | ||
| <Microsoft.Build.UnitTests.BackEnd.RequestCoresTask CoreCount="2" ReleaseAfter="true"> | ||
| <Output PropertyName="Granted" TaskParameter="GrantedCores" /> | ||
| </Microsoft.Build.UnitTests.BackEnd.RequestCoresTask> | ||
| <Message Text="CallbackResult: RequestCores(2) = $(Granted)" Importance="high" /> | ||
| </Target> | ||
|
|
||
| </Project> |
2 changes: 2 additions & 0 deletions
2
src/Build.UnitTests/TestAssets/ExampleNetTask/TestNetTaskResourceCallback/global.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| { | ||
|
JanProvaznik marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.