From 6f2b83b8d037699333711ab7618da622457cf38e Mon Sep 17 00:00:00 2001 From: WSSDude <41929176+WSSDude@users.noreply.github.com> Date: Sat, 22 Feb 2025 10:21:46 +0100 Subject: [PATCH] Better versioning * Version info based off git information * Add autogenerated resource file so the final DLL has some version info * Cleaner inclusion of autogenerated files (prevents constant stdafx.h rebuilds and puts resulting files into some more normal directory) * Fix #894 --- .gitignore | 1 + src/CETVersion.h.in | 4 -- src/Options.cpp | 3 +- src/scripting/Scripting.cpp | 4 +- src/stdafx.h | 1 - src/xmake/CETVersion.h.in | 21 +++++++++ src/xmake/Resource.rc.in | 31 +++++++++++++ xmake.lua | 90 +++++++++++++++++++++++++++++-------- 8 files changed, 129 insertions(+), 26 deletions(-) delete mode 100644 src/CETVersion.h.in create mode 100644 src/xmake/CETVersion.h.in create mode 100644 src/xmake/Resource.rc.in diff --git a/.gitignore b/.gitignore index d2870782..a975f14d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ package/* vs2022/* vsxmake*/ *.pyc +src/config/* \ No newline at end of file diff --git a/src/CETVersion.h.in b/src/CETVersion.h.in deleted file mode 100644 index 19d357b1..00000000 --- a/src/CETVersion.h.in +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#define CET_BUILD_BRANCH "${GIT_BRANCH}" -#define CET_BUILD_COMMIT "${GIT_TAG}" diff --git a/src/Options.cpp b/src/Options.cpp index 39a311d9..14dec372 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -1,5 +1,6 @@ #include +#include "config/CETVersion.h" #include "Paths.h" #include "Utils.h" #include "RED4ext/Api/Runtime.hpp" @@ -177,7 +178,7 @@ Options::Options(Paths& aPaths) if (GameImage.FileVersion.major != 0) { - Log::Info("CET version {} [{}]", CET_BUILD_COMMIT, CET_BUILD_BRANCH); + Log::Info("CET version {}", CET_VERSION_FULL); Log::Info("Game version {}.{}.{}.{}", GameImage.FileVersion.major, GameImage.FileVersion.minor, GameImage.FileVersion.build, GameImage.FileVersion.revision); Log::Info("Root path: \"{}\"", UTF16ToUTF8(aPaths.GameRoot().native())); Log::Info("Cyber Engine Tweaks path: \"{}\"", UTF16ToUTF8(aPaths.CETRoot().native())); diff --git a/src/scripting/Scripting.cpp b/src/scripting/Scripting.cpp index 2e9a601b..6207f04c 100644 --- a/src/scripting/Scripting.cpp +++ b/src/scripting/Scripting.cpp @@ -2,6 +2,8 @@ #include "Scripting.h" +#include "config/CETVersion.h" + #include "FunctionOverride.h" #include "GameOptions.h" #include "Texture.h" @@ -125,7 +127,7 @@ void Scripting::Initialize() globals["GetVersion"] = []() -> std::string { - return CET_BUILD_COMMIT; + return CET_GIT_TAG; }; globals["GetDisplayResolution"] = [this]() -> std::tuple diff --git a/src/stdafx.h b/src/stdafx.h index 208d1997..1450b9cf 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -67,7 +67,6 @@ #include #include -#include "CETVersion.h" #include "common/Logging.h" #include "common/FontMaterialDesignIcons.h" #include "common/ImGuiNotify.h" diff --git a/src/xmake/CETVersion.h.in b/src/xmake/CETVersion.h.in new file mode 100644 index 00000000..bdfed656 --- /dev/null +++ b/src/xmake/CETVersion.h.in @@ -0,0 +1,21 @@ +#pragma once + +${define CET_DEBUG_BUILD} +${define CET_GIT_TAG} +${define CET_GIT_TAG_LONG} +${define CET_GIT_BRANCH} +${define CET_GIT_COMMIT} +${define CET_GIT_COMMIT_LONG} +${define CET_GIT_COMMIT_DATE} + +${define CET_VERSION_MAJOR} +${define CET_VERSION_MINOR} +${define CET_VERSION_PATCH} +${define CET_VERSION_SIMPLE} +${define CET_VERSION_FULL} +${define CET_VERSION} + +${define CET_CURRENT_YEAR} +${define CET_PRODUCT_NAME} +${define CET_GROUP_NAME} +${define CET_FILE_NAME} diff --git a/src/xmake/Resource.rc.in b/src/xmake/Resource.rc.in new file mode 100644 index 00000000..8c301ea2 --- /dev/null +++ b/src/xmake/Resource.rc.in @@ -0,0 +1,31 @@ +#include "Windows.h" + +LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL + +VS_VERSION_INFO VERSIONINFO + FILEVERSION ${CET_VERSION_MAJOR},${CET_VERSION_MINOR},${CET_VERSION_PATCH},0 + PRODUCTVERSION ${CET_VERSION_MAJOR},${CET_VERSION_MINOR},${CET_VERSION_PATCH},0 + FILEFLAGSMASK 0x3fL + FILEFLAGS 0x${CET_DEBUG_BUILD}L + FILEOS 0x40004L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "${CET_GROUP_NAME}" + VALUE "FileDescription", "${CET_PRODUCT_NAME}" + VALUE "FileVersion", "${CET_VERSION_SIMPLE}" + VALUE "LegalCopyright", "© 2020-${CET_CURRENT_YEAR} ${CET_GROUP_NAME}. All Rights Reserved" + VALUE "OriginalFilename", "${CET_FILE_NAME}" + VALUE "ProductName", "${CET_PRODUCT_NAME}" + VALUE "ProductVersion", "${CET_VERSION_FULL}" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0409 0x04E2 + END +END diff --git a/xmake.lua b/xmake.lua index 0e904908..758ae807 100644 --- a/xmake.lua +++ b/xmake.lua @@ -9,37 +9,29 @@ add_rules("c.unity_build") add_cxflags("/bigobj", "/MP", "/EHsc") add_defines("UNICODE", "_UNICODE", "_CRT_SECURE_NO_WARNINGS") -local vsRuntime = "MD" - if is_mode("debug") then - add_defines("CET_DEBUG") - set_symbols("debug") set_optimize("none") set_warnings("all") set_policy("build.optimization.lto", false) - - vsRuntime = vsRuntime.."d" elseif is_mode("releasedbg") then - add_defines("CET_DEBUG") - set_symbols("debug") set_optimize("fastest") set_warnings("all") set_policy("build.optimization.lto", true) - - vsRuntime = vsRuntime.."d" elseif is_mode("release") then - add_defines("NDEBUG") - set_symbols("debug") set_strip("all") set_optimize("fastest") - set_runtimes("MD") set_warnings("all", "error") set_policy("build.optimization.lto", true) end -set_runtimes(vsRuntime); +set_symbols("debug") +set_runtimes(is_mode("release") and "MD" or "MDd"); -add_requireconfs("**", { configs = { debug = is_mode("debug"), lto = not is_mode("debug"), shared = false, vs_runtime = vsRuntime } }) +add_requireconfs("**", { configs = { + --debug = is_mode("debug"), -- This seems to cause compilation issues recently and probably has little benefit anyway + lto = not is_mode("debug"), + shared = false, + vs_runtime = is_mode("release") and "MD" or "MDd" } }) add_requires("spdlog 1.11.0") add_requires("nlohmann_json") @@ -67,14 +59,74 @@ target("cyber_engine_tweaks") add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\"") -- WINVER=0x0601 == Windows 7xmake set_pcxxheader("src/stdafx.h") set_kind("shared") - set_filename("cyber_engine_tweaks.asi") - add_files("src/**.cpp") - add_headerfiles("src/**.h", "build/CETVersion.h") + + set_configdir(path.join("src", "config")) + add_configfiles("src/xmake/**.in") + + add_files("src/**.cpp", "src/**.rc") + add_headerfiles("src/**.h") add_includedirs("src/", "build/") add_syslinks("User32", "Version", "d3d11", "dxgi") add_packages("spdlog", "nlohmann_json", "minhook", "hopscotch-map", "imgui", "mem", "sol2", "tiltedcore", "sqlite3", "openrestry-luajit", "xbyak", "stb") add_deps("RED4ext.SDK") - add_configfiles("src/CETVersion.h.in") + + -- Set up basic config variables. + -- Required for us to set up something here first to be able to access and modify "configvars" + -- in `on_load`, there seems to be no way to do this otherwise at the moment. + set_configvar("CET_PRODUCT_NAME", "Cyber Engine Tweaks") + + on_load(function(target) + -- Set filename based on project name + target:set("basename", target:name()) + target:set("extension", ".asi") + + -- Get a list of existing target config variables. + local configVars = target:get("configvar") + + -- Set up other basic config variables. + configVars.CET_CURRENT_YEAR = tonumber(os.date("%Y")) + configVars.CET_GROUP_NAME = configVars.CET_PRODUCT_NAME .. " Team" + configVars.CET_FILE_NAME = target:filename(); + + -- Set up build type. + if is_mode("release") then + configVars.CET_DEBUG_BUILD = 0 + else + configVars.CET_DEBUG_BUILD = 1 + target:add("defines", "CET_DEBUG") + end + + -- Emulate GIT_ XMake Git builtins so we can parse them ourselves. + -- Unable to use and access builtins unfortunately. This is taken directly from XMake source. + configVars.CET_GIT_TAG = os.iorun("git describe --tags"):gsub("%s", "") + configVars.CET_GIT_TAG_LONG = os.iorun("git describe --tags --long"):gsub("%s", "") + configVars.CET_GIT_BRANCH = os.iorun("git rev-parse --abbrev-ref HEAD"):gsub("%s", "") + configVars.CET_GIT_COMMIT = os.iorun("git rev-parse --short HEAD"):gsub("%s", "") + configVars.CET_GIT_COMMIT_LONG = os.iorun("git rev-parse HEAD"):gsub("%s", "") + configVars.CET_GIT_COMMIT_DATE = os.iorun("git log -1 --date=format:%Y%m%d%H%M%S --format=%ad"):gsub("%s", "") + + -- Split tag so we can easily extract version from it. + local splitGitTag = configVars.CET_GIT_TAG:split("%.") + assert(#splitGitTag == 3) + + -- Setup version variables. + configVars.CET_VERSION_MAJOR = tonumber(splitGitTag[1]:match("%d+")) + configVars.CET_VERSION_MINOR = tonumber(splitGitTag[2]:match("%d+")) + configVars.CET_VERSION_PATCH = tonumber(splitGitTag[3]:match("%d+")) + configVars.CET_VERSION_SIMPLE = format( + "%d.%d.%d", + configVars.CET_VERSION_MAJOR, + configVars.CET_VERSION_MINOR, + configVars.CET_VERSION_PATCH) + configVars.CET_VERSION_FULL = format( + "%s [%s]", + configVars.CET_GIT_TAG, + configVars.CET_GIT_BRANCH) + configVars.CET_VERSION = configVars.CET_VERSION_FULL + + -- Push new list to target. + target:add("configvar", configVars) + end) on_package(function(target) import("net.http")