Skip to content

Commit 2021ef3

Browse files
committed
feat: generate hamdata.ini automatically on every build
1 parent a699fd0 commit 2021ef3

File tree

7 files changed

+99
-8
lines changed

7 files changed

+99
-8
lines changed

.github/workflows/CI.yml

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
1414
jobs:
1515
build:
16-
name: "Build"
16+
name: "Build on ${{ matrix.os.suffix }}"
1717

1818
strategy:
1919
matrix:
@@ -58,6 +58,9 @@ jobs:
5858
vcpkgDirectory: '${{env.VCPKG_ROOT}}'
5959
vcpkgGitCommitId: 'ef7dbf94b9198bc58f45951adcf1f041fcbc5ea0'
6060
runVcpkgInstall: false
61+
62+
- name: Set up rust
63+
uses: actions-rust-lang/[email protected]
6164

6265
# Run CMake+vcpkg+Ninja+CTest to generate/build/test.
6366
- name: Build and Test with CMake
@@ -77,8 +80,8 @@ jobs:
7780
run: |
7881
cmake --install ${{github.workspace}}/_build/github-actions --config RelWithDebInfo --prefix ${{github.workspace}}/_build/ci-install --component ${{ matrix.target }}
7982
80-
# Prepare artifact
81-
- name: Prepare artifact
83+
# Prepare and Upload Artifact
84+
- name: Prepare and Upload Artifact
8285
id: prepare_artifact
8386
run: >
8487
python scripts/package_target.py
@@ -87,10 +90,37 @@ jobs:
8790
--artifact-dir ${{github.workspace}}/_build/ci-artifact
8891
--target ${{ matrix.target }}
8992
--suffix ${{ matrix.os.suffix }}
93+
- uses: actions/upload-artifact@v4
94+
with:
95+
name: ${{ steps.prepare_artifact.outputs.artifact_name }}
96+
path: ${{github.workspace}}/_build/ci-artifact/${{ steps.prepare_artifact.outputs.artifact_name }}
97+
98+
package:
99+
name: "Package Release"
100+
needs: build
101+
runs-on: ubuntu-latest
102+
103+
steps:
104+
- name: Download all artifacts
105+
uses: actions/download-artifact@v4
106+
with:
107+
path: artifacts
90108

91-
# Upload result
92-
- name: Upload build result
109+
- name: Copy hamdata.ini to Windows artifact
110+
run: |
111+
mkdir -p artifacts/AG-server-ci-windows/ag_addon/addons/amxmodx/configs
112+
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
113+
114+
- name: Upload Windows Artifact
93115
uses: actions/upload-artifact@v4
94116
with:
95-
name: ${{ steps.prepare_artifact.outputs.artifact_name }}
96-
path: ${{github.workspace}}/_build/ci-artifact
117+
name: AG-server-ci-windows
118+
path: artifacts/AG-server-ci-windows
119+
overwrite: true
120+
121+
- name: Upload Linux Artifact
122+
uses: actions/upload-artifact@v4
123+
with:
124+
name: AG-server-ci-linux
125+
path: artifacts/AG-server-ci-linux
126+
overwrite: true

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ include( CTest )
3333
option( AUTO_DEPLOY "Whether to automatically deploy to deploy paths" )
3434
option( NO_STEAM_API "Disable Steam API" )
3535
option( GENERATE_AMXX_OFFSETS "Generate AMXX offsets when building" )
36+
option( GENERATE_HAMDATA_INI "Generate hamdata.ini when building" )
3637

3738
#-----------------------------------------------------------------
3839
# Compiler checks

CMakePresets.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
"AUTO_DEPLOY": false,
2020
"GENERATE_AMXX_OFFSETS": false,
21+
"GENERATE_HAMDATA_INI": false,
2122
"GNU_FORCE_COLORED_OUTPUT": true
2223
}
2324
},
@@ -28,6 +29,7 @@
2829
"cacheVariables": {
2930
"GNU_FORCE_COLORED_OUTPUT": false,
3031
"GENERATE_AMXX_OFFSETS": true,
32+
"GENERATE_HAMDATA_INI": true,
3133
"WARNINGS_ARE_ERRORS": true
3234
}
3335
}

CMakeUserPresets.example.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"inherits": ["base", "platform-generator"],
77
"cacheVariables": {
88
"AUTO_DEPLOY": true,
9-
"GENERATE_AMXX_OFFSETS": false
9+
"GENERATE_AMXX_OFFSETS": false,
10+
"GENERATE_HAMDATA_INI": false
1011
}
1112
}
1213
],

cmake/InstallHamdataIni.cmake.in

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Set the binary dir path from configure_file
2+
set( ACTUAL_BINARY_DIR "@CMAKE_BINARY_DIR@" )
3+
4+
set( hamdata_ini "${ACTUAL_BINARY_DIR}/hamdata_ini_generator/target/release/output/auto_hamdata190.ini" )
5+
6+
if( NOT EXISTS ${hamdata_ini} )
7+
message( FATAL_ERROR "hamdata.ini file not found at: ${hamdata_ini}" )
8+
endif()
9+
10+
# Install it
11+
file(
12+
INSTALL ${hamdata_ini}
13+
DESTINATION "${CMAKE_INSTALL_PREFIX}/addons/amxmodx/configs"
14+
RENAME "hamdata.ini"
15+
)

gamedir/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,3 +413,18 @@ if( GENERATE_AMXX_OFFSETS )
413413
COMPONENT server
414414
)
415415
endif()
416+
417+
if ( GENERATE_HAMDATA_INI AND PLATFORM_LINUX )
418+
# Generate the install script
419+
configure_file(
420+
${CMAKE_SOURCE_DIR}/cmake/InstallHamdataIni.cmake.in
421+
${CMAKE_CURRENT_BINARY_DIR}/InstallHamdataIni.cmake
422+
@ONLY
423+
)
424+
425+
# Install hamdata.ini file
426+
install(
427+
SCRIPT ${CMAKE_CURRENT_BINARY_DIR}/InstallHamdataIni.cmake
428+
COMPONENT server
429+
)
430+
endif()

src/game/server/CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,30 @@ if( GENERATE_AMXX_OFFSETS )
319319
${AMXX_OFFSETS_CLASS_LIST}
320320
)
321321
endif()
322+
323+
if( GENERATE_HAMDATA_INI AND PLATFORM_LINUX )
324+
set( HAMDATA_GENERATOR_REPO_DIR "${CMAKE_BINARY_DIR}/hamdata_ini_generator" )
325+
set( HAMDATA_GENERATOR_DIR "${HAMDATA_GENERATOR_REPO_DIR}/target/release" )
326+
set( HAMDATA_GENERATOR_EXEC "${HAMDATA_GENERATOR_DIR}/vtable" )
327+
328+
FetchContent_Declare(
329+
hamdata_ini_generator
330+
GIT_REPOSITORY https://github.com/ag-community/hamdata_ini_generator
331+
SOURCE_DIR ${HAMDATA_GENERATOR_REPO_DIR}
332+
)
333+
334+
FetchContent_MakeAvailable( hamdata_ini_generator )
335+
336+
add_custom_command(
337+
TARGET server POST_BUILD
338+
COMMAND make -C ${HAMDATA_GENERATOR_REPO_DIR} release
339+
COMMENT "Compiling hamdata.ini generator"
340+
)
341+
342+
add_custom_command(
343+
TARGET server POST_BUILD
344+
COMMAND ${HAMDATA_GENERATOR_EXEC} vtable-dump $<TARGET_FILE:server>
345+
WORKING_DIRECTORY ${HAMDATA_GENERATOR_DIR}
346+
COMMENT "Generating hamdata.ini"
347+
)
348+
endif()

0 commit comments

Comments
 (0)