From 45461b69240dadbdd11cedaed51d27fbf260384e Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Wed, 12 Jun 2024 22:52:58 +0100 Subject: [PATCH] Initial Commit of code --- .github/workflows/main.yml | 74 ++++++++++++++++++++++++++++++++++++++ Build.sln | 27 ++++++++++++++ build.ps1 | 2 ++ build.sh | 1 + build/Build.csproj | 37 +++++++++++++++++++ build/BuildLinuxTask.cs | 17 +++++++++ build/BuildMacOSTask.cs | 20 +++++++++++ build/BuildWindowsTask.cs | 18 ++++++++++ build/Program.cs | 11 ++++++ 9 files changed, 207 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 Build.sln create mode 100644 build.ps1 create mode 100755 build.sh create mode 100644 build/Build.csproj create mode 100644 build/BuildLinuxTask.cs create mode 100644 build/BuildMacOSTask.cs create mode 100644 build/BuildWindowsTask.cs create mode 100644 build/Program.cs diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..32268d2 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,74 @@ +name: Build + +on: [push, pull_request] + +jobs: + build: + name: build-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-latest] + fail-fast: false + steps: + - name: Expose GitHub Runtime + uses: crazy-max/ghaction-github-runtime@v3 + + - name: Install Mac Dependencies + if: runner.os == 'macOS' + run: | + brew install cmake autoconf automake libtool + + - name: Install Linux Dependencies + if: runner.os == 'Linux' + run: sudo apt-get install cmake autoconf automake libtool + + - name: Clone repository + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Run Cake + run: dotnet run --project ./build/Build.csproj --universalBinary=true + env: + ACTIONS_RUNTIME_TOKEN: ${{ env.ACTIONS_RUNTIME_TOKEN }} + ACTIONS_RUNTIME_URL: "${{ env.ACTIONS_RUNTIME_URL }}" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + deploy: + name: deploy + if: ${{ github.event_name == 'push' }} + runs-on: ubuntu-latest + permissions: + packages: write + contents: write + needs: [ build ] + steps: + - name: Expose GitHub Runtime + uses: crazy-max/ghaction-github-runtime@v3 + + - name: Clone repository + uses: actions/checkout@v4 + with: + submodules: recursive + + #- name: Rename License File + # run: mv ./basis_universal/LICENSE ./basis_universal/LICENSE + + - name: Run CAKE + run: dotnet run --project ./build/Build.csproj -- --target=Package --universalBinary=true --toolname=basisu --executablename=basisu --commandname=mgcb-basisu --licensepath=basis_universal/LICENSE + env: + ACTIONS_RUNTIME_TOKEN: ${{ env.ACTIONS_RUNTIME_TOKEN }} + ACTIONS_RUNTIME_URL: "${{ env.ACTIONS_RUNTIME_URL }}" + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Make a release + if: github.ref_type == 'tag' + uses: ncipollo/release-action@v1 + with: + name: 'MonoGame.Tool.FFprobe ${{ github.ref_name }}' + tag: ${{ github.ref_name }} + allowUpdates: true + removeArtifacts: true + artifacts: "artifacts/**/*.nupkg" + token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/Build.sln b/Build.sln new file mode 100644 index 0000000..bf83afd --- /dev/null +++ b/Build.sln @@ -0,0 +1,27 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Build", "build\Build.csproj", "{05EA3CA1-0ABE-4772-978B-DCC60854A51C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Tool.BuildScripts", "buildscripts\MonoGame.Tool.BuildScripts.csproj", "{6CE6C044-1BE5-4380-9CFD-FB1E0CFD013B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {05EA3CA1-0ABE-4772-978B-DCC60854A51C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {05EA3CA1-0ABE-4772-978B-DCC60854A51C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {05EA3CA1-0ABE-4772-978B-DCC60854A51C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {05EA3CA1-0ABE-4772-978B-DCC60854A51C}.Release|Any CPU.Build.0 = Release|Any CPU + {6CE6C044-1BE5-4380-9CFD-FB1E0CFD013B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CE6C044-1BE5-4380-9CFD-FB1E0CFD013B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CE6C044-1BE5-4380-9CFD-FB1E0CFD013B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CE6C044-1BE5-4380-9CFD-FB1E0CFD013B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal \ No newline at end of file diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..794b925 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,2 @@ +dotnet run --project build/Build.csproj --universalBinary=true -- $args +exit $LASTEXITCODE; \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..2bdbbcb --- /dev/null +++ b/build.sh @@ -0,0 +1 @@ +dotnet run --project ./build/Build.csproj --universalBinary=true -- "$@" \ No newline at end of file diff --git a/build/Build.csproj b/build/Build.csproj new file mode 100644 index 0000000..0feb5b2 --- /dev/null +++ b/build/Build.csproj @@ -0,0 +1,37 @@ + + + + Exe + net8.0 + $(MSBuildProjectDirectory) + enable + enable + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/build/BuildLinuxTask.cs b/build/BuildLinuxTask.cs new file mode 100644 index 0000000..8e3ba1a --- /dev/null +++ b/build/BuildLinuxTask.cs @@ -0,0 +1,17 @@ +namespace BuildScripts; + +[TaskName("Build Linux")] +[IsDependentOn(typeof(PrepTask))] +[IsDependeeOf(typeof(BuildToolTask))] +public sealed class BuildLinuxTask : FrostingTask +{ + public override bool ShouldRun(BuildContext context) => context.IsRunningOnLinux(); + + public override void Run(BuildContext context) + { + var buildWorkingDir = "basis_universal/"; + context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildWorkingDir, Arguments = "CMakeLists.txt" }); + context.StartProcess("make", new ProcessSettings { WorkingDirectory = buildWorkingDir, Arguments = "" }); + context.CopyFile($"{buildWorkingDir}basisu", $"{context.ArtifactsDir}/basisu"); + } +} \ No newline at end of file diff --git a/build/BuildMacOSTask.cs b/build/BuildMacOSTask.cs new file mode 100644 index 0000000..9cfa73b --- /dev/null +++ b/build/BuildMacOSTask.cs @@ -0,0 +1,20 @@ +using System.Runtime.InteropServices; + +namespace BuildScripts; + +[TaskName("Build macOS")] +[IsDependentOn(typeof(PrepTask))] +[IsDependeeOf(typeof(BuildToolTask))] +public sealed class BuildMacOSTask : FrostingTask +{ + public override bool ShouldRun(BuildContext context) => context.IsRunningOnMacOs(); + + public override void Run(BuildContext context) + { + var buildWorkingDir = "basis_universal/"; + context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildWorkingDir, Arguments = "-DCMAKE_OSX_ARCHITECTURES=\"x86_64;arm64\" CMakeLists.txt" }); + context.StartProcess("make", new ProcessSettings { WorkingDirectory = buildWorkingDir, Arguments = "" }); + var files = Directory.GetFiles(System.IO.Path.Combine (buildWorkingDir, "bin_osx"), "basisu", SearchOption.TopDirectoryOnly); + context.CopyFile(files[0], $"{context.ArtifactsDir}/basisu"); + } +} \ No newline at end of file diff --git a/build/BuildWindowsTask.cs b/build/BuildWindowsTask.cs new file mode 100644 index 0000000..fdacced --- /dev/null +++ b/build/BuildWindowsTask.cs @@ -0,0 +1,18 @@ +namespace BuildScripts; + +[TaskName("Build Windows")] +[IsDependentOn(typeof(PrepTask))] +[IsDependeeOf(typeof(BuildToolTask))] +public sealed class BuildWindowsTask : FrostingTask +{ + public override bool ShouldRun(BuildContext context) => context.IsRunningOnWindows(); + + public override void Run(BuildContext context) + { + var buildWorkingDir = "basis_universal/"; + context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildWorkingDir, Arguments = "CMakeLists.txt" }); + context.StartProcess("make", new ProcessSettings { WorkingDirectory = buildWorkingDir, Arguments = "" }); + var files = Directory.GetFiles(System.IO.Path.Combine (buildWorkingDir, "bin_windows"), "basisu.exe", SearchOption.TopDirectoryOnly); + context.CopyFile(files[0], $"{context.ArtifactsDir}/basisu.exe"); + } +} \ No newline at end of file diff --git a/build/Program.cs b/build/Program.cs new file mode 100644 index 0000000..1501361 --- /dev/null +++ b/build/Program.cs @@ -0,0 +1,11 @@ +namespace BuildScripts; + +public static class Program +{ + public static int Main(string[] args) + => new CakeHost() + .AddAssembly(typeof(BuildContext).Assembly) + .UseWorkingDirectory("../") + .UseContext() + .Run(args); +} \ No newline at end of file