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

RAR-as-a-service draft #11153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
29 changes: 29 additions & 0 deletions MSBuild.sln
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.BuildCheck.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.Templates", "template_feed\Microsoft.Build.Templates.csproj", "{A86EE74A-AEF0-42ED-A5A7-7A54BC0773D8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4D013D5D-E085-4F4F-B36B-9484F7E51657}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RarTest", "src\RarTest\RarTest.csproj", "{20D438A5-B93B-4972-BFAD-373954BD6117}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -916,6 +920,30 @@ Global
{A86EE74A-AEF0-42ED-A5A7-7A54BC0773D8}.Release|x64.Build.0 = Release|Any CPU
{A86EE74A-AEF0-42ED-A5A7-7A54BC0773D8}.Release|x86.ActiveCfg = Release|Any CPU
{A86EE74A-AEF0-42ED-A5A7-7A54BC0773D8}.Release|x86.Build.0 = Release|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.Debug|Any CPU.Build.0 = Debug|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.Debug|ARM64.ActiveCfg = Debug|arm64
{20D438A5-B93B-4972-BFAD-373954BD6117}.Debug|ARM64.Build.0 = Debug|arm64
{20D438A5-B93B-4972-BFAD-373954BD6117}.Debug|x64.ActiveCfg = Debug|x64
{20D438A5-B93B-4972-BFAD-373954BD6117}.Debug|x64.Build.0 = Debug|x64
{20D438A5-B93B-4972-BFAD-373954BD6117}.Debug|x86.ActiveCfg = Debug|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.Debug|x86.Build.0 = Debug|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.MachineIndependent|Any CPU.ActiveCfg = MachineIndependent|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.MachineIndependent|Any CPU.Build.0 = MachineIndependent|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.MachineIndependent|ARM64.ActiveCfg = MachineIndependent|arm64
{20D438A5-B93B-4972-BFAD-373954BD6117}.MachineIndependent|ARM64.Build.0 = MachineIndependent|arm64
{20D438A5-B93B-4972-BFAD-373954BD6117}.MachineIndependent|x64.ActiveCfg = MachineIndependent|x64
{20D438A5-B93B-4972-BFAD-373954BD6117}.MachineIndependent|x64.Build.0 = MachineIndependent|x64
{20D438A5-B93B-4972-BFAD-373954BD6117}.MachineIndependent|x86.ActiveCfg = MachineIndependent|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.MachineIndependent|x86.Build.0 = MachineIndependent|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.Release|Any CPU.ActiveCfg = Release|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.Release|Any CPU.Build.0 = Release|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.Release|ARM64.ActiveCfg = Release|arm64
{20D438A5-B93B-4972-BFAD-373954BD6117}.Release|ARM64.Build.0 = Release|arm64
{20D438A5-B93B-4972-BFAD-373954BD6117}.Release|x64.ActiveCfg = Release|x64
{20D438A5-B93B-4972-BFAD-373954BD6117}.Release|x64.Build.0 = Release|x64
{20D438A5-B93B-4972-BFAD-373954BD6117}.Release|x86.ActiveCfg = Release|Any CPU
{20D438A5-B93B-4972-BFAD-373954BD6117}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -934,6 +962,7 @@ Global
{B60173F0-F9F0-4688-9DF8-9ADDD57BD45F} = {9BAD9352-DEFB-45E5-B8A4-4816B9B22A33}
{F47E1A0A-7D81-40CF-B8B3-A0F4B5ADE943} = {760FF85D-8BEB-4992-8095-A9678F88FD47}
{71E59632-D644-491B-AF93-22BC93167C56} = {9BAD9352-DEFB-45E5-B8A4-4816B9B22A33}
{20D438A5-B93B-4972-BFAD-373954BD6117} = {4D013D5D-E085-4F4F-B36B-9484F7E51657}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F948D667-14E3-4F98-BA50-3F3C948BF4C2}
Expand Down
1 change: 1 addition & 0 deletions eng/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<PackageVersion Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
<PackageVersion Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerVersion)" />
<PackageVersion Include="System.Formats.Asn1" Version="$(SystemFormatsAsn1Version)" />
<PackageVersion Include="System.IO.Hashing" Version="$(SystemIOHashingVersion)" />
<PackageVersion Include="System.Memory" Version="$(SystemMemoryVersion)" />
<PackageVersion Include="System.Net.Http" Version="$(SystemNetHttpVersion)" />
<PackageVersion Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
Expand Down
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
When updating the version of System.Memory file a breaking change here: https://github.com/dotnet/docs/issues/new?assignees=gewarren&labels=breaking-change%2CPri1%2Cdoc-idea&template=breaking-change.yml&title=%5BBreaking+change%5D%3A+
and follow the guidelines written here (internal-link): https://dev.azure.com/devdiv/DevDiv/_wiki/wikis/DevDiv.wiki/1796/How-to-add-a-Known-Issue
-->
<SystemIOHashingVersion>8.0.0</SystemIOHashingVersion>
<SystemMemoryVersion>4.5.5</SystemMemoryVersion>
<SystemNetHttpVersion>4.3.4</SystemNetHttpVersion>
<SystemReflectionMetadataLoadContextVersion>8.0.0</SystemReflectionMetadataLoadContextVersion>
Expand Down
77 changes: 77 additions & 0 deletions src/Build/BackEnd/Components/Communications/RarNodeLauncher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Security.Principal;
using System.Threading;
using Microsoft.Build.BackEnd;
using Microsoft.Build.Framework;
using Microsoft.Build.Framework.Telemetry;
using Microsoft.Build.Internal;
using Microsoft.Build.Shared;

namespace Microsoft.Build.BackEnd.Client
{
public sealed class RarNodeLauncher
{
public static void LaunchServer()
{
CommunicationsUtilities.Trace("Checking for RAR server...");
RarNodeHandshake handshake = new(HandshakeOptions.None);

if (IsPipeExists(handshake))
{
CommunicationsUtilities.Trace($"Existing RAR server found.");
return;
}

string serverLaunchMutexName = $@"Global\msbuild-rar-server-launch-{handshake.ComputeHash()}";

// Then, check if another MSBuild process has started the server launch.
// This accounts for any delay between the server starting and opening its mutex.
using Mutex serverLaunchMutex = new(
initiallyOwned: true,
name: serverLaunchMutexName,
createdNew: out bool createdNew);

if (!createdNew)
{
CommunicationsUtilities.Trace("Another process launching the RAR server.");
return;
}

CommunicationsUtilities.Trace("Starting Server...");

string msbuildLocation = BuildEnvironmentHelper.Instance.CurrentMSBuildExePath;
string commandLineArgs = string.Join(" ", ["/nologo", "/nodemode:3"]);

NodeLauncher nodeLauncher = new();
Process msbuildProcess = nodeLauncher.Start(msbuildLocation, commandLineArgs, nodeId: 0);

CommunicationsUtilities.Trace("RAR Server started with PID: {0}", msbuildProcess.Id);
}

private static bool IsPipeExists(RarNodeHandshake handshake)
{
string[] pipes = Directory.GetFiles(@"\\.\pipe\");

return pipes.Contains(Path.Combine(@"\\.\pipe\", $"msbuild-rar-{handshake.ComputeHash()}"));
}

private static bool IsServerRunning(ServerNodeHandshake handshake)
{
string serverRunningMutexName = $@"Global\msbuild-rar-server-running-{handshake.ComputeHash()}";

// First, check if the server has created the mutex.
// Use a mutex to avoid using a timeout or checking a max pipe instance exception.
bool isRunning = Mutex.TryOpenExisting(serverRunningMutexName, out Mutex? mutex);
mutex?.Dispose();

return isRunning;
}
}
}
1 change: 1 addition & 0 deletions src/Build/Microsoft.Build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<Compile Include="BackEnd\Components\ProjectCache\*.cs" />
<Compile Include="BackEnd\Components\Communications\CurrentHost.cs" />
<Compile Include="BackEnd\Components\Communications\DetouredNodeLauncher.cs" />
<Compile Include="BackEnd\Components\Communications\RarNodeLauncher.cs" />
<Compile Include="BackEnd\Components\Communications\SerializationContractInitializer.cs" />
<Compile Include="BackEnd\Components\Communications\ServerNodeEndpointOutOfProc.cs" />
<Compile Include="BackEnd\Components\FileAccesses\IFileAccessManager.cs" />
Expand Down
5 changes: 5 additions & 0 deletions src/Framework/Traits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public Traits()
/// </summary>
public const string UseMSBuildServerEnvVarName = "MSBUILDUSESERVER";

/// <summary>
/// Internally set if ResolveAssemblyReference tasks should forward requests to the out-of-proc node.
/// </summary>
public const string ExecuteRAROutOFProcessEnvVarName = "MSBUILDEXECUTERAROUTOFPROC";

public readonly bool DebugEngine = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("MSBuildDebugEngine"));
public readonly bool DebugScheduler;
public readonly bool DebugNodeCommunication;
Expand Down
1 change: 1 addition & 0 deletions src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@ public void InvalidToolsVersionErrors()
lowPriority: false,
question: false,
isBuildCheckEnabled: false,
enableRarService: false,
inputResultsCaches: null,
outputResultsCache: null,
saveProjectResult: false,
Expand Down
2 changes: 2 additions & 0 deletions src/MSBuild/CommandLineSwitches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ internal enum ParameterizedSwitch
GetTargetResult,
GetResultOutputFile,
FeatureAvailability,
EnableRarService,
// This has to be kept as last enum value
NumberOfParameterizedSwitches,
}
Expand Down Expand Up @@ -296,6 +297,7 @@ internal ParameterizedSwitchInfo(
new ParameterizedSwitchInfo( ["getItem"],  ParameterizedSwitch.GetItem, null, true, "MissingGetItemError", true, false, "HelpMessage_44_GetItemSwitch"),
new ParameterizedSwitchInfo( ["getTargetResult"],  ParameterizedSwitch.GetTargetResult, null, true, "MissingGetTargetResultError", true, false, "HelpMessage_45_GetTargetResultSwitch"),
new ParameterizedSwitchInfo( ["getResultOutputFile"],  ParameterizedSwitch.GetResultOutputFile, null, true, "MissingGetResultFileError", true, false, "HelpMessage_51_GetResultOutputFileSwitch"),
new ParameterizedSwitchInfo( ["enableRarService"], ParameterizedSwitch.EnableRarService, null, true, null, true, false, "HelpMessage_53_EnableRarServiceSwitch"),
new ParameterizedSwitchInfo( ["featureAvailability", "fa"],  ParameterizedSwitch.FeatureAvailability, null, true, "MissingFeatureAvailabilityError", true, false, "HelpMessage_46_FeatureAvailabilitySwitch")
};

Expand Down
1 change: 1 addition & 0 deletions src/MSBuild/MSBuild/Microsoft.Build.CommonTypes.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -3322,6 +3322,7 @@ elementFormDefault="qualified">
<xs:attribute name="ProfileName" />
<xs:attribute name="PublicKeysRestrictedForGlobalLocation" />
<xs:attribute name="SearchPaths" use="required" />
<xs:attribute name="ShouldExecuteInProcess" type="msb:boolean" />
<xs:attribute name="Silent" type="msb:boolean" />
<xs:attribute name="StateFile" />
<xs:attribute name="TargetedRuntimeVersion" />
Expand Down
22 changes: 21 additions & 1 deletion src/MSBuild/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1052,6 +1052,18 @@
LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars.
</comment>
</data>
<data name="HelpMessage_53_EnableRarServiceSwitch" xml:space="preserve">
<value> -rarService[:True|False]
Causes MSBuild to run a persistent service for the ResolveAssemblyReference task.

This flag is experimental and may not work as intended.
</value>
<comment>
LOCALIZATION: "MSBuild" should not be localized.
LOCALIZATION: "-rarService" should not be localized.
LOCALIZATION: None of the lines should be longer than a standard width console window, eg 80 chars.
</comment>
</data>
<data name="InvalidConfigurationFile" xml:space="preserve">
<value>MSBUILD : Configuration error MSB1043: The application could not start. {0}</value>
<comment>
Expand Down Expand Up @@ -1496,6 +1508,14 @@
LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized.
</comment>
</data>
<data name="InvalidRarServiceValue" xml:space="preserve">
<value>MSBUILD : error MSB1069: Enable RAR service value is not valid. {0}.</value>
<comment>{StrBegin="MSBUILD : error MSB1069: "}
UE: This message does not need in-line parameters because the exception takes care of displaying the invalid arg.
This error is shown when a user specifies a node reuse value that is not equivilant to Boolean.TrueString or Boolean.FalseString.
LOCALIZATION: The prefix "MSBUILD : error MSBxxxx:" should not be localized.
</comment>
</data>
<data name="InvalidPreprocessPath" xml:space="preserve">
<value>MSBUILD : error MSB1047: File to preprocess to is not valid. {0}</value>
<comment>{StrBegin="MSBUILD : error MSB1047: "}</comment>
Expand Down Expand Up @@ -1812,7 +1832,7 @@
<!--
The command line message bucket is: MSB1001 - MSB1999

Next error code should be MSB1069.
Next error code should be MSB1070.

Don't forget to update this comment after using the new code.
-->
Expand Down
26 changes: 26 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions src/MSBuild/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading