Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better versioning #1004

Merged
merged 1 commit into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ package/*
vs2022/*
vsxmake*/
*.pyc
src/config/*
4 changes: 0 additions & 4 deletions src/CETVersion.h.in

This file was deleted.

3 changes: 2 additions & 1 deletion src/Options.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdafx.h>

#include "config/CETVersion.h"
#include "Paths.h"
#include "Utils.h"
#include "RED4ext/Api/Runtime.hpp"
Expand Down Expand Up @@ -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()));
Expand Down
4 changes: 3 additions & 1 deletion src/scripting/Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Scripting.h"

#include "config/CETVersion.h"

#include "FunctionOverride.h"
#include "GameOptions.h"
#include "Texture.h"
Expand Down Expand Up @@ -125,7 +127,7 @@ void Scripting::Initialize()

globals["GetVersion"] = []() -> std::string
{
return CET_BUILD_COMMIT;
return CET_GIT_TAG;
};

globals["GetDisplayResolution"] = [this]() -> std::tuple<float, float>
Expand Down
1 change: 0 additions & 1 deletion src/stdafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
#include <unordered_map>
#include <vector>

#include "CETVersion.h"
#include "common/Logging.h"
#include "common/FontMaterialDesignIcons.h"
#include "common/ImGuiNotify.h"
Expand Down
21 changes: 21 additions & 0 deletions src/xmake/CETVersion.h.in
Original file line number Diff line number Diff line change
@@ -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}
31 changes: 31 additions & 0 deletions src/xmake/Resource.rc.in
Original file line number Diff line number Diff line change
@@ -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
90 changes: 71 additions & 19 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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_<XXX> 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")
Expand Down