Skip to content

Add a source package that can be used to connect to the roslyn build server #78986

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Jun 16, 2025

This package will be used by the SDK CLI to communicate with the build server (so dotnet run file.cs can skip MSBuild and "run csc directly" instead when possible - note that it cannot actually start csc.exe because process start overhead would negate any optimizations from skipping MSBuild). See dotnet/sdk#48011.

The set of files from the package is also used by the Replay tool to dogfood them in this repo (and to verify it is a coherent set of files).

@jjonescz jjonescz added the Feature - Run File #: and #! directives and file-based C# programs label Jun 17, 2025
@jjonescz jjonescz marked this pull request as ready for review June 17, 2025 15:57
@jjonescz jjonescz requested review from a team as code owners June 17, 2025 15:57
@jjonescz jjonescz requested a review from a team June 17, 2025 15:57
@@ -72,7 +75,7 @@ internal static BuildRequest CreateBuildRequest(
arguments,
workingDirectory: workingDirectory,
tempDirectory: tempDirectory,
compilerHash: BuildProtocolConstants.GetCommitHash() ?? "",
compilerHash: compilerHash ?? BuildProtocolConstants.GetCommitHash() ?? "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is it intended for the SDK to get the compiler hash?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to how BuildProtocolConstants.GetCommitHash would do it (look for CommitHashAttribute on a compiler dll). BuildProtocolConstants.GetCommitHash itself didn't work because this is a source package so the assembly is not the C# assembly but now I realized I can probably make that utility work by changing the assembly it looks at and then remove this parameter.

Copy link
Member Author

@jjonescz jjonescz Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now I realized I can probably make that utility work by changing the assembly it looks at and then remove this parameter.

I take this back, the utility is included as source in different projects and it's not possible to make it grab the CommitHash attribute from one assembly which all would reference, so probably best to keep as I have it now.

<Compile Include="$(MSBuildThisFileDirectory)..\..\Compilers\Core\Portable\InternalUtilities\PlatformInformation.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\Compilers\Shared\BuildServerConnection.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\Compilers\Shared\NamedPipeUtil.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\..\Compilers\Shared\RuntimeHostInfo.cs" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's always bugged me how this logic is spread out among so many files in different directories. Did you consider as part of this pulling it into a singe isolation directory?

Copy link
Member Author

@jjonescz jjonescz Jun 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I can move them all to the Shared directory.

Not sure if I should move those being shared from Compilers\Core\Portable as well - especially the InternalUtilities are referenced from many other projects and there is a lot of them (63 .cs files in InternalUtilities) and I'd expect we either move all or none of them. But now the Shared folder contains mostly build server protocol related files, but with InternalUtilities moved in this nice separation would be lost.

<PackageId>Microsoft.CodeAnalysis.BuildClient</PackageId>
<IncludeBuildOutput>false</IncludeBuildOutput>
<PackageDescription>
Package containing sources of Microsoft .NET Compiler Platform ("Roslyn") build client API. For internal use only.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a bit how we can and will break the APIs here.

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only intended consumers of this package are us and the sdk repo. Both of us have nullable on by default. Do we need these to be here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the sources from the source package are considered to be "generated code" due to this:

generated_code = true

and hence they need an explicit #nullable enable.

<Compile Include="$(MSBuildThisFileDirectory)..\CommandLine\BuildProtocol.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\CommandLine\ConsoleUtil.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\CommandLine\NativeMethods.cs" />
<Compile Include="$(MSBuildThisFileDirectory)..\CommandLine\CompilerServerLogger.cs" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we didn't have effectively the following instead of manually listig the files?

<Import Project="..\..\NuGet\Microsoft.CodeAnalysis.BuildClient.Package\Microsoft.CodeAnalysis.BuildClient.targets" />

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that can be done here. But for example in VBCSCompilerCommandLine.projitems which also shares some of these files, it can't be done since there would be conflicts (because it doesn't currently share all these files and some of the types it gets from the referenced projects, maybe that could be avoided as well, but it seems to be a deep rabbit hole).

@jjonescz jjonescz requested a review from jaredpar June 23, 2025 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Run File #: and #! directives and file-based C# programs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants