From 2021ef3c308ed572bbf4844baf0682a51cc386ed Mon Sep 17 00:00:00 2001 From: 7mochi Date: Fri, 17 Oct 2025 01:39:02 -0500 Subject: [PATCH] feat: generate hamdata.ini automatically on every build --- .github/workflows/CI.yml | 44 +++++++++++++++++++++++++++----- CMakeLists.txt | 1 + CMakePresets.json | 2 ++ CMakeUserPresets.example.json | 3 ++- cmake/InstallHamdataIni.cmake.in | 15 +++++++++++ gamedir/CMakeLists.txt | 15 +++++++++++ src/game/server/CMakeLists.txt | 27 ++++++++++++++++++++ 7 files changed, 99 insertions(+), 8 deletions(-) create mode 100644 cmake/InstallHamdataIni.cmake.in diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f83a25cf..b564f401 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,7 +13,7 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: build: - name: "Build" + name: "Build on ${{ matrix.os.suffix }}" strategy: matrix: @@ -58,6 +58,9 @@ jobs: vcpkgDirectory: '${{env.VCPKG_ROOT}}' vcpkgGitCommitId: 'ef7dbf94b9198bc58f45951adcf1f041fcbc5ea0' runVcpkgInstall: false + + - name: Set up rust + uses: actions-rust-lang/setup-rust-toolchain@v1.15.0 # Run CMake+vcpkg+Ninja+CTest to generate/build/test. - name: Build and Test with CMake @@ -77,8 +80,8 @@ jobs: run: | cmake --install ${{github.workspace}}/_build/github-actions --config RelWithDebInfo --prefix ${{github.workspace}}/_build/ci-install --component ${{ matrix.target }} - # Prepare artifact - - name: Prepare artifact + # Prepare and Upload Artifact + - name: Prepare and Upload Artifact id: prepare_artifact run: > python scripts/package_target.py @@ -87,10 +90,37 @@ jobs: --artifact-dir ${{github.workspace}}/_build/ci-artifact --target ${{ matrix.target }} --suffix ${{ matrix.os.suffix }} + - uses: actions/upload-artifact@v4 + with: + name: ${{ steps.prepare_artifact.outputs.artifact_name }} + path: ${{github.workspace}}/_build/ci-artifact/${{ steps.prepare_artifact.outputs.artifact_name }} + + package: + name: "Package Release" + needs: build + runs-on: ubuntu-latest + + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts - # Upload result - - name: Upload build result + - name: Copy hamdata.ini to Windows artifact + run: | + mkdir -p artifacts/AG-server-ci-windows/ag_addon/addons/amxmodx/configs + cp artifacts/AG-server-ci-linux/ag_addon/addons/amxmodx/configs/hamdata.ini artifacts/AG-server-ci-windows/ag_addon/addons/amxmodx/configs/hamdata.ini + + - name: Upload Windows Artifact uses: actions/upload-artifact@v4 with: - name: ${{ steps.prepare_artifact.outputs.artifact_name }} - path: ${{github.workspace}}/_build/ci-artifact + name: AG-server-ci-windows + path: artifacts/AG-server-ci-windows + overwrite: true + + - name: Upload Linux Artifact + uses: actions/upload-artifact@v4 + with: + name: AG-server-ci-linux + path: artifacts/AG-server-ci-linux + overwrite: true diff --git a/CMakeLists.txt b/CMakeLists.txt index c132e32c..bbcf1c3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ include( CTest ) option( AUTO_DEPLOY "Whether to automatically deploy to deploy paths" ) option( NO_STEAM_API "Disable Steam API" ) option( GENERATE_AMXX_OFFSETS "Generate AMXX offsets when building" ) +option( GENERATE_HAMDATA_INI "Generate hamdata.ini when building" ) #----------------------------------------------------------------- # Compiler checks diff --git a/CMakePresets.json b/CMakePresets.json index 7d69f58f..c8c033ca 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -18,6 +18,7 @@ "AUTO_DEPLOY": false, "GENERATE_AMXX_OFFSETS": false, + "GENERATE_HAMDATA_INI": false, "GNU_FORCE_COLORED_OUTPUT": true } }, @@ -28,6 +29,7 @@ "cacheVariables": { "GNU_FORCE_COLORED_OUTPUT": false, "GENERATE_AMXX_OFFSETS": true, + "GENERATE_HAMDATA_INI": true, "WARNINGS_ARE_ERRORS": true } } diff --git a/CMakeUserPresets.example.json b/CMakeUserPresets.example.json index d2d10800..7679a528 100644 --- a/CMakeUserPresets.example.json +++ b/CMakeUserPresets.example.json @@ -6,7 +6,8 @@ "inherits": ["base", "platform-generator"], "cacheVariables": { "AUTO_DEPLOY": true, - "GENERATE_AMXX_OFFSETS": false + "GENERATE_AMXX_OFFSETS": false, + "GENERATE_HAMDATA_INI": false } } ], diff --git a/cmake/InstallHamdataIni.cmake.in b/cmake/InstallHamdataIni.cmake.in new file mode 100644 index 00000000..d09c1309 --- /dev/null +++ b/cmake/InstallHamdataIni.cmake.in @@ -0,0 +1,15 @@ +# Set the binary dir path from configure_file +set( ACTUAL_BINARY_DIR "@CMAKE_BINARY_DIR@" ) + +set( hamdata_ini "${ACTUAL_BINARY_DIR}/hamdata_ini_generator/target/release/output/auto_hamdata190.ini" ) + +if( NOT EXISTS ${hamdata_ini} ) + message( FATAL_ERROR "hamdata.ini file not found at: ${hamdata_ini}" ) +endif() + +# Install it +file( + INSTALL ${hamdata_ini} + DESTINATION "${CMAKE_INSTALL_PREFIX}/addons/amxmodx/configs" + RENAME "hamdata.ini" +) \ No newline at end of file diff --git a/gamedir/CMakeLists.txt b/gamedir/CMakeLists.txt index bca453e1..bdf5ca2f 100644 --- a/gamedir/CMakeLists.txt +++ b/gamedir/CMakeLists.txt @@ -413,3 +413,18 @@ if( GENERATE_AMXX_OFFSETS ) COMPONENT server ) endif() + +if ( GENERATE_HAMDATA_INI AND PLATFORM_LINUX ) + # Generate the install script + configure_file( + ${CMAKE_SOURCE_DIR}/cmake/InstallHamdataIni.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/InstallHamdataIni.cmake + @ONLY + ) + + # Install hamdata.ini file + install( + SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/InstallHamdataIni.cmake + COMPONENT server + ) +endif() diff --git a/src/game/server/CMakeLists.txt b/src/game/server/CMakeLists.txt index b09aa34c..43ccb5c7 100644 --- a/src/game/server/CMakeLists.txt +++ b/src/game/server/CMakeLists.txt @@ -319,3 +319,30 @@ if( GENERATE_AMXX_OFFSETS ) ${AMXX_OFFSETS_CLASS_LIST} ) endif() + +if( GENERATE_HAMDATA_INI AND PLATFORM_LINUX ) + set( HAMDATA_GENERATOR_REPO_DIR "${CMAKE_BINARY_DIR}/hamdata_ini_generator" ) + set( HAMDATA_GENERATOR_DIR "${HAMDATA_GENERATOR_REPO_DIR}/target/release" ) + set( HAMDATA_GENERATOR_EXEC "${HAMDATA_GENERATOR_DIR}/vtable" ) + + FetchContent_Declare( + hamdata_ini_generator + GIT_REPOSITORY https://github.com/ag-community/hamdata_ini_generator + SOURCE_DIR ${HAMDATA_GENERATOR_REPO_DIR} + ) + + FetchContent_MakeAvailable( hamdata_ini_generator ) + + add_custom_command( + TARGET server POST_BUILD + COMMAND make -C ${HAMDATA_GENERATOR_REPO_DIR} release + COMMENT "Compiling hamdata.ini generator" + ) + + add_custom_command( + TARGET server POST_BUILD + COMMAND ${HAMDATA_GENERATOR_EXEC} vtable-dump $ + WORKING_DIRECTORY ${HAMDATA_GENERATOR_DIR} + COMMENT "Generating hamdata.ini" + ) +endif() \ No newline at end of file