Skip to content
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
81 changes: 67 additions & 14 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,90 @@ jobs:
build:
strategy:
matrix:
runs-on: [windows-2019, ubuntu-20.04]
os:
- runs-on: windows-2022
suffix: ci-windows
- runs-on: ubuntu-22.04
suffix: ci-linux

# The type of runner that the job will run on
runs-on: ${{ matrix.runs-on }}
runs-on: ${{ matrix.os.runs-on }}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3.3.0
with:
submodules: recursive

- name: Set up Python 3.8
uses: actions/setup-python@v4.5.0
with:
python-version: 3.8

fetch-depth: 0 # Required for automatic versioning

- name: Install Ubuntu packages
if: matrix.runs-on == 'ubuntu-20.04'
if: matrix.os.runs-on == 'ubuntu-22.04'
run: |
sudo dpkg --add-architecture i386
sudo apt update || true
sudo apt install -y libc6:i386 ninja-build gcc-9-multilib g++-9-multilib libssl1.1:i386 libssl-dev:i386 zlib1g-dev:i386
sudo apt install -y libc6:i386 linux-libc-dev:i386 ninja-build gcc-multilib g++-multilib

- name: Build release
id: build
run: |
python ./scripts/build_release.py --build-type release --vs 2019 --toolset v141_xp --linux-compiler gcc-9 --out-dir ./_build_out --cmake-args="-DWARNINGS_ARE_ERRORS=ON" --github-actions
cmake --preset github-actions
cmake --build --preset github-actions
cmake --install ${{github.workspace}}/_build/github-actions --config RelWithDebInfo --prefix ${{github.workspace}}/_build/ci-install

# Prepare artifact
- name: Prepare artifact
id: prepare_artifact
run: >
python scripts/package_target.py
--build-dir ${{github.workspace}}/_build/github-actions
--install-dir ${{github.workspace}}/_build/ci-install
--artifact-dir ${{github.workspace}}/_build/ci-artifact
--suffix ${{ matrix.os.suffix }}

# Upload result
- name: Upload build result
uses: actions/upload-artifact@v4.6.0
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build.outputs.artifact_name }}
path: ./_build_out/WeaponMod-*.zip
name: ${{ steps.prepare_artifact.outputs.artifact_name }}
path: ${{github.workspace}}/_build/ci-artifact

merge-artifacts:
name: "Merge Artifacts"
needs: build
runs-on: ubuntu-latest

env:
# Must also be updated in src/game/server/CMakeLists.txt
AMXX_OFFSET_GENERATOR_VERSION: "1.0.1"

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v4
with:
submodules: false # Only need scripts folder

# Download artifacts
- uses: actions/download-artifact@v4
with:
path: ${{github.workspace}}/_build/ci-artifacts
pattern: "*-ci-*"
merge-multiple: true

# Merge them
- name: Merge artifacts
id: merge_artifacts
run: >
python scripts/merge_artifacts.py
--artifact-dir ${{github.workspace}}/_build/ci-artifacts
--out-dir ${{github.workspace}}/_build/ci-out-artifact
ci-linux
ci-windows

# Upload merged artifact
- name: Upload merged artifact
uses: actions/upload-artifact@v4
with:
name: ${{ steps.merge_artifacts.outputs.artifact_name }}
path: ${{github.workspace}}/_build/ci-out-artifact

15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
/_build*
/.build*
# CMake build directory
/build
/build_*
/_build
/_build_*
CMakeUserPresets.json

# macOS garbage
.DS_Store

# Ignore .vscode but allow examples
.vscode/*
!.vscode/**/*.example.*
12 changes: 12 additions & 0 deletions .vscode/settings.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"[cmake]": {
"editor.insertSpaces": false,
"editor.tabSize": 4
},
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"clangd.arguments": [
"-header-insertion=never",
"--compile-commands-dir=_build/user"
],
"cmake.useCMakePresets": "always"
}
32 changes: 19 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ include(InputFilesList)
include(WinXPSupport)
include(GitVersionSemverfier)

# This will be used by CI build scripts
file( WRITE ${CMAKE_BINARY_DIR}/version.txt ${GIT_SEM_VERSION} )

message( "Version: ${GIT_SEM_VERSION} (from Git)" )

project( WeaponMod VERSION "${GIT_MAJOR}.${GIT_MINOR}.${GIT_PATCH}" )
include( PlatformInfo )

Expand Down Expand Up @@ -242,18 +247,18 @@ include_directories( ${GENERATED_INCLUDE_DIR} )
# Autodeploy macro
#-----------------------------------------------------------------
if( AUTO_DEPLOY )
macro( add_auto_deploy TARGET_NAME PUBLISH_PATHS_FILE )
if ( WIN32 )
add_custom_command( TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/scripts/deploy_libs.bat "${CMAKE_BINARY_DIR}\\${PUBLISH_PATHS_FILE}" "$<TARGET_FILE:${TARGET_NAME}>" "$<TARGET_PDB_FILE:${TARGET_NAME}>"
)
else()
add_custom_command( TARGET ${TARGET_NAME}
POST_BUILD
COMMAND ${CMAKE_SOURCE_DIR}/scripts/deploy_libs.sh "${CMAKE_BINARY_DIR}/${PUBLISH_PATHS_FILE}" "$<TARGET_FILE:${TARGET_NAME}>"
)
endif()
macro( add_auto_deploy target_name publish_paths_file )
add_custom_command( TARGET ${target_name}
POST_BUILD
COMMAND
${CMAKE_COMMAND}
-P
${CMAKE_SOURCE_DIR}/cmake/DeployLibs.cmake
--
${CMAKE_BINARY_DIR}
"$<CONFIG>"
${CMAKE_BINARY_DIR}/${publish_paths_file}
)
endmacro()
else()
macro( add_auto_deploy )
Expand All @@ -266,5 +271,6 @@ endif()
set( THREADS_PREFER_PTHREAD_FLAG ON )
find_package( Threads REQUIRED )

add_subdirectory( thirdparty )
add_subdirectory( gamedir )
add_subdirectory( src )
add_subdirectory( thirdparty )
40 changes: 40 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"version": 9,
"cmakeMinimumRequired": {
"major": 3,
"minor": 30
},
"include": [
"cmake/CMake${hostSystemName}Presets.json"
],
"configurePresets": [
{
"name": "base",
"inherits": ["platform-toolchain"],
"binaryDir": "${sourceDir}/_build/${presetName}",
"hidden": true,
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": true,

"AUTO_DEPLOY": false,
"GNU_FORCE_COLORED_OUTPUT": true
}
},
{
"name": "github-actions",
"inherits": ["platform-generator", "base"],
"cacheVariables": {
"GNU_FORCE_COLORED_OUTPUT": false,
"WARNINGS_ARE_ERRORS": true
}
}
],
"buildPresets": [
{
"name": "github-actions",
"configurePreset": "github-actions",
"inheritConfigureEnvironment": true,
"configuration": "RelWithDebInfo"
}
]
}
26 changes: 26 additions & 0 deletions CMakeUserPresets.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": 4,
"configurePresets": [
{
"name": "user",
"inherits": ["base", "platform-generator"],
"cacheVariables": {
"AUTO_DEPLOY": true
}
}
],
"buildPresets": [
{
"name": "user-debug",
"configurePreset": "user",
"inheritConfigureEnvironment": true,
"configuration": "Debug"
},
{
"name": "user-release",
"configurePreset": "user",
"inheritConfigureEnvironment": true,
"configuration": "RelWithDebInfo"
}
]
}
15 changes: 15 additions & 0 deletions cmake/CMakeLinuxPresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 4,
"configurePresets": [
{
"name": "platform-toolchain",
"hidden": true,
"toolchainFile": "${sourceDir}/cmake/toolchains/linux-gcc.cmake"
},
{
"name": "platform-generator",
"hidden": true,
"generator": "Ninja Multi-Config"
}
]
}
15 changes: 15 additions & 0 deletions cmake/CMakeWindowsPresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": 4,
"configurePresets": [
{
"name": "platform-toolchain",
"hidden": true
},
{
"name": "platform-generator",
"hidden": true,
"generator": "Visual Studio 17 2022",
"architecture": "Win32"
}
]
}
72 changes: 72 additions & 0 deletions cmake/DeployLibs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
cmake_minimum_required( VERSION 3.25.0 )

# In script mode, CMAKE_ARGVx contains ALL arguments, including `-P` and script path
# This is stupid, so we neew to find where `--` is
set( actual_args_start_idx 0 )
math( EXPR last_arg_idx "${CMAKE_ARGC} - 1" )

foreach( i RANGE 0 ${last_arg_idx})
set( arg "${CMAKE_ARGV${i}}" )

if( "${arg}" STREQUAL "--" )
math( EXPR actual_args_start_idx "${i} + 1")
break()
endif()
endforeach()

# Copy args to temp vars
math( EXPR arg_binary_dir_idx "${actual_args_start_idx} + 0" )
set( binary_dir ${CMAKE_ARGV${arg_binary_dir_idx}} )


math( EXPR arg_config_idx "${actual_args_start_idx} + 1" )
set( config_name ${CMAKE_ARGV${arg_config_idx}} )

math( EXPR arg_path_list_idx "${actual_args_start_idx} + 2" )
set( path_list_file ${CMAKE_ARGV${arg_path_list_idx}} )

# Check that args are set
if( NOT binary_dir )
message( FATAL_ERROR "Binary dir path not specified." )
endif()

if( NOT path_list_file )
message( FATAL_ERROR "Path list file not specified." )
endif()

# Check that paths exist
if( NOT EXISTS "${binary_dir}" )
message( FATAL_ERROR "Binary dir ${FATAL_ERROR} doesn't exist." )
endif()

if( NOT EXISTS "${path_list_file}" )
message( NOTICE "No deployment path specified. Create file ${path_list_file} with folder paths on separate lines for auto deployment." )
return()
endif()

# Read the path list file
file( STRINGS ${path_list_file} deploy_paths )

# Iterate over all paths in the file
foreach( deploy_path IN LISTS deploy_paths)
cmake_path( IS_ABSOLUTE deploy_path is_path_absolute )

if( NOT is_path_absolute )
message( SEND_ERROR "Path must be absolute: ${deploy_path_full}" )
continue()
endif()

if( NOT EXISTS "${deploy_path}" )
message( SEND_ERROR "Path doesn't exist: ${deploy_path}" )
continue()
endif()

# Run cmake --install for the path
execute_process(
COMMAND
${CMAKE_COMMAND}
--install ${binary_dir}
--config "${config_name}"
--prefix ${deploy_path}
)
endforeach()
Loading