Skip to content

Commit

Permalink
dotnet#35696 Build on Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
svick committed Feb 21, 2025
1 parent b230069 commit b1a4f26
Show file tree
Hide file tree
Showing 12 changed files with 89 additions and 19 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
artifacts/
.github/
.teamcity/
**/bin/
**/obj/
eng-Metalama/*.g.props
Dockerfile
16 changes: 16 additions & 0 deletions .github/workflows/build-on-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Build on Docker

on: push
# on: workflow_dispatch

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Build Metalama.Premium using Docker
# Don't do the final copying step, since that fails with "no space left on device"
run: docker build . --target build
2 changes: 1 addition & 1 deletion Build.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(& dotnet nuget locals http-cache -c) | Out-Null
& dotnet run --project "$PSScriptRoot\eng-Metalama\src\BuildMetalamaCompiler.csproj" -- $args
& dotnet run --project "$PSScriptRoot/eng-Metalama/src/BuildMetalamaCompiler.csproj" -- $args
exit $LASTEXITCODE

12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# See comment in global.json for why the RC is still necessary
FROM mcr.microsoft.com/dotnet/sdk:9.0.100-rc.1 AS build

WORKDIR /src

COPY . /src/

RUN pwsh ./Build.ps1 build

FROM scratch

COPY --from=build /src/artifacts /artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
20 changes: 20 additions & 0 deletions eng-Metalama/DownloadNetSdkAnalyzers/net-sdk-releases.json
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,14 @@
"sdk-zip-url": "https://download.visualstudio.microsoft.com/download/pr/c20bc0e0-7344-4fb9-9c9b-697e11537c7e/405231def9d620e5a0ee7e5ba0a8fe97/dotnet-sdk-8.0.404-win-x64.zip",
"roslyn-version": "4.11.0-3.24510.3"
},
"8.0.405": {
"sdk-zip-url": "https://download.visualstudio.microsoft.com/download/pr/0b9ebc5d-c870-410f-b0f5-763468a0c340/a45cf691a7023cc9ae5e8b7ea9aaae2a/dotnet-sdk-8.0.405-win-x64.zip",
"roslyn-version": "4.11.0-3.24554.2"
},
"8.0.406": {
"sdk-zip-url": "https://download.visualstudio.microsoft.com/download/pr/4e3954c2-f714-4c43-b49a-0ee07c7cf7b2/f644fc3a93b8cf88099385ae14bea068/dotnet-sdk-8.0.406-win-x64.zip",
"roslyn-version": "4.11.0-3.24554.2"
},
"9.0.100": {
"sdk-zip-url": "https://download.visualstudio.microsoft.com/download/pr/c5650c11-6944-488c-9192-cbab3c199deb/059197c7e46969164e752eec107fbea1/dotnet-sdk-9.0.100-win-x64.zip",
"roslyn-version": "4.12.0-3.24523.4"
Expand Down Expand Up @@ -311,6 +319,18 @@
"9.0.100-rc.2": {
"sdk-zip-url": "https://download.visualstudio.microsoft.com/download/pr/af6bbccc-1d18-4bcb-aa3a-ce76f864f977/8ecffe6494804fb6c6be93488c58eef6/dotnet-sdk-9.0.100-rc.2.24474.11-win-x64.zip",
"roslyn-version": "4.12.0-3.24473.3"
},
"9.0.101": {
"sdk-zip-url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/9.0.101/dotnet-sdk-9.0.101-win-x64.zip",
"roslyn-version": "4.12.0-3.24570.6"
},
"9.0.102": {
"sdk-zip-url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/9.0.102/dotnet-sdk-9.0.102-win-x64.zip",
"roslyn-version": "4.12.0-3.24574.8"
},
"9.0.200": {
"sdk-zip-url": "https://builds.dotnet.microsoft.com/dotnet/Sdk/9.0.200/dotnet-sdk-9.0.200-win-x64.zip",
"roslyn-version": "4.13.0-3.25072.11"
}
}
}
2 changes: 1 addition & 1 deletion eng-Metalama/src/BuildMetalamaCompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<AssemblyName>Build</AssemblyName>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions eng-Metalama/src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

var product = new Product(MetalamaDependencies.MetalamaCompiler)
{
VersionsFilePath = "eng\\Versions.props",
VersionsFilePath = "eng/Versions.props",
GenerateArcadeProperties = true,
AdditionalDirectoriesToClean = ["artifacts"],
Solutions = [new RoslynSolution()],
Expand All @@ -33,7 +33,7 @@
"Metalama.Roslyn.CodeAnalysis.VisualBasic.Workspaces.$(PackageVersion).nupkg"),
Dependencies = [DevelopmentDependencies.PostSharpEngineering],
SupportedProperties = new() { ["TestAll"] = "Supported by the 'test' command. Run all tests instead of just Metalama's unit tests." },
ExportedProperties = { { @"eng\Versions.props", new[] { "RoslynVersion" } } },
ExportedProperties = { { @"eng/Versions.props", new[] { "RoslynVersion" } } },
KeepEditorConfig = true,
Configurations = Product.DefaultConfigurations.WithValue(BuildConfiguration.Release, c => c with { ExportsToTeamCityBuild = true }),
DefaultTestsFilter = "Category!=OuterLoop"
Expand Down
30 changes: 24 additions & 6 deletions eng-Metalama/src/RoslynSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.InteropServices;
using PostSharp.Engineering.BuildTools.Build;
using PostSharp.Engineering.BuildTools.Build.Model;
using PostSharp.Engineering.BuildTools.ContinuousIntegration;
Expand Down Expand Up @@ -75,12 +76,29 @@ private bool ExecuteScript(BuildContext context, BuildSettings settings, string
new Regex(".+The process cannot access the file.+because it is being used by another process."), 1)
};

return ToolInvocationHelper.InvokePowershell(
context.Console,
Path.Combine(context.RepoDirectory, "eng", "build.ps1"),
argsBuilder.ToString(),
context.RepoDirectory,
toolOptions);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return ToolInvocationHelper.InvokePowershell(
context.Console,
Path.Combine(context.RepoDirectory, "eng", "build.ps1"),
argsBuilder.ToString(),
context.RepoDirectory,
toolOptions);
}
else
{
argsBuilder
.Replace("-build", "--build")
.Replace("-pack", "--pack")
.Replace("-restore", "--restore");

return ToolInvocationHelper.InvokeTool(
context.Console,
"bash",
$"{Path.Combine(context.RepoDirectory, "eng", "build.sh")} {argsBuilder}",
context.RepoDirectory,
toolOptions);
}
}

public override bool Pack(BuildContext context, BuildSettings settings)
Expand Down
4 changes: 2 additions & 2 deletions eng/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ usage()
echo " --prepareMachine Prepare machine for CI run, clean up processes after build"
echo " --warnAsError Treat all warnings as errors"
echo " --sourceBuild Simulate building for source-build"
echo " --solution Soluton to build (Default is Compilers.slnf)"
echo " --solution Soluton to build (Default is Metalama.Compiler.slnf)"
echo ""
echo "Command line arguments starting with '/p:' are passed through to MSBuild."
}
Expand Down Expand Up @@ -79,7 +79,7 @@ warn_as_error=false
properties=""
source_build=false
restoreUseStaticGraphEvaluation=true
solution_to_build="Compilers.slnf"
solution_to_build="Metalama.Compiler.slnf"

args=""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,14 @@
<None Include="$(ArtifactsBinDir)Metalama.Compiler.Sdk\$(Configuration)\netstandard2.0\Metalama.Compiler.Interface.dll" Visible="false" Pack="true" PackagePath="analyzers/dotnet/cs" />

<None Include="README.md" Visible="false" Pack="true" PackagePath="" />
<!-- </Metalama> -->
</ItemGroup>

<ItemGroup>
<Content Include="build\**\*.*" PackagePath="build\" />
<Content Include="buildMultiTargeting\**\*.*" PackagePath="buildMultiTargeting\" />
<Content Include="build\**\*.*" />
<Content Include="buildMultiTargeting\**\*.*" />
</ItemGroup>

<Target Name="_GetFilesToPackage" DependsOnTargets="$(_DependsOn)">
<!-- <Metalama> -->
<Exec Command="dotnet run $(RoslynVersion)" WorkingDirectory="..\..\..\..\eng-Metalama\DownloadNetSdkAnalyzers" ConsoleToMsBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="NetSdkAnalyzersPath" />
</Exec>
Expand All @@ -92,7 +90,7 @@
<_File Include="@(DesktopMetalamaCompilerBinArtifact)" TargetDir="tasks/net472" Condition="'$(TargetFramework)' == 'net472'" />
<_File Include="@(CommonMetalamaCompilerBinArtifact)" TargetDir="tasks/$(NetCore)/bincore" Condition="'$(TargetFramework)' != 'net472'" />
<_File Include="@(CoreClrMetalamaCompilerBinArtifact)" TargetDir="tasks/$(NetCore)/bincore" Condition="'$(TargetFramework)' != 'net472'" />
<_File Include="$(NetSdkAnalyzersPath)\*.dll" TargetDir="sdkAnalyzers" />
<_File Include="$(NetSdkAnalyzersPath)\*.dll" TargetDir="sdkAnalyzers" Condition="'$(TargetFramework)' == 'net472'" />

<TfmSpecificPackageFile Include="@(_File)" PackagePath="%(_File.TargetDir)/%(_File.RecursiveDir)%(_File.FileName)%(_File.Extension)" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
<DesktopMetalamaCompilerBinArtifact Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.CSharp.Workspaces\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.CSharp.Workspaces.dll" />
<DesktopMetalamaCompilerBinArtifact Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.Features\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.Features.dll" />
<DesktopMetalamaCompilerBinArtifact Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.CSharp.Features\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.CSharp.Features.dll" />
<DesktopMetalamaCompilerBinArtifact Include="$(ArtifactsBinDir)Microsoft.CodeAnalysis.Scripting\$(Configuration)\netstandard2.0\Microsoft.CodeAnalysis.Scripting.dll"/>
<DesktopMetalamaCompilerBinArtifact Include="$(PkgSystem_Composition_AttributedModel)\lib\net462\System.Composition.AttributedModel.dll"/>
<DesktopMetalamaCompilerBinArtifact Include="$(PkgSystem_Composition_Convention)\lib\net462\System.Composition.Convention.dll"/>
<DesktopMetalamaCompilerBinArtifact Include="$(PkgSystem_Composition_Hosting)\lib\net462\System.Composition.Hosting.dll"/>
Expand Down

0 comments on commit b1a4f26

Please sign in to comment.