Skip to content

Commit 1e158cf

Browse files
committed
Switch to CAKE Frosting for CI
1 parent 7080076 commit 1e158cf

12 files changed

+190
-100
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,5 @@ tools/
403403
# Artifacts
404404
artifacts/
405405
artifacts-*/
406+
407+
.idea

MonoGame.Library.SDL.sln

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.0.31903.59
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Library.SDL", "src\MonoGame.Library.SDL.csproj", "{F9BD9E87-2B0B-4CB8-9C39-3FACD66E14AF}"
7+
EndProject
8+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build", "build\Build.csproj", "{8363325E-56EB-4B87-B170-C28237FB80CC}"
9+
EndProject
10+
Global
11+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
12+
Debug|Any CPU = Debug|Any CPU
13+
Release|Any CPU = Release|Any CPU
14+
EndGlobalSection
15+
GlobalSection(SolutionProperties) = preSolution
16+
HideSolutionNode = FALSE
17+
EndGlobalSection
18+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
19+
{F9BD9E87-2B0B-4CB8-9C39-3FACD66E14AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20+
{F9BD9E87-2B0B-4CB8-9C39-3FACD66E14AF}.Debug|Any CPU.Build.0 = Debug|Any CPU
21+
{F9BD9E87-2B0B-4CB8-9C39-3FACD66E14AF}.Release|Any CPU.ActiveCfg = Release|Any CPU
22+
{F9BD9E87-2B0B-4CB8-9C39-3FACD66E14AF}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{8363325E-56EB-4B87-B170-C28237FB80CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{8363325E-56EB-4B87-B170-C28237FB80CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{8363325E-56EB-4B87-B170-C28237FB80CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{8363325E-56EB-4B87-B170-C28237FB80CC}.Release|Any CPU.Build.0 = Release|Any CPU
27+
EndGlobalSection
28+
EndGlobal

build.cake

-97
This file was deleted.

build.ps1

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dotnet run --project build/Build.csproj -- $args
2+
exit $LASTEXITCODE;

build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dotnet run --project ./build/Build.csproj -- "$@"

build/Build.csproj

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net7.0</TargetFramework>
5+
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
<ItemGroup>
9+
<Using Include="Cake.Frosting" />
10+
<Using Include="Cake.Common.Tools.DotNet" />
11+
<Using Include="Cake.Common.Tools.DotNet.MSBuild" />
12+
<Using Include="Cake.Common.Tools.DotNet.Pack" />
13+
<Using Include="Cake.Common.IO" />
14+
<Using Include="Cake.Common" />
15+
<Using Include="Cake.Core" />
16+
<Using Include="Cake.Core.Diagnostics" />
17+
<Using Include="Cake.Core.IO" />
18+
<Using Include="Cake.FileHelpers" />
19+
</ItemGroup>
20+
<ItemGroup>
21+
<PackageReference Include="Cake.FileHelpers" Version="6.1.3" />
22+
<PackageReference Include="Cake.Frosting" Version="3.1.0" />
23+
</ItemGroup>
24+
</Project>

build/BuildLinuxTask.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
namespace BuildScripts;
3+
4+
[TaskName("Build Linux")]
5+
public sealed class BuildLinuxTask : FrostingTask<BuildContext>
6+
{
7+
public override bool ShouldRun(BuildContext context) => context.IsRunningOnLinux();
8+
9+
public override void Run(BuildContext context)
10+
{
11+
// Build
12+
var buildDir = "sdl/build";
13+
context.CreateDirectory(buildDir);
14+
context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "../ -DCMAKE_BUILD_TYPE=Release" });
15+
context.StartProcess("make", new ProcessSettings { WorkingDirectory = buildDir });
16+
17+
// Copy artifact
18+
context.CreateDirectory(context.ArtifactsDir);
19+
foreach (var filePath in context.GetFiles(buildDir + "/*"))
20+
{
21+
if (filePath.GetFilename().ToString().StartsWith("libSDL2-2.0.so.0."))
22+
{
23+
context.CopyFile(filePath, $"{context.ArtifactsDir}/libSDL2-2.0.so.0");
24+
return;
25+
}
26+
}
27+
28+
throw new Exception("Failed to locate the artifact file of libSDL2-2.0.so :/");
29+
}
30+
}

build/BuildMacOSTask.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
namespace BuildScripts;
3+
4+
[TaskName("Build macOS")]
5+
public sealed class BuildMacOSTask : FrostingTask<BuildContext>
6+
{
7+
public override bool ShouldRun(BuildContext context) => context.IsRunningOnMacOs();
8+
9+
public override void Run(BuildContext context)
10+
{
11+
// Build
12+
var buildDir = "sdl/build";
13+
context.CreateDirectory(buildDir);
14+
context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "../ -DCMAKE_OSX_DEPLOYMENT_TARGET=10.15 -DCMAKE_OSX_ARCHITECTURES=arm64;x86_64 -DCMAKE_BUILD_TYPE=Release" });
15+
context.StartProcess("make", new ProcessSettings { WorkingDirectory = buildDir });
16+
17+
// Copy artifact
18+
context.CreateDirectory(context.ArtifactsDir);
19+
context.CopyFile("sdl/build/libSDL2-2.0.0.dylib", $"{context.ArtifactsDir}/libSDL2-2.0.0.dylib");
20+
}
21+
}

build/BuildWindowsTask.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
namespace BuildScripts;
3+
4+
[TaskName("Build Windows")]
5+
public sealed class BuildWindowsTask : FrostingTask<BuildContext>
6+
{
7+
public override bool ShouldRun(BuildContext context) => context.IsRunningOnWindows();
8+
9+
public override void Run(BuildContext context)
10+
{
11+
// Build
12+
var buildDir = "sdl/build";
13+
context.CreateDirectory(buildDir);
14+
context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "-A x64 ../" });
15+
context.StartProcess("msbuild", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "SDL2.sln /p:Configuration=Release" });
16+
17+
// Copy artifact
18+
context.CreateDirectory(context.ArtifactsDir);
19+
context.CopyFile("sdl/build/Release/SDL2.dll", $"{context.ArtifactsDir}/SDL2.dll");
20+
}
21+
}

build/PackageTask.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
namespace BuildScripts;
3+
4+
[TaskName("Package")]
5+
public sealed class PackageTask : FrostingTask<BuildContext>
6+
{
7+
public override bool ShouldRun(BuildContext context) => context.IsRunningOnLinux();
8+
9+
public override void Run(BuildContext context)
10+
{
11+
var sdlMajor = context.FindRegexMatchGroupInFile("sdl/include/SDL_version.h", @"#define SDL_MAJOR_VERSION +(?<ver>\d+)", 1, System.Text.RegularExpressions.RegexOptions.Singleline);
12+
var sdlMinor = context.FindRegexMatchGroupInFile("sdl/include/SDL_version.h", @"#define SDL_MINOR_VERSION +(?<ver>\d+)", 1, System.Text.RegularExpressions.RegexOptions.Singleline);
13+
var sdlPatch = context.FindRegexMatchGroupInFile("sdl/include/SDL_version.h", @"#define SDL_PATCHLEVEL +(?<ver>\d+)", 1, System.Text.RegularExpressions.RegexOptions.Singleline);
14+
var sdlVersion = $"{sdlMajor}.{sdlMinor}.{sdlPatch}";
15+
var dnMsBuildSettings = new DotNetMSBuildSettings();
16+
dnMsBuildSettings.WithProperty("Version", sdlVersion + "." + context.EnvironmentVariable("GITHUB_RUN_NUMBER"));
17+
dnMsBuildSettings.WithProperty("RepositoryUrl", "https://github.com/" + context.EnvironmentVariable("GITHUB_REPOSITORY"));
18+
19+
context.DotNetPack("MonoGame.Library.SDL.csproj", new DotNetPackSettings
20+
{
21+
MSBuildSettings = dnMsBuildSettings,
22+
Verbosity = DotNetVerbosity.Minimal,
23+
Configuration = "Release"
24+
});
25+
}
26+
}

build/Program.cs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
namespace BuildScripts;
3+
4+
public static class Program
5+
{
6+
public static int Main(string[] args)
7+
=> new CakeHost()
8+
.UseWorkingDirectory("../")
9+
.UseContext<BuildContext>()
10+
.Run(args);
11+
12+
public static string GetArgument(this ICakeArguments args, string argName, string defaultArgValue)
13+
=> args.HasArgument(argName) ? args.GetArgument(argName) : defaultArgValue;
14+
}
15+
16+
public class BuildContext : FrostingContext
17+
{
18+
public string ArtifactsDir { get; }
19+
20+
public BuildContext(ICakeContext context) : base(context)
21+
{
22+
ArtifactsDir = context.Arguments.GetArgument("artifactsDir", "artifacts");
23+
}
24+
}
25+
26+
[TaskName("Default")]
27+
[IsDependentOn(typeof(BuildWindowsTask))]
28+
[IsDependentOn(typeof(BuildMacOSTask))]
29+
[IsDependentOn(typeof(BuildLinuxTask))]
30+
public class DefaultTask : FrostingTask
31+
{
32+
}

MonoGame.Library.SDL.csproj renamed to src/MonoGame.Library.SDL.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<Content Include="artifacts-windows-x64\SDL2.dll">
12+
<Content Include="..\artifacts-windows-x64\SDL2.dll">
1313
<Link>SDL2.dll</Link>
1414
<PackagePath>runtimes\win-x64\native</PackagePath>
1515
</Content>
16-
<Content Include="artifacts-macos\libSDL2-2.0.0.dylib">
16+
<Content Include="..\artifacts-macos\libSDL2-2.0.0.dylib">
1717
<Link>libSDL2-2.0.0.dylib</Link>
1818
<PackagePath>runtimes\osx\native</PackagePath>
1919
</Content>
20-
<Content Include="artifacts-linux-x64\libSDL2-2.0.so.0">
20+
<Content Include="..\artifacts-linux-x64\libSDL2-2.0.so.0">
2121
<Link>libSDL2-2.0.so.0</Link>
2222
<PackagePath>runtimes\linux-x64\native</PackagePath>
2323
</Content>

0 commit comments

Comments
 (0)