Skip to content

Commit f154049

Browse files
authored
Use apphost for core compiler (#80026)
* Use apphost for core compiler * Remove unused members * Include executables in the toolset package * Avoid missing apphosts in source build * Improve setting DOTNET_ROOT * Skip invalid test combinations * Fix linux and remove opt-out * Fix tests * Clarify * Preserve executables through rehydration * Revert unintentional change * Fix DOTNET_ROOT setting * Build macOS separately * Add chmod on any unix * Document s_executablesGroup
1 parent 9e39738 commit f154049

File tree

22 files changed

+302
-182
lines changed

22 files changed

+302
-182
lines changed

azure-pipelines.yml

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ parameters:
125125
default:
126126
name: $(PoolName)
127127
demands: ImageOverride -equals $(WindowsQueueName)
128+
- name: macOSPool
129+
type: object
130+
default:
131+
vmImage: macOS-15
128132
- name: vs2022PreviewPool
129133
type: object
130134
default:
@@ -170,6 +174,16 @@ stages:
170174
testArtifactName: Transport_Artifacts_Unix_Debug
171175
poolParameters: ${{ parameters.ubuntuPool }}
172176

177+
- ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
178+
- stage: MacOS_Build
179+
dependsOn: []
180+
jobs:
181+
- template: eng/pipelines/build-unix-job.yml
182+
parameters:
183+
jobName: Build_macOS_Debug
184+
testArtifactName: Transport_Artifacts_macOS_Debug
185+
poolParameters: ${{ parameters.macOSPool }}
186+
173187
- stage: Source_Build
174188
dependsOn: []
175189
jobs:
@@ -370,14 +384,19 @@ stages:
370384
testArguments: --testCoreClr
371385
poolParameters: ${{ parameters.ubuntuPool }}
372386

373-
# https://github.com/dotnet/runtime/issues/97186
374-
# Disabled until runtime can track down the crash
375-
- ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
387+
- ${{ if ne(variables['Build.Reason'], 'PullRequest') }}:
388+
- stage: MacOS_Debug_CoreClr
389+
dependsOn: MacOS_Build
390+
variables:
391+
- ${{ if ne(variables['System.TeamProject'], 'public') }}:
392+
- group: DotNet-HelixApi-Access
393+
jobs:
394+
# https://github.com/dotnet/runtime/issues/97186
376395
- template: eng/pipelines/test-unix-job.yml
377396
parameters:
378397
testRunName: 'Test macOS Debug'
379398
jobName: Test_macOS_Debug
380-
testArtifactName: Transport_Artifacts_Unix_Debug
399+
testArtifactName: Transport_Artifacts_macOS_Debug
381400
configuration: Debug
382401
testArguments: --testCoreClr
383402
helixQueueName: $(HelixMacOsQueueName)

eng/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ function GetCompilerTestAssembliesIncludePaths {
341341
assemblies+=" --include '^Microsoft\.CodeAnalysis\.VisualBasic\.Emit\.UnitTests$'"
342342
assemblies+=" --include '^Roslyn\.Compilers\.VisualBasic\.IOperation\.UnitTests$'"
343343
assemblies+=" --include '^Microsoft\.CodeAnalysis\.VisualBasic\.CommandLine\.UnitTests$'"
344+
assemblies+=" --include '^Microsoft\.Build\.Tasks\.CodeAnalysis\.UnitTests$'"
344345
echo "$assemblies"
345346
}
346347

src/Compilers/CSharp/csc/AnyCpu/csc.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
<PropertyGroup>
55
<OutputType>Exe</OutputType>
66
<TargetFrameworks>$(NetRoslynSourceBuild);net472</TargetFrameworks>
7-
<UseAppHost>false</UseAppHost>
87
<IsSymbolPublishingPackage>true</IsSymbolPublishingPackage>
98
</PropertyGroup>
109

src/Compilers/Core/MSBuildTask/InteractiveCompiler.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ namespace Microsoft.CodeAnalysis.BuildTasks
1616
/// </summary>
1717
public abstract class InteractiveCompiler : ManagedToolTask
1818
{
19-
internal readonly PropertyDictionary _store = new PropertyDictionary();
20-
2119
public InteractiveCompiler()
2220
: base(ErrorString.ResourceManager)
2321
{

src/Compilers/Core/MSBuildTask/ManagedCompiler.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ private enum CompilationKind
5151
}
5252

5353
private CancellationTokenSource? _sharedCompileCts;
54-
internal readonly PropertyDictionary _store = new PropertyDictionary();
5554

5655
internal abstract RequestLanguage Language { get; }
5756

src/Compilers/Core/MSBuildTask/ManagedToolTask.cs

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@
44

55
using System;
66
using System.Collections.Generic;
7-
using System.Diagnostics;
87
using System.IO;
98
using System.Resources;
109
using System.Text;
1110
using Microsoft.Build.Framework;
1211
using Microsoft.Build.Utilities;
12+
using Microsoft.CodeAnalysis.CommandLine;
1313
using Roslyn.Utilities;
1414

1515
namespace Microsoft.CodeAnalysis.BuildTasks
1616
{
1717
public abstract class ManagedToolTask : ToolTask
1818
{
19+
internal readonly PropertyDictionary _store = new PropertyDictionary();
20+
1921
/// <summary>
2022
/// A copy of this task, compiled for .NET Framework, is deployed into the .NET SDK. It is a bridge task
2123
/// that is loaded into .NET Framework MSBuild but launches the .NET Core compiler. This task necessarily
@@ -77,13 +79,7 @@ internal string GenerateToolArguments()
7779
/// </summary>
7880
protected sealed override string GenerateCommandLineCommands()
7981
{
80-
var commandLineArguments = GenerateToolArguments();
81-
if (UsingBuiltinTool && IsBuiltinToolRunningOnCoreClr)
82-
{
83-
commandLineArguments = RuntimeHostInfo.GetDotNetExecCommandLine(PathToBuiltInTool, commandLineArguments);
84-
}
85-
86-
return commandLineArguments;
82+
return GenerateToolArguments();
8783
}
8884

8985
/// <summary>
@@ -118,12 +114,9 @@ protected sealed override string GenerateResponseFileCommands()
118114
/// This could be the managed assembly itself (on desktop .NET on Windows),
119115
/// or a runtime such as dotnet.
120116
/// </summary>
121-
protected sealed override string GenerateFullPathToTool() => (UsingBuiltinTool, IsBuiltinToolRunningOnCoreClr) switch
122-
{
123-
(true, true) => RuntimeHostInfo.GetDotNetPathOrDefault(),
124-
(true, false) => PathToBuiltInTool,
125-
(false, _) => Path.Combine(ToolPath ?? "", ToolExe)
126-
};
117+
protected sealed override string GenerateFullPathToTool() => UsingBuiltinTool
118+
? PathToBuiltInTool
119+
: Path.Combine(ToolPath ?? "", ToolExe);
127120

128121
protected abstract string ToolNameWithoutExtension { get; }
129122

@@ -139,10 +132,7 @@ protected sealed override string GenerateResponseFileCommands()
139132
/// It returns the name of the managed assembly, which might not be the path returned by
140133
/// GenerateFullPathToTool, which can return the path to e.g. the dotnet executable.
141134
/// </remarks>
142-
protected sealed override string ToolName =>
143-
IsBuiltinToolRunningOnCoreClr
144-
? $"{ToolNameWithoutExtension}.dll"
145-
: $"{ToolNameWithoutExtension}.exe";
135+
protected sealed override string ToolName => $"{ToolNameWithoutExtension}{PlatformInformation.ExeExtension}";
146136

147137
/// <summary>
148138
/// This generates the command line arguments passed to the tool.
@@ -206,5 +196,17 @@ internal static string GetBuildTaskDirectory()
206196

207197
return buildTaskDirectory;
208198
}
199+
200+
protected override bool ValidateParameters()
201+
{
202+
// Set DOTNET_ROOT so that the apphost executables launch properly.
203+
if (RuntimeHostInfo.GetToolDotNetRoot() is { } dotNetRoot)
204+
{
205+
Log.LogMessage("Setting {0} to '{1}'", RuntimeHostInfo.DotNetRootEnvironmentName, dotNetRoot);
206+
EnvironmentVariables = [.. EnvironmentVariables ?? [], $"{RuntimeHostInfo.DotNetRootEnvironmentName}={dotNetRoot}"];
207+
}
208+
209+
return base.ValidateParameters();
210+
}
209211
}
210212
}

src/Compilers/Core/MSBuildTaskTests/CscTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using Microsoft.CodeAnalysis.BuildTasks.UnitTests.TestUtilities;
88
using Roslyn.Test.Utilities;
9+
using Roslyn.Utilities;
910
using Xunit;
1011
using Xunit.Abstractions;
1112

@@ -484,14 +485,13 @@ public void EmptyCscToolExe()
484485
csc.ToolExe = "";
485486
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
486487
Assert.Equal("", csc.GenerateCommandLineContents());
487-
// StartsWith because it can be csc.exe or csc.dll
488-
Assert.StartsWith(Path.Combine("path", "to", "custom_csc", "csc."), csc.GeneratePathToTool());
488+
AssertEx.Equal(Path.Combine("path", "to", "custom_csc", $"csc{PlatformInformation.ExeExtension}"), csc.GeneratePathToTool());
489489

490490
csc = new Csc();
491491
csc.ToolPath = Path.Combine("path", "to", "custom_csc");
492492
csc.Sources = MSBuildUtil.CreateTaskItems("test.cs");
493493
Assert.Equal("", csc.GenerateCommandLineContents());
494-
Assert.StartsWith(Path.Combine("path", "to", "custom_csc", "csc."), csc.GeneratePathToTool());
494+
AssertEx.Equal(Path.Combine("path", "to", "custom_csc", $"csc{PlatformInformation.ExeExtension}"), csc.GeneratePathToTool());
495495
}
496496

497497
[Fact]

src/Compilers/Core/MSBuildTaskTests/IntegrationTests.cs

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if NET472
65
using System.Collections.Generic;
76
using System.IO;
87
using Microsoft.CodeAnalysis.Test.Utilities;
@@ -24,24 +23,6 @@ private ProcessResult RunCompilerOutput(TempFile file)
2423
return ProcessUtilities.Run(file.Path, "", Path.GetDirectoryName(file.Path));
2524
}
2625

27-
private static void VerifyResult(ProcessResult result)
28-
{
29-
Assert.Equal("", result.Output);
30-
Assert.Equal("", result.Errors);
31-
Assert.Equal(0, result.ExitCode);
32-
}
33-
34-
private void VerifyResultAndOutput(ProcessResult result, TempDirectory path, string expectedOutput)
35-
{
36-
using (var resultFile = GetResultFile(path, "hello.exe"))
37-
{
38-
VerifyResult(result);
39-
40-
var runningResult = RunCompilerOutput(resultFile);
41-
Assert.Equal(expectedOutput, runningResult.Output);
42-
}
43-
}
44-
4526
// A dictionary with name and contents of all the files we want to create for the SimpleMSBuild test.
4627
private Dictionary<string, string> SimpleMsBuildFiles => new Dictionary<string, string> {
4728
{ "HelloSolution.sln",
@@ -536,7 +517,7 @@ public void ReportAnalyzerMSBuild()
536517
string arguments = string.Format(@"/m /nr:false /t:Rebuild /p:UseSharedCompilation=false /p:UseRoslyn=1 HelloSolution.sln");
537518
var result = RunCommandLineCompiler(_msbuildExecutable, arguments, _tempDirectory, ReportAnalyzerMsBuildFiles,
538519
new Dictionary<string, string>
539-
{ { "MyMSBuildToolsPath", Path.GetDirectoryName(typeof(IntegrationTests).Assembly.Location) } });
520+
{ { "MyMSBuildToolsPath", Path.GetDirectoryName(typeof(IntegrationTests).Assembly.Location)! } });
540521

541522
Assert.True(result.ExitCode != 0);
542523
Assert.Contains("/reportanalyzer", result.Output);
@@ -717,4 +698,3 @@ public class Class1
717698
}
718699
}
719700
}
720-
#endif

src/Compilers/Core/MSBuildTaskTests/MSBuildManagedToolTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
65
using System.IO;
7-
using Microsoft.CodeAnalysis.Test.Utilities;
6+
using Roslyn.Utilities;
87
using Xunit;
98

109
namespace Microsoft.CodeAnalysis.BuildTasks.UnitTests;
@@ -16,7 +15,7 @@ public void PathToBuiltinTool()
1615
{
1716
var taskPath = Path.GetDirectoryName(typeof(ManagedCompiler).Assembly.Location)!;
1817
var relativePath = RuntimeHostInfo.IsCoreClrRuntime
19-
? Path.Combine("bincore", "csc.dll")
18+
? Path.Combine("bincore", $"csc{PlatformInformation.ExeExtension}")
2019
: "csc.exe";
2120
var task = new Csc();
2221
Assert.Equal(Path.Combine(taskPath, relativePath), task.PathToBuiltInTool);

src/Compilers/Core/MSBuildTaskTests/Microsoft.Build.Tasks.CodeAnalysis.UnitTests.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<Target Name="CopyAssetsForIntegrationTests" Condition="'@(CommandLineCompilerReference)' != ''" AfterTargets="ResolveProjectReferences" BeforeTargets="AssignTargetPaths">
7070
<PropertyGroup>
7171
<_CommandLineCompilerReferenceOutputPath>@(CommandLineCompilerReference->'%(RootDir)%(Directory)*.*')</_CommandLineCompilerReferenceOutputPath>
72+
<_LinkPrefix Condition="'$(TargetFramework)' != 'net472'">bincore\</_LinkPrefix>
7273
</PropertyGroup>
7374
<ItemGroup>
7475
<_CommandLineCompilerReferenceContent Include="$(_CommandLineCompilerReferenceOutputPath)" />
@@ -78,7 +79,7 @@
7879
<Output TaskParameter="Filtered" ItemName="_CommandLineCompilerReferenceDeduplicated" />
7980
</RemoveDuplicates>
8081
<ItemGroup>
81-
<Content Include="%(_CommandLineCompilerReferenceDeduplicated.Original)" CopyToOutputDirectory="PreserveNewest" />
82+
<Content Include="%(_CommandLineCompilerReferenceDeduplicated.Original)" Link="$(_LinkPrefix)%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />
8283
</ItemGroup>
8384
</Target>
8485
</Project>

0 commit comments

Comments
 (0)