From f102464752b7b01beeee79bb3dd4397e01e2116b Mon Sep 17 00:00:00 2001 From: Christophe Huybrechts Date: Wed, 11 Nov 2026 13:15:39 +0100 Subject: [PATCH] Add build pipeline and fix Linux building --- .github/workflows/build.yml | 225 ++++++++++++++++++++++++ CMakeLists.txt | 19 ++ external/CMakeLists.txt | 55 ++++-- src/CMakeLists.txt | 32 +++- src/common/network_linux.cpp | 16 -- src/common/packet_serialize.h | 2 +- src/common/stat.h | 12 +- src/servers/game/debug/window_linux.cpp | 20 +++ src/servers/hub/coordinator.h | 1 + src/servers/hub/game.cpp | 10 +- src/servers/hub/replication.h | 1 + tools/CMakeLists.txt | 2 + tools/lea/lea.cpp | 10 +- 13 files changed, 354 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 src/servers/game/debug/window_linux.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..e7595d91 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,225 @@ +name: build + +# Every push to master builds Windows and Linux and refreshes the rolling +# "latest" release. Pull requests build too, but publish nothing. +on: + push: + branches: [master] + pull_request: + branches: [master] + workflow_dispatch: + +permissions: + contents: read + +env: + PHYSX_TAG: "4.1.2" + +jobs: + # --------------------------------------------------------------------------- + # Windows -- PhysX ships prebuilt in external/physx-4.1, so nothing to fetch. + # --------------------------------------------------------------------------- + windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v7 + + # Same flow as the README: setup.bat locates VS via vswhere and loads the + # MSVC x64 environment, then the repo's own Ninja presets do the work. + # + # The *_RELEASE overrides only add debug info: CMAKE_BUILD_TYPE=Release + # emits no PDBs on its own, and we ship them. /Z7 rather than /Zi because + # Ninja compiles in parallel and /Zi would have every cl.exe contending + # for one vc.pdb. /DEBUG implies /OPT:NOREF, so REF|ICF are restored. + - name: Build + shell: cmd + run: | + call .\setup.bat + if errorlevel 1 exit /b 1 + where ninja >nul 2>&1 || set "PATH=%VSINSTALLDIR%Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;%PATH%" + cmake --preset release ^ + -DCMAKE_C_FLAGS_RELEASE="/O2 /Ob2 /DNDEBUG /Z7" ^ + -DCMAKE_CXX_FLAGS_RELEASE="/O2 /Ob2 /DNDEBUG /Z7" ^ + -DCMAKE_EXE_LINKER_FLAGS_RELEASE="/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF" ^ + -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="/INCREMENTAL:NO /DEBUG /OPT:REF /OPT:ICF" + if errorlevel 1 exit /b 1 + cmake --build --preset release + if errorlevel 1 exit /b 1 + + # All binaries land in build/ (only intermediates go to build/release). + # build/gamedata is deliberately excluded: game data comes from the + # client, not from us. + - name: Stage package + shell: pwsh + run: | + $ErrorActionPreference = 'Stop' + $stage = 'stage/win64' + New-Item -ItemType Directory -Force -Path $stage, "$stage/third-party-licenses" | Out-Null + + foreach ($srv in 'login_srv', 'hub_srv', 'mm_srv', 'game_srv') { + Copy-Item "build/$srv.exe" $stage + Copy-Item "build/$srv.pdb" $stage + } + Copy-Item 'build/PhysX*.dll' $stage + Copy-Item 'external/physx-4.1/LICENSE.md' "$stage/third-party-licenses/PhysX-4.1-LICENSE.md" + Copy-Item 'LICENSE.md' $stage + + - uses: actions/upload-artifact@v4 + with: + name: win64 + path: stage/win64/ + if-no-files-found: error + + # --------------------------------------------------------------------------- + # Linux -- PhysX has no prebuilt Linux binaries, so it is built from source + # and cached. First run is slow; later runs restore in seconds. + # --------------------------------------------------------------------------- + linux: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + + - name: Install build tools + run: | + sudo apt-get update + sudo apt-get install -y ninja-build clang + + - name: Cache PhysX + id: physx-cache + uses: actions/cache@v4 + with: + path: ~/physx-libs + key: physx-${{ env.PHYSX_TAG }}-${{ runner.os }}-clang-v1 + + # PhysX 4.1 predates these compilers and builds with -Werror alongside + # clang's -Weverything, so every warning added to clang since 2021 breaks + # it. Dropping -Werror is the only change needed. + - name: Build PhysX + if: steps.physx-cache.outputs.cache-hit != 'true' + run: | + set -e + git clone --depth 1 --branch 4.1 https://github.com/NVIDIAGameWorks/PhysX.git /tmp/physx-src + cd /tmp/physx-src + sed -i 's/ -Werror//g' physx/source/compiler/cmake/linux/CMakeLists.txt + sed -e 's/PX_BUILDSNIPPETS" value="True"/PX_BUILDSNIPPETS" value="False"/' \ + -e 's/PX_BUILDPUBLICSAMPLES" value="True"/PX_BUILDPUBLICSAMPLES" value="False"/' \ + -e 's/name="linux"/name="linux-headless"/' \ + physx/buildtools/presets/public/linux.xml \ + > physx/buildtools/presets/public/linux-headless.xml + cd physx + export PHYSX_ROOT_DIR="$PWD" + export PM_PxShared_PATH="$PHYSX_ROOT_DIR/../pxshared" + export PM_CMakeModules_PATH="$PHYSX_ROOT_DIR/../externals/cmakemodules" + export PM_PATHS="$PM_CMakeModules_PATH" + python3 ./buildtools/cmake_generate_projects.py linux-headless + cmake --build compiler/linux-headless-release -j "$(nproc)" + mkdir -p ~/physx-libs + cp bin/linux.clang/release/*.a ~/physx-libs/ + ls -la ~/physx-libs + + # -g plus a split of the debug info into .debug files, so the shipped + # binaries stay small while crashes remain symbolicatable -- the Linux + # equivalent of the PDBs the Windows job ships. + - name: Build + run: | + cmake --preset release \ + -DPHYSX_LINUX_LIB_DIR="$HOME/physx-libs" \ + -DCMAKE_C_FLAGS_RELEASE="-O3 -DNDEBUG -g" \ + -DCMAKE_CXX_FLAGS_RELEASE="-O3 -DNDEBUG -g" + cmake --build --preset release + + - name: Stage package + run: | + set -e + stage=stage/linux64 + mkdir -p "$stage/third-party-licenses" + for srv in login_srv hub_srv mm_srv game_srv; do + cp "build/$srv" "$stage/" + objcopy --only-keep-debug "$stage/$srv" "$stage/$srv.debug" + objcopy --strip-debug "$stage/$srv" + objcopy --add-gnu-debuglink="$stage/$srv.debug" "$stage/$srv" + chmod +x "$stage/$srv" + done + cp external/physx-4.1/LICENSE.md "$stage/third-party-licenses/PhysX-4.1-LICENSE.md" + cp LICENSE.md "$stage/" + ls -la "$stage" + + - uses: actions/upload-artifact@v4 + with: + name: linux64 + path: stage/linux64/ + if-no-files-found: error + + # --------------------------------------------------------------------------- + # Rolling release: one "latest" tag, replaced on every push to master. + # --------------------------------------------------------------------------- + release: + needs: [windows, linux] + if: github.event_name == 'push' && github.ref == 'refs/heads/master' + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Package + run: | + set -e + built=$(date -u '+%Y-%m-%d %H:%M:%S UTC') + for plat in win64 linux64; do + cat > "artifacts/$plat/BUILDINFO.txt" < notes.md < when its configure script says so; without + # it gz*.c implicitly declares read/write/lseek/close, an error from GCC 14 on. + target_compile_definitions(zlib PRIVATE Z_HAVE_UNISTD_H) endif() # ---- EA foundation libraries ---- @@ -49,6 +53,11 @@ target_compile_definitions(eastl PRIVATE EASTL_OPENSOURCE=1) target_link_libraries(eastl PUBLIC eastdc) +if(NOT WIN32) + # the lea tool is a shared library, so everything it pulls in must be PIC + set_target_properties(eaassert eathread eastdc eastl PROPERTIES POSITION_INDEPENDENT_CODE ON) +endif() + # ---- tinyxml2 (compiled into the server targets, as genie did) ---- add_library(tinyxml2 INTERFACE) target_include_directories(tinyxml2 INTERFACE ${EXTERNAL_DIR}/tinyxml2-8.0.0) @@ -62,23 +71,41 @@ file(GLOB IMGUI_SOURCES CONFIGURE_DEPENDS ${EXTERNAL_DIR}/imgui-1.81/*.cpp) add_library(imgui STATIC ${IMGUI_SOURCES}) target_include_directories(imgui PUBLIC ${EXTERNAL_DIR}/imgui-1.81) -# ---- PhysX (prebuilt win64 libs) ---- +# ---- PhysX ---- +if(MXM_HAVE_PHYSX) add_library(physx INTERFACE) target_include_directories(physx INTERFACE ${PHYSX_DIR}/include/physx ${PHYSX_DIR}/include/pxshared) -target_link_directories(physx INTERFACE - "$<$:${PHYSX_DIR}/lib/debug>" - "$<$:${PHYSX_DIR}/lib/checked>" - "$<$>:${PHYSX_DIR}/lib/release>" -) -target_link_libraries(physx INTERFACE - PhysXExtensions_static_64 - PhysX_64 - PhysXPvdSDK_static_64 - PhysXCommon_64 - PhysXFoundation_64 - PhysXCooking_64 - PhysXCharacterKinematic_static_64) +if(WIN32) + target_link_directories(physx INTERFACE + "$<$:${PHYSX_DIR}/lib/debug>" + "$<$:${PHYSX_DIR}/lib/checked>" + "$<$>:${PHYSX_DIR}/lib/release>" + ) + target_link_libraries(physx INTERFACE + PhysXExtensions_static_64 + PhysX_64 + PhysXPvdSDK_static_64 + PhysXCommon_64 + PhysXFoundation_64 + PhysXCooking_64 + PhysXCharacterKinematic_static_64) +else() + # PhysX 4.1 builds every module static on Linux and they reference each + # other, so they have to be resolved as a single link group. + target_link_directories(physx INTERFACE ${PHYSX_LINUX_LIB_DIR}) + target_link_libraries(physx INTERFACE + -Wl,--start-group + PhysXExtensions_static_64 + PhysX_static_64 + PhysXPvdSDK_static_64 + PhysXCommon_static_64 + PhysXFoundation_static_64 + PhysXCooking_static_64 + PhysXCharacterKinematic_static_64 + -Wl,--end-group) +endif() +endif() # copy_physx_dlls() is defined in the root CMakeLists.txt diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1c01891..02881ffe 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,6 +22,11 @@ file(GLOB_RECURSE GAME_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/servers/game/*.h ${CMAKE_CURRENT_SOURCE_DIR}/servers/game/*.c ${CMAKE_CURRENT_SOURCE_DIR}/servers/game/*.cpp) +if(NOT WIN32) + list(FILTER GAME_SOURCES EXCLUDE REGEX "/servers/game/debug/") + list(APPEND GAME_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/servers/game/debug/window_linux.cpp) +endif() + file(GLOB_RECURSE MM_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/servers/matchmaker/*.h ${CMAKE_CURRENT_SOURCE_DIR}/servers/matchmaker/*.c @@ -36,7 +41,11 @@ set(SERVER_COMMON_INCLUDES ${EXTERNAL_DIR}/tracy-0.8 ${EXTERNAL_DIR}/glm_0.9.9.8) set(SERVER_COMMON_LINKS zlib eastl eathread eastdc tinyxml2) -set(SERVER_COMMON_LINKS_WIN ws2_32 user32 advapi32) +if(WIN32) + set(SERVER_COMMON_LINKS_PLATFORM ws2_32 user32 advapi32) +else() + set(SERVER_COMMON_LINKS_PLATFORM pthread dl) +endif() set(SERVER_COMMON_DEFINES GLM_FORCE_XYZW_ONLY) set(NATVIS ${EXTERNAL_DIR}/EASTL-3.16.07/doc/EASTL.natvis) @@ -47,7 +56,7 @@ if(WIN32) target_sources(login_srv PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/servers/login/login_rc.rc) endif() target_include_directories(login_srv PRIVATE ${SRC_DIR} ${EA_INCLUDES}) -target_link_libraries(login_srv PRIVATE eastl eathread eastdc ws2_32) +target_link_libraries(login_srv PRIVATE eastl eathread eastdc ${SERVER_COMMON_LINKS_PLATFORM}) if(MSVC) target_sources(login_srv PRIVATE ${NATVIS}) endif() @@ -62,7 +71,7 @@ if(WIN32) target_sources(hub_srv PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/servers/hub/hub_rc.rc) endif() target_include_directories(hub_srv PRIVATE ${SERVER_COMMON_INCLUDES}) -target_link_libraries(hub_srv PRIVATE ${SERVER_COMMON_LINKS} ${SERVER_COMMON_LINKS_WIN}) +target_link_libraries(hub_srv PRIVATE ${SERVER_COMMON_LINKS} ${SERVER_COMMON_LINKS_PLATFORM}) target_compile_definitions(hub_srv PRIVATE ${SERVER_COMMON_DEFINES}) if(MSVC) target_sources(hub_srv PRIVATE ${NATVIS}) @@ -71,6 +80,7 @@ add_dependencies(hub_srv sync_gamedata) mxm_debug_suffix(hub_srv) # ---- GameServer (game_srv) ---- +if(MXM_HAVE_PHYSX) add_executable(game_srv ${COMMON_SOURCES} ${MXM_SOURCES} ${GAME_SOURCES} ${EXTERNAL_DIR}/tinyxml2-8.0.0/tinyxml2.cpp @@ -80,11 +90,15 @@ if(WIN32) endif() target_include_directories(game_srv PRIVATE ${SERVER_COMMON_INCLUDES} - ${EXTERNAL_DIR}/sokol - ${EXTERNAL_DIR}/imgui-1.81 ${CMAKE_CURRENT_SOURCE_DIR}/servers/game) target_link_libraries(game_srv PRIVATE - ${SERVER_COMMON_LINKS} ${SERVER_COMMON_LINKS_WIN} imgui sokol physx) + ${SERVER_COMMON_LINKS} ${SERVER_COMMON_LINKS_PLATFORM} physx) +if(WIN32) + target_include_directories(game_srv PRIVATE + ${EXTERNAL_DIR}/sokol + ${EXTERNAL_DIR}/imgui-1.81) + target_link_libraries(game_srv PRIVATE imgui sokol) +endif() target_compile_definitions(game_srv PRIVATE ${SERVER_COMMON_DEFINES}) if(MSVC) target_sources(game_srv PRIVATE ${NATVIS}) @@ -92,6 +106,7 @@ endif() copy_physx_dlls(game_srv) add_dependencies(game_srv sync_gamedata) mxm_debug_suffix(game_srv) +endif() # ---- MatchMaker (mm_srv) ---- add_executable(mm_srv @@ -104,7 +119,7 @@ endif() target_include_directories(mm_srv PRIVATE ${SERVER_COMMON_INCLUDES} ${CMAKE_CURRENT_SOURCE_DIR}/servers/matchmaker) -target_link_libraries(mm_srv PRIVATE ${SERVER_COMMON_LINKS} ${SERVER_COMMON_LINKS_WIN}) +target_link_libraries(mm_srv PRIVATE ${SERVER_COMMON_LINKS} ${SERVER_COMMON_LINKS_PLATFORM}) target_compile_definitions(mm_srv PRIVATE ${SERVER_COMMON_DEFINES}) if(MSVC) target_sources(mm_srv PRIVATE ${NATVIS}) @@ -114,6 +129,9 @@ mxm_debug_suffix(mm_srv) # ---- Profiling (was: genie --profile -> TRACY_ENABLE on Release) ---- if(PROFILE) foreach(srv hub_srv game_srv mm_srv) + if(NOT TARGET ${srv}) + continue() + endif() target_compile_definitions(${srv} PRIVATE "$<$>:TRACY_ENABLE>") endforeach() endif() diff --git a/src/common/network_linux.cpp b/src/common/network_linux.cpp index fb508b19..4955f108 100644 --- a/src/common/network_linux.cpp +++ b/src/common/network_linux.cpp @@ -266,20 +266,4 @@ void AsyncConnection::CropPartialPackets() } } -// https://stackoverflow.com/a/4135003 -/** - * number of seconds from 1 Jan. 1601 00:00 to 1 Jan 1970 00:00 UTC - */ -#define EPOCH_DIFF 11644473600LL - -uint64_t CurrentFiletimeTimestampUTC() -{ - struct timeval tv; - uint64_t result = EPOCH_DIFF; - gettimeofday(&tv, NULL); - result += tv.tv_sec; - result *= 10000000LL; - result += tv.tv_usec * 10; - return result; -} #endif diff --git a/src/common/packet_serialize.h b/src/common/packet_serialize.h index 453dc5be..aee6f295 100644 --- a/src/common/packet_serialize.h +++ b/src/common/packet_serialize.h @@ -24,7 +24,7 @@ namespace PS } #define SER_BEGIN() auto& str = PS::NewString() -#define SER(fmt, ...) str.append_sprintf(fmt "\n", __VA_ARGS__); +#define SER(fmt, ...) str.append_sprintf(fmt "\n", ##__VA_ARGS__); template const char* PacketSerialize(const void* packetData, const i32 packetSize) diff --git a/src/common/stat.h b/src/common/stat.h index 7feb159b..0f066bf8 100644 --- a/src/common/stat.h +++ b/src/common/stat.h @@ -14,10 +14,10 @@ inline void WriteInitStat(W& packet, const StatValue* stats, u16 count) ASSERT(stats); ASSERT(count > 0); - packet.Write(count); + packet.template Write(count); for(u16 i = 0; i < count; i++) { - packet.Write(stats[i].type); - packet.Write(stats[i].value); + packet.template Write(stats[i].type); + packet.template Write(stats[i].value); } StatValue cur[8]; @@ -49,10 +49,10 @@ inline void WriteInitStat(W& packet, const StatValue* stats, u16 count) if(hasRes) cur[n++] = { resourceType, resourceVal }; if(stamina != 0.f) cur[n++] = { (u8)StatType::STAT_TYPE_STAMINA, stamina }; - packet.Write(n); + packet.template Write(n); for(u16 i = 0; i < n; i++) { - packet.Write(cur[i].type); - packet.Write(cur[i].value); + packet.template Write(cur[i].type); + packet.template Write(cur[i].value); } } diff --git a/src/servers/game/debug/window_linux.cpp b/src/servers/game/debug/window_linux.cpp new file mode 100644 index 00000000..6b8160b4 --- /dev/null +++ b/src/servers/game/debug/window_linux.cpp @@ -0,0 +1,20 @@ +#ifdef CONF_LINUX +#include "window.h" + +void WindowCreate() {} +intptr_t ThreadWindow(void*) { return 0; } +void WindowRequestClose() {} +void WindowWaitForCleanup() {} + +namespace Dbg { + +GameUID PushNewGame(const FixedStr32&) { return GameUID::INVALID; } +void PushNewFrame(GameUID) {} +void Push(GameUID, const PlayerMaster&) {} +void Push(GameUID, const Npc&) {} +void Push(GameUID, const Dynamic&) {} +void PushPhysics(GameUID, const PhysicsScene&) {} +void PopGame(GameUID) {} + +} +#endif diff --git a/src/servers/hub/coordinator.h b/src/servers/hub/coordinator.h index c37045cc..6f601476 100644 --- a/src/servers/hub/coordinator.h +++ b/src/servers/hub/coordinator.h @@ -5,6 +5,7 @@ #include #include +#include "config.h" #include "matchmaker_connector.h" #include "instance.h" #include "account.h" diff --git a/src/servers/hub/game.cpp b/src/servers/hub/game.cpp index 641c5e05..eafd6018 100644 --- a/src/servers/hub/game.cpp +++ b/src/servers/hub/game.cpp @@ -478,7 +478,7 @@ bool HubGame::ParseChatCommand(ClientHandle clientHd, const wchar* msg, const i3 if (EA::StdC::Strncmp(msg, L"spawn ", 6) == 0) { msg += 6; // skip command - int classTypeVal = _wtoi(msg); // convert wide string to integer + int classTypeVal = EA::StdC::AtoI32(msg); // convert wide string to integer WorldHub::ActorCore* playerActor = world.FindPlayerActor(playerActorUID[userID]); ASSERT(playerActor); @@ -516,14 +516,14 @@ bool HubGame::ParseChatCommand(ClientHandle clientHd, const wchar* msg, const i3 wchar firstNum[32]; size_t len = space - msg; if (len < sizeof(firstNum)) { - wcsncpy(firstNum, msg, len); + EA::StdC::Strncpy(firstNum, msg, len); firstNum[len] = L'\0'; - classTypeVal = _wtoi(firstNum); - skinIndex = _wtoi(space + 1); // Convert second number after space + classTypeVal = EA::StdC::AtoI32(firstNum); + skinIndex = EA::StdC::AtoI32(space + 1); // Convert second number after space } } else { - classTypeVal = _wtoi(msg); // Just class type provided + classTypeVal = EA::StdC::AtoI32(msg); // Just class type provided } WorldHub::ActorPlayer* playerActor = world.FindPlayerActor(playerActorUID[userID]); diff --git a/src/servers/hub/replication.h b/src/servers/hub/replication.h index d4cd7be7..571ec3b2 100644 --- a/src/servers/hub/replication.h +++ b/src/servers/hub/replication.h @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b5f718b8..05bac8cf 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -35,6 +35,7 @@ target_link_libraries(navmesh PRIVATE ${TOOL_COMMON_LINKS}) mxm_debug_suffix(navmesh) # ---- ToolCollision (col) ---- +if(MXM_HAVE_PHYSX) add_executable(col ${TOOL_COMMON_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/collision/tool_collision.cpp) target_include_directories(col PRIVATE ${TOOL_COMMON_INCLUDES} @@ -42,3 +43,4 @@ target_include_directories(col PRIVATE target_link_libraries(col PRIVATE ${TOOL_COMMON_LINKS} physx) copy_physx_dlls(col) mxm_debug_suffix(col) +endif() diff --git a/tools/lea/lea.cpp b/tools/lea/lea.cpp index c340c73c..91c21092 100644 --- a/tools/lea/lea.cpp +++ b/tools/lea/lea.cpp @@ -693,8 +693,14 @@ union Filter // C api extern "C" { -__declspec(dllexport) Filter* GenerateKey(const char* ipPortString); -__declspec(dllexport) void Decrypt(Filter* filter, void* data, const i32 dataSize); +#ifdef CONF_WINDOWS +#define LEA_EXPORT __declspec(dllexport) +#else +#define LEA_EXPORT __attribute__((visibility("default"))) +#endif + +LEA_EXPORT Filter* GenerateKey(const char* ipPortString); +LEA_EXPORT void Decrypt(Filter* filter, void* data, const i32 dataSize); } Filter* GenerateKey(const char* ipPortString)