From 0b4630621ac3b76b654bc78c239df4f3761d87bc Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 16 Jun 2025 12:49:48 +0200 Subject: [PATCH 1/6] Add BuildClient package --- Compilers.slnf | 1 + Roslyn.sln | 7 +++++ eng/config/PublishData.json | 1 + .../Core/CommandLine/BuildProtocol.cs | 2 ++ .../Core/CommandLine/CompilerServerLogger.cs | 2 ++ .../Core/CommandLine/NativeMethods.cs | 2 ++ .../Core/Portable/InternalUtilities/Debug.cs | 2 ++ .../InternalUtilities/PlatformInformation.cs | 2 ++ src/Compilers/Shared/BuildServerConnection.cs | 2 ++ src/Compilers/Shared/NamedPipeUtil.cs | 2 ++ src/Compilers/Shared/RuntimeHostInfo.cs | 2 ++ ...ft.CodeAnalysis.BuildClient.Package.csproj | 30 +++++++++++++++++++ 12 files changed, 55 insertions(+) create mode 100644 src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj diff --git a/Compilers.slnf b/Compilers.slnf index 49acd2063d58..458efec9fbc6 100644 --- a/Compilers.slnf +++ b/Compilers.slnf @@ -53,6 +53,7 @@ "src\\ExpressionEvaluator\\Core\\Source\\ExpressionCompiler\\Microsoft.CodeAnalysis.ExpressionCompiler.csproj", "src\\ExpressionEvaluator\\VisualBasic\\Source\\ExpressionCompiler\\Microsoft.CodeAnalysis.VisualBasic.ExpressionCompiler.vbproj", "src\\Interactive\\csi\\csi.csproj", + "src\\NuGet\\Microsoft.CodeAnalysis.BuildClient.Package\\Microsoft.CodeAnalysis.BuildClient.Package.csproj", "src\\NuGet\\Microsoft.CodeAnalysis.Compilers.Package\\Microsoft.CodeAnalysis.Compilers.Package.csproj", "src\\NuGet\\Microsoft.CodeAnalysis.Package\\Microsoft.CodeAnalysis.Package.csproj", "src\\NuGet\\Microsoft.Net.Compilers.Toolset\\AnyCpu\\Microsoft.Net.Compilers.Toolset.Package.csproj", diff --git a/Roslyn.sln b/Roslyn.sln index 980009f1a1d5..27c924657d82 100644 --- a/Roslyn.sln +++ b/Roslyn.sln @@ -733,6 +733,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.Tasks.CodeA EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Build.Tasks.CodeAnalysis.Sdk.UnitTests", "src\Compilers\Core\SdkTaskTests\Microsoft.Build.Tasks.CodeAnalysis.Sdk.UnitTests.csproj", "{5399BBCC-417F-C710-46DE-EB0C0074C34D}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.BuildClient.Package", "src\NuGet\Microsoft.CodeAnalysis.BuildClient.Package\Microsoft.CodeAnalysis.BuildClient.Package.csproj", "{5E4F7448-B00B-4F5B-859F-6ED0354253D5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1807,6 +1809,10 @@ Global {5399BBCC-417F-C710-46DE-EB0C0074C34D}.Debug|Any CPU.Build.0 = Debug|Any CPU {5399BBCC-417F-C710-46DE-EB0C0074C34D}.Release|Any CPU.ActiveCfg = Release|Any CPU {5399BBCC-417F-C710-46DE-EB0C0074C34D}.Release|Any CPU.Build.0 = Release|Any CPU + {5E4F7448-B00B-4F5B-859F-6ED0354253D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5E4F7448-B00B-4F5B-859F-6ED0354253D5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5E4F7448-B00B-4F5B-859F-6ED0354253D5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5E4F7448-B00B-4F5B-859F-6ED0354253D5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -2150,6 +2156,7 @@ Global {1B4AC233-B345-123F-E004-DAA28DE1CB08} = {A41D1B99-F489-4C43-BBDF-96D61B19A6B9} {91F9EAA4-ACA2-87EE-868E-6CC3B73D6A11} = {A41D1B99-F489-4C43-BBDF-96D61B19A6B9} {5399BBCC-417F-C710-46DE-EB0C0074C34D} = {A41D1B99-F489-4C43-BBDF-96D61B19A6B9} + {5E4F7448-B00B-4F5B-859F-6ED0354253D5} = {C52D8057-43AF-40E6-A01B-6CDBB7301985} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {604E6B91-7BC0-4126-AE07-D4D2FEFC3D29} diff --git a/eng/config/PublishData.json b/eng/config/PublishData.json index e2ad4fac15ab..9727fa29ce65 100644 --- a/eng/config/PublishData.json +++ b/eng/config/PublishData.json @@ -31,6 +31,7 @@ "Microsoft.Net.Compilers.Toolset.Arm64": "arcade", "Microsoft.Net.Compilers.Toolset.Framework": "arcade", "Microsoft.NETCore.Compilers": "arcade", + "Microsoft.CodeAnalysis.BuildClient": "arcade", "Microsoft.CodeAnalysis.Contracts": "arcade", "Microsoft.CodeAnalysis.Debugging": "arcade", "Microsoft.CodeAnalysis.PooledObjects": "arcade", diff --git a/src/Compilers/Core/CommandLine/BuildProtocol.cs b/src/Compilers/Core/CommandLine/BuildProtocol.cs index e315beaf65a2..1bd920af986e 100644 --- a/src/Compilers/Core/CommandLine/BuildProtocol.cs +++ b/src/Compilers/Core/CommandLine/BuildProtocol.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable + using Roslyn.Utilities; using System; using System.Collections.Generic; diff --git a/src/Compilers/Core/CommandLine/CompilerServerLogger.cs b/src/Compilers/Core/CommandLine/CompilerServerLogger.cs index b0f2a0cb0df6..9f1a6a7f3f43 100644 --- a/src/Compilers/Core/CommandLine/CompilerServerLogger.cs +++ b/src/Compilers/Core/CommandLine/CompilerServerLogger.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable + using Roslyn.Utilities; using System; using System.Collections.Generic; diff --git a/src/Compilers/Core/CommandLine/NativeMethods.cs b/src/Compilers/Core/CommandLine/NativeMethods.cs index c5008b95be2d..647245ea2664 100644 --- a/src/Compilers/Core/CommandLine/NativeMethods.cs +++ b/src/Compilers/Core/CommandLine/NativeMethods.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Runtime.InteropServices; using System.Runtime.Versioning; diff --git a/src/Compilers/Core/Portable/InternalUtilities/Debug.cs b/src/Compilers/Core/Portable/InternalUtilities/Debug.cs index ebd3a10bf625..4468c0ac5266 100644 --- a/src/Compilers/Core/Portable/InternalUtilities/Debug.cs +++ b/src/Compilers/Core/Portable/InternalUtilities/Debug.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; diff --git a/src/Compilers/Core/Portable/InternalUtilities/PlatformInformation.cs b/src/Compilers/Core/Portable/InternalUtilities/PlatformInformation.cs index fbf447469915..559fc24c63aa 100644 --- a/src/Compilers/Core/Portable/InternalUtilities/PlatformInformation.cs +++ b/src/Compilers/Core/Portable/InternalUtilities/PlatformInformation.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.IO; using System.Runtime.Versioning; diff --git a/src/Compilers/Shared/BuildServerConnection.cs b/src/Compilers/Shared/BuildServerConnection.cs index 675771e47e06..91269cbf37c6 100644 --- a/src/Compilers/Shared/BuildServerConnection.cs +++ b/src/Compilers/Shared/BuildServerConnection.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Collections.Generic; using System.Diagnostics; diff --git a/src/Compilers/Shared/NamedPipeUtil.cs b/src/Compilers/Shared/NamedPipeUtil.cs index 0a45e71b27ba..50c2595610c3 100644 --- a/src/Compilers/Shared/NamedPipeUtil.cs +++ b/src/Compilers/Shared/NamedPipeUtil.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.IO; using System.IO.Pipes; diff --git a/src/Compilers/Shared/RuntimeHostInfo.cs b/src/Compilers/Shared/RuntimeHostInfo.cs index 26d11e2d2837..7ff9b16c7dfa 100644 --- a/src/Compilers/Shared/RuntimeHostInfo.cs +++ b/src/Compilers/Shared/RuntimeHostInfo.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +#nullable enable + using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; diff --git a/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj new file mode 100644 index 000000000000..461897245f21 --- /dev/null +++ b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj @@ -0,0 +1,30 @@ + + + + + + $(NetRoslynSourceBuild) + + + true + true + Microsoft.CodeAnalysis.BuildClient + false + + Package containing sources of Microsoft .NET Compiler Platform ("Roslyn") build client API. For internal use only. + + + + + + + + + + + + + + + + From f0494fad19f173971a07ad81f0722ccb96757543 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 16 Jun 2025 16:23:28 +0200 Subject: [PATCH 2/6] Allow sdk passing compiler hash --- src/Compilers/Shared/BuildServerConnection.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Compilers/Shared/BuildServerConnection.cs b/src/Compilers/Shared/BuildServerConnection.cs index 91269cbf37c6..e3e61d1b46ff 100644 --- a/src/Compilers/Shared/BuildServerConnection.cs +++ b/src/Compilers/Shared/BuildServerConnection.cs @@ -65,7 +65,8 @@ internal static BuildRequest CreateBuildRequest( string workingDirectory, string? tempDirectory, string? keepAlive, - string? libDirectory) + string? libDirectory, + string? compilerHash = null) { Debug.Assert(workingDirectory is object); @@ -74,7 +75,7 @@ internal static BuildRequest CreateBuildRequest( arguments, workingDirectory: workingDirectory, tempDirectory: tempDirectory, - compilerHash: BuildProtocolConstants.GetCommitHash() ?? "", + compilerHash: compilerHash ?? BuildProtocolConstants.GetCommitHash() ?? "", requestId: requestId, keepAlive: keepAlive, libDirectory: libDirectory); @@ -180,12 +181,6 @@ internal static async Task RunServerBuildRequestAsync( { Debug.Assert(pipeName is object); - // early check for the build hash. If we can't find it something is wrong; no point even trying to go to the server - if (string.IsNullOrWhiteSpace(BuildProtocolConstants.GetCommitHash())) - { - return new IncorrectHashBuildResponse(); - } - using var pipe = await tryConnectToServerAsync(pipeName, timeoutOverride, logger, tryCreateServerFunc, cancellationToken).ConfigureAwait(false); if (pipe is null) { From 0f82cdab5f07dafbfbdb9bcf590deaa238c9d0d1 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Tue, 17 Jun 2025 10:59:16 +0200 Subject: [PATCH 3/6] Reuse in Replay --- ...icrosoft.CodeAnalysis.BuildClient.Package.csproj | 12 +----------- .../Microsoft.CodeAnalysis.BuildClient.targets | 13 +++++++++++++ src/Tools/Replay/Replay.csproj | 11 +---------- 3 files changed, 15 insertions(+), 21 deletions(-) create mode 100644 src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.targets diff --git a/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj index 461897245f21..0dc3ded8398b 100644 --- a/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj +++ b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj @@ -15,16 +15,6 @@ - - - - - - - - - - - + diff --git a/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.targets b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.targets new file mode 100644 index 000000000000..1ff7664341fa --- /dev/null +++ b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.targets @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/Tools/Replay/Replay.csproj b/src/Tools/Replay/Replay.csproj index 519b8cf1b36e..180c31962b9f 100644 --- a/src/Tools/Replay/Replay.csproj +++ b/src/Tools/Replay/Replay.csproj @@ -7,16 +7,6 @@ - - - - - - - - - - csc @@ -41,4 +31,5 @@ + From 3ff6ebb5a31bbf00ee3b44b7f3a4aa8a2662b949 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Wed, 18 Jun 2025 12:05:33 +0200 Subject: [PATCH 4/6] Add a bit how we can and will break the APIs --- .../Microsoft.CodeAnalysis.BuildClient.Package.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj index 0dc3ded8398b..140c6b85b08c 100644 --- a/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj +++ b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.Package.csproj @@ -12,6 +12,7 @@ false Package containing sources of Microsoft .NET Compiler Platform ("Roslyn") build client API. For internal use only. + Relying on APIs from this package is explicitly not supported, they can and will break on a regular basis. From 055817428945f682865c4480c36c72edd27bcb54 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Wed, 18 Jun 2025 12:43:20 +0200 Subject: [PATCH 5/6] Move more files to the shared folder --- src/Compilers/CSharp/csc/CscCommandLine.projitems | 14 +++++++------- .../Core/MSBuildTask/Directory.Build.props | 10 +++++----- .../VBCSCompiler/VBCSCompilerCommandLine.projitems | 12 ++++++------ .../{Core/CommandLine => Shared}/BuildProtocol.cs | 0 .../CommandLine => Shared}/CompilerServerLogger.cs | 0 .../{Core/CommandLine => Shared}/ConsoleUtil.cs | 0 .../{Core/CommandLine => Shared}/NativeMethods.cs | 0 .../VisualBasic/vbc/VbcCommandLine.projitems | 12 ++++++------ .../Microsoft.CodeAnalysis.BuildClient.targets | 6 +++--- 9 files changed, 27 insertions(+), 27 deletions(-) rename src/Compilers/{Core/CommandLine => Shared}/BuildProtocol.cs (100%) rename src/Compilers/{Core/CommandLine => Shared}/CompilerServerLogger.cs (100%) rename src/Compilers/{Core/CommandLine => Shared}/ConsoleUtil.cs (100%) rename src/Compilers/{Core/CommandLine => Shared}/NativeMethods.cs (100%) diff --git a/src/Compilers/CSharp/csc/CscCommandLine.projitems b/src/Compilers/CSharp/csc/CscCommandLine.projitems index 3aef01cf38e3..90bc1372064f 100644 --- a/src/Compilers/CSharp/csc/CscCommandLine.projitems +++ b/src/Compilers/CSharp/csc/CscCommandLine.projitems @@ -18,16 +18,16 @@ CommandLine - - - - - - + - + + + + + + diff --git a/src/Compilers/Core/MSBuildTask/Directory.Build.props b/src/Compilers/Core/MSBuildTask/Directory.Build.props index 6c4c27e3282b..c2ed649d8b4e 100644 --- a/src/Compilers/Core/MSBuildTask/Directory.Build.props +++ b/src/Compilers/Core/MSBuildTask/Directory.Build.props @@ -23,13 +23,13 @@ - + + + + + - - - - diff --git a/src/Compilers/Server/VBCSCompiler/VBCSCompilerCommandLine.projitems b/src/Compilers/Server/VBCSCompiler/VBCSCompilerCommandLine.projitems index 395032d6c3f0..0034825a87d6 100644 --- a/src/Compilers/Server/VBCSCompiler/VBCSCompilerCommandLine.projitems +++ b/src/Compilers/Server/VBCSCompiler/VBCSCompilerCommandLine.projitems @@ -18,15 +18,15 @@ - - - - - - + + + + + + diff --git a/src/Compilers/Core/CommandLine/BuildProtocol.cs b/src/Compilers/Shared/BuildProtocol.cs similarity index 100% rename from src/Compilers/Core/CommandLine/BuildProtocol.cs rename to src/Compilers/Shared/BuildProtocol.cs diff --git a/src/Compilers/Core/CommandLine/CompilerServerLogger.cs b/src/Compilers/Shared/CompilerServerLogger.cs similarity index 100% rename from src/Compilers/Core/CommandLine/CompilerServerLogger.cs rename to src/Compilers/Shared/CompilerServerLogger.cs diff --git a/src/Compilers/Core/CommandLine/ConsoleUtil.cs b/src/Compilers/Shared/ConsoleUtil.cs similarity index 100% rename from src/Compilers/Core/CommandLine/ConsoleUtil.cs rename to src/Compilers/Shared/ConsoleUtil.cs diff --git a/src/Compilers/Core/CommandLine/NativeMethods.cs b/src/Compilers/Shared/NativeMethods.cs similarity index 100% rename from src/Compilers/Core/CommandLine/NativeMethods.cs rename to src/Compilers/Shared/NativeMethods.cs diff --git a/src/Compilers/VisualBasic/vbc/VbcCommandLine.projitems b/src/Compilers/VisualBasic/vbc/VbcCommandLine.projitems index 0ac1959f91e3..aab4e9fe2399 100644 --- a/src/Compilers/VisualBasic/vbc/VbcCommandLine.projitems +++ b/src/Compilers/VisualBasic/vbc/VbcCommandLine.projitems @@ -18,15 +18,15 @@ CommandLine - - - - - - + + + + + + diff --git a/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.targets b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.targets index 1ff7664341fa..d98ead6380e8 100644 --- a/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.targets +++ b/src/NuGet/Microsoft.CodeAnalysis.BuildClient.Package/Microsoft.CodeAnalysis.BuildClient.targets @@ -1,13 +1,13 @@ - - - + + + From 14fcc76126e46e409ce6792f7f2a739df78c4c58 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 23 Jun 2025 10:41:12 +0200 Subject: [PATCH 6/6] Use shared file list in build task --- src/Compilers/Core/MSBuildTask/Directory.Build.props | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/Compilers/Core/MSBuildTask/Directory.Build.props b/src/Compilers/Core/MSBuildTask/Directory.Build.props index c2ed649d8b4e..734b20b8f852 100644 --- a/src/Compilers/Core/MSBuildTask/Directory.Build.props +++ b/src/Compilers/Core/MSBuildTask/Directory.Build.props @@ -23,18 +23,9 @@ - - - - - - - - - @@ -68,4 +59,6 @@ contentFiles\any\any + +