From 1ec27c61bcb0e3599f931e45c7203760c0dfc707 Mon Sep 17 00:00:00 2001 From: Tom Spilman Date: Sun, 25 Aug 2024 12:53:42 -0500 Subject: [PATCH] Switch to premake for project generation. --- .github/workflows/main.yml | 6 +- build/BuildContext.cs | 13 --- .../BuildDesktopVKTask.cs | 26 +++-- src/monogame/build_windows.bat | 8 -- src/monogame/make_windows_solution.bat | 2 +- src/monogame/premake5.lua | 109 ++++++++++++++++++ src/monogame/vulkan/MGG_Vulkan.cpp | 4 +- src/monogame/xmake.lua | 45 -------- 8 files changed, 131 insertions(+), 82 deletions(-) delete mode 100644 src/monogame/build_windows.bat create mode 100644 src/monogame/premake5.lua delete mode 100644 src/monogame/xmake.lua diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1ae48e73762..16e2b4a444b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,10 +21,10 @@ jobs: with: dotnet-version: '8.0.x' - - name: Setup Xmake - uses: xmake-io/github-action-setup-xmake@v1 + - name: Setup Premake5 + uses: abel0b/setup-premake@v2.4 with: - xmake-version: latest + version: "5.0.0-beta2" - name: Setup Java uses: actions/setup-java@v4 diff --git a/build/BuildContext.cs b/build/BuildContext.cs index e5173de2d7d..e23ad2c4445 100644 --- a/build/BuildContext.cs +++ b/build/BuildContext.cs @@ -170,17 +170,4 @@ out IEnumerable processOutput return processOutput.Any(match => match.StartsWith($"{workload} ")); } - - public int XMake(string workingDir, params string[] args) - { - return this.StartProcess( - "xmake", - new ProcessSettings() - { - WorkingDirectory = workingDir, - Arguments = string.Join(" ", args), - RedirectStandardOutput = false, - } - ); - } } diff --git a/build/BuildFrameworksTasks/BuildDesktopVKTask.cs b/build/BuildFrameworksTasks/BuildDesktopVKTask.cs index 7655f747cc6..5cf7be73aa0 100644 --- a/build/BuildFrameworksTasks/BuildDesktopVKTask.cs +++ b/build/BuildFrameworksTasks/BuildDesktopVKTask.cs @@ -9,20 +9,26 @@ public sealed class BuildDesktopVKTask : FrostingTask public override void Run(BuildContext context) { - int exit = context.XMake(@"src\monogame\", "f -m debug -v -y"); - if (exit < 0) - throw new Exception($"Setting debug config failed! {exit}"); + // TODO: This should be moved to its own seperate + // build process so that it doesn't run on all MG builds. + { + var buildDir = "src/monogame/external/sdl2/build"; + context.CreateDirectory(buildDir); + context.StartProcess("cmake", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "-A x64 -D CMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded ../" }); + context.StartProcess("msbuild", new ProcessSettings { WorkingDirectory = buildDir, Arguments = "SDL2.sln /p:Configuration=Release /p:Platform=x64" }); + } - exit = context.XMake(@"src\monogame\", "-r"); + // Generate the native projects. + var exit = context.StartProcess("premake5", new ProcessSettings { WorkingDirectory = "src/monogame", Arguments = "clean" }); if (exit < 0) - throw new Exception($"Rebuild debug failed! {exit}"); - - exit = context.XMake(@"src\monogame\", "f -m release -v -y"); + throw new Exception($"Setting Premake clean failed! {exit}"); + exit = context.StartProcess("premake5", new ProcessSettings { WorkingDirectory = "src/monogame", Arguments = "--os=windows --verbose vs2022" }); if (exit < 0) - throw new Exception($"Setting release config failed! {exit}"); + throw new Exception($"Setting Premake generation failed! {exit}"); - exit = context.XMake(@"src\monogame\", "-r"); + // Build it. + exit = context.StartProcess("msbuild", new ProcessSettings { WorkingDirectory = "src/monogame", Arguments = "monogame.sln /p:Configuration=Release /p:Platform=x64" }); if (exit < 0) - throw new Exception($"Rebuild release failed! {exit}"); + throw new Exception($"Setting build failed! {exit}"); } } diff --git a/src/monogame/build_windows.bat b/src/monogame/build_windows.bat deleted file mode 100644 index 5f75c6e38ce..00000000000 --- a/src/monogame/build_windows.bat +++ /dev/null @@ -1,8 +0,0 @@ -@echo off -@echo. -@echo === Debug ======================================================================== -xmake f -m debug && xmake -r - -@echo. -@echo === Release ====================================================================== -xmake f -m release && xmake -r \ No newline at end of file diff --git a/src/monogame/make_windows_solution.bat b/src/monogame/make_windows_solution.bat index 9f175f3262b..a861b6cc4c1 100644 --- a/src/monogame/make_windows_solution.bat +++ b/src/monogame/make_windows_solution.bat @@ -1,4 +1,4 @@ @echo off -xmake project -m "Release,Debug" -k vsxmake +premake5 vs2022 diff --git a/src/monogame/premake5.lua b/src/monogame/premake5.lua new file mode 100644 index 00000000000..6b3baebbbc1 --- /dev/null +++ b/src/monogame/premake5.lua @@ -0,0 +1,109 @@ +-- MonoGame - Copyright (C) MonoGame Foundation, Inc +-- This file is subject to the terms and conditions defined in +-- file 'LICENSE.txt', which is part of this source code package. + +function common(project_name) + + platform_target_path = "../../Artifacts/monogame.native/%{cfg.system}/" .. project_name .. "/%{cfg.buildcfg}" + + kind "SharedLib" + language "C++" + architecture "x64" + defines { "DLL_EXPORT" } + targetdir( platform_target_path ) + targetname "monogame.native" + + files + { + "include/**.h", + "common/**.h", + "common/**.cpp", + } + includedirs + { + "include", + } + +end + +-- SDL is supported on all desktop platforms. +function sdl2() + + defines { "MG_SDL2" } + + files + { + "sdl/**.h", + "sdl/**.cpp", + } + + includedirs + { + "external/sdl2/sdl/include", + } + + filter { "system:windows" } + links + { + "external/sdl2/build/Release/SDL2-static.lib", + "winmm", + "imm32", + "user32", + "gdi32", + "advapi32", + "setupapi", + "ole32", + "oleaut32", + "version", + "shell32" + } + +end + +-- Vulkan is supported for all desktop platforms. +function vulkan() + + defines { "MG_VULKAN" } + + files + { + "vulkan/**.h", + "vulkan/**.cpp", + } + + filter "system:windows" + files { "vulkan/**.rc", } + + includedirs + { + "external/vulkan-headers/include", + "external/volk", + "external/vma/include", + } + +end + +function configs() + + filter "configurations:Debug" + defines { "DEBUG" } + symbols "On" + + filter "configurations:Release" + defines { "NDEBUG" } + optimize "On" + +end + +workspace "monogame" + configurations { "Debug", "Release" } + +project "desktopvk" + common("desktopvk") + sdl2() + vulkan() + configs() + + +project "windowsdx" + common("windowsdx") diff --git a/src/monogame/vulkan/MGG_Vulkan.cpp b/src/monogame/vulkan/MGG_Vulkan.cpp index 383a364fad4..2b031e8a2c6 100644 --- a/src/monogame/vulkan/MGG_Vulkan.cpp +++ b/src/monogame/vulkan/MGG_Vulkan.cpp @@ -15,11 +15,11 @@ #include #define VOLK_IMPLEMENTATION -#include +#include #define VMA_IMPLEMENTATION #define VMA_STATIC_VULKAN_FUNCTIONS 1 -#include +#include #if defined(MG_SDL2) #include diff --git a/src/monogame/xmake.lua b/src/monogame/xmake.lua deleted file mode 100644 index 353f009c92e..00000000000 --- a/src/monogame/xmake.lua +++ /dev/null @@ -1,45 +0,0 @@ --- MonoGame - Copyright (C) MonoGame Foundation, Inc --- This file is subject to the terms and conditions defined in --- file 'LICENSE.txt', which is part of this source code package. - --- Bulding a dynamic link library. -set_kind("shared") -set_basename("monogame.native") -add_defines("DLL_EXPORT") -add_rules("mode.release", "mode.debug") - --- Always include the common bits. -add_files("common/*.cpp") -add_includedirs("include") - --- Required dependencies. -add_requires("libsdl 2.30.*") -add_requires("vulkansdk") - -target("desktopvk") - - set_targetdir("../../Artifacts/monogame.native/$(os)/desktopvk/$(mode)") - - -- SDL is supported on all desktop platforms. - add_defines("MG_SDL2") - add_files("sdl/*.cpp") - add_packages("libsdl") - - -- Vulkan is supported for all desktop platforms. - add_defines("MG_VULKAN"); - add_files("vulkan/*.cpp") - add_packages("vulkansdk") - if is_plat("windows") then - add_files("vulkan/vulkan.rc") - end - add_links("volk") - - target_end() - - -- - target("windowsdx") - - -- TODO! - - target_end() -