ci: use libsdl-org/setup for SDL + package with CPack (#362)

* Fix unittests with null renderer

* cmake: fix configuration when building from a non-git/non-release archive

* test: don't access freed memory

* cmake+ci: use libsdl-org/setup-sdl for SDL2 + create package with CMake

* Install all files to root + SDL2.dll
This commit is contained in:
Anonymous Maarten 2024-05-28 12:02:39 +02:00 committed by GitHub
parent 9054ba9b81
commit c76b766ce7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 102 additions and 207 deletions

View File

@ -1,34 +0,0 @@
#!/bin/bash
set -e
if [ "${MATRIX_PLATFORM}" = "clang" ]
then
export CC=clang
export CXX=clang++
else
export CC=gcc
export CXX=g++
fi
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
BUILD_TAG=${GITHUB_REF_NAME}
else
BUILD_TAG=$(git rev-parse --short HEAD)
fi
# install deps
sudo apt-get update -qq > /dev/null
sudo apt-get install -qq -y libsdl2-dev > /dev/null
# build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -DDETHRACE_WERROR=ON -B build
cmake --build build -- -j 4
# package artifact
releasename="dethrace-${BUILD_TAG}-linux-${PLATFORM_ARCH}"
rm -rf "$releasename"
mkdir "$releasename"
cp build/dethrace "$releasename/dethrace"
tar -czvf "$releasename.tar.gz" "$releasename"
echo "filename=$releasename.tar.gz" >>$GITHUB_OUTPUT

View File

@ -1,23 +0,0 @@
#!/bin/bash
set -e
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then
BUILD_TAG=${GITHUB_REF_NAME}
else
BUILD_TAG=$(git rev-parse --short HEAD)
fi
# install deps
brew install SDL2
# build
cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_OSX_ARCHITECTURES=x86_64 -DBUILD_TESTS=ON -DDETHRACE_WERROR=ON -B build
cmake --build build -- -j 4
# package artifact
releasename="dethrace-${BUILD_TAG}-darwin-${PLATFORM_ARCH}"
rm -rf "$releasename"
mkdir "$releasename"
cp build/dethrace "$releasename/dethrace"
tar -czvf "$releasename.tar.gz" "$releasename"
echo "filename=$releasename.tar.gz">>$GITHUB_OUTPUT

View File

@ -1,55 +0,0 @@
#!/bin/bash
set -e
if test -z "$MSYSTEM"; then
# mingw@Linux
if test $MATRIX_PLATFORM = "x86"; then
sdl_path="i686-w64-mingw32"
apt_packages="gcc-mingw-w64-i686 g++-mingw-w64-i686"
export CC=i686-w64-mingw32-gcc-win32
export CXX=i686-w64-mingw32-g++-win32
else
sdl_path="x86_64-w64-mingw32"
apt_packages="gcc-mingw-w64-x86-64 g++-mingw-w64-x86-64"
export CC=x86_64-w64-mingw32-gcc-win32
export CXX=x86_64-w64-mingw32-g++-win32
fi
# install deps
sudo apt-get update -qq > /dev/null
sudo apt-get install -qq -y $apt_packages > /dev/null
SDL2_VERSION=2.0.18
wget -nv https://www.libsdl.org/release/SDL2-devel-$SDL2_VERSION-mingw.tar.gz -O /tmp/SDL2-devel-$SDL2_VERSION-mingw.tar.gz
tar -xf /tmp/SDL2-devel-$SDL2_VERSION-mingw.tar.gz -C /tmp
$CC --verbose
$CXX --verbose
# build
cmake -DCMAKE_SYSTEM_NAME=Windows -DSDL2_ROOT_DIR=/tmp/SDL2-$SDL2_VERSION/$sdl_path -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -DDETHRACE_WERROR=ON -B build -DCMAKE_EXE_LINKER_FLAGS_INIT=-lssp
cmake --build build -- -j 4
# package artifact
tar -czvf mingw-$MATRIX_PLATFORM.tar.gz -C build dethrace.exe -C /tmp/SDL2-$SDL2_VERSION/$sdl_path/bin SDL2.dll
else
# mingw@Windows
if test $MATRIX_PLATFORM = "x86"; then
bin_path="/mingw32/bin"
pacman_packages="mingw-w64-i686-cmake mingw-w64-i686-make mingw-w64-i686-gcc mingw-w64-i686-SDL2"
else
bin_path="/mingw64/bin"
pacman_packages="mingw-w64-x86_64-cmake mingw-w64-x86_64-make mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2"
fi
# install deps
pacman -S --noconfirm $pacman_packages
# build
cmake -G "MinGW Makefiles" -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON -B build
cmake --build build -- -j 4
# package artifact
tar -czvf mingw-$MATRIX_PLATFORM.tar.gz -C build dethrace.exe -C $bin_path SDL2.dll
fi

View File

@ -1,43 +0,0 @@
$ErrorActionPreference = "Stop"
if ($($Env:PLATFORM_ARCH) -eq "x86") {
$sdl_path = "x86"
} else {
$sdl_path = "x64"
}
if ($($Env:GITHUB_REF_TYPE) -eq "tag") {
$build_tag=$Env:GITHUB_REF_NAME
} else {
$build_tag=$(git rev-parse --short HEAD)
}
$sdl2_version = "2.24.0"
# install deps
Invoke-WebRequest -Uri https://www.libsdl.org/release/SDL2-devel-$sdl2_version-VC.zip -OutFile $Env:TEMP\SDL2-devel.zip
Expand-Archive $Env:TEMP\SDL2-devel.zip -DestinationPath $Env:TEMP
# build
cmake -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTS=ON "-DSDL2_ROOT_DIR=$($Env:TEMP)\SDL2-$sdl2_version" -B build
if ($LASTEXITCODE -ne 0) {
Exit $LASTEXITCODE
}
cmake --build build --config RelWithDebInfo
if ($LASTEXITCODE -ne 0) {
Exit $LASTEXITCODE
}
# copy SDL2.dll to build folder, so tests can run
cp $Env:TEMP\SDL2-$sdl2_version\lib\$sdl_path\SDL2.dll build
# package artifact
$releasename="dethrace-$build_tag-windows-$Env:PLATFORM_ARCH"
mkdir "$releasename"
cp build/dethrace.exe "$releasename/dethrace.exe"
cp build/dethrace.pdb "$releasename/dethrace.pdb"
cp build/SDL2.dll "$releasename/SDL2.dll"
7z a -tzip "$releasename.zip" "$releasename"
echo "filename=$releasename.zip">>$Env:GITHUB_OUTPUT

View File

@ -15,38 +15,69 @@ jobs:
strategy:
matrix:
platform:
- { name: Linux, os: ubuntu-latest, arch: amd64, script: build-linux.sh }
- { name: MacOS, os: macos-latest, arch: amd64, script: build-macos.sh }
- { name: Windows, os: windows-latest, arch: amd64, script: build-msvc.ps1 }
- { name: Windows, os: windows-latest, arch: x86, script: build-msvc.ps1 }
runs-on: ${{ matrix.platform.os }}
name: CI (${{ matrix.platform.name }} ${{ matrix.platform.arch }})
- { name: 'Linux', arch: 'x64', os: ubuntu-latest, werror: true }
- { name: 'MacOS', arch: 'arm64-x64', os: macos-latest, werror: true, cmake-args: '-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"' }
- { name: 'Windows', arch: 'Win32', os: windows-latest }
- { name: 'Windows', arch: 'x64', os: windows-latest }
defaults:
run:
shell: sh
runs-on: '${{ matrix.platform.os }}'
name: 'CI ${{ matrix.platform.name }} ${{ matrix.platform.arch }}'
steps:
- uses: actions/checkout@v3
- name: Setup Ninja
uses: ashutoshvarma/setup-ninja@master
with:
version: 1.10.2
- uses: ilammy/msvc-dev-cmd@v1.4.1
- uses: actions/checkout@v4
- name: Set up Ninja
uses: aseprite/get-ninja@main
- uses: ilammy/msvc-dev-cmd@v1.13.0
if: runner.os == 'Windows'
with:
arch: ${{ matrix.platform.arch }}
- name: Build
id: build
run: .github/scripts/${{ matrix.platform.script }}
env:
PLATFORM_ARCH: ${{ matrix.platform.arch }}
- name: Test
- name: Install Linux dependencies
if: ${{ runner.os == 'Linux' }}
run: |
sudo apt-get update
sudo apt-get install -y libgl-dev
- name: Set up SDL
uses: libsdl-org/setup-sdl@main
with:
cmake-arguments: ${{ matrix.platform.cmake-args }}
cmake-generator: Ninja
version: 2-latest
add-to-environment: true
- name: 'Prepare sources for release'
if: ${{ startsWith(github.ref, 'refs/tags/') }}
run: |
echo "${{ github.ref_name }}" >VERSION
- name: 'Configure (CMake)'
id: configure
run: |
cmake -B build -GNinja \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DBUILD_TESTS=ON \
-DDETHRACE_WERROR=${{ !!matrix.platform.werror }} \
-DCMAKE_POLICY_DEFAULT_CMP0074=NEW \
-DDETHRACE_INSTALL=ON \
-DDETHRACE_PACKAGE_PLATFORM=${{ matrix.platform.name }} \
-DDETHRACE_PACKAGE_ARCH=${{ matrix.platform.arch }} \
${{ matrix.platform.cmake-args }}
- name: 'Build (CMake)'
run: |
cmake --build build
- name: 'Test (CTest)'
run: |
ctest --test-dir build --verbose
- name: 'Package (CPack)'
run: |
cd build
ctest --verbose
cpack .
- name: Upload Artifact
# if: startsWith(github.ref, 'refs/tags/') || github.ref_name == 'main'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ steps.build.outputs.filename }}
path: ${{ steps.build.outputs.filename }}
name: '${{ steps.configure.outputs.filename }}'
path: 'build/dist/${{ steps.configure.outputs.filename }}'
if-no-files-found: error
create-release:
name: Create Release
@ -55,7 +86,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Fetch Build Artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Calculate Variables
@ -64,7 +95,7 @@ jobs:
echo "ref_name_without_v=$(echo ${GITHUB_REF_NAME} | cut -c2-)" >>$GITHUB_OUTPUT
- name: Create Release
id: create_release
uses: softprops/action-gh-release@v0.1.14
uses: softprops/action-gh-release@v2
with:
draft: false
prerelease: false

View File

@ -8,8 +8,12 @@ project(dethrace C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/")
if(MSVC)
set(CMAKE_INSTALL_BINDIR "." CACHE PATH "User executables")
set(CMAKE_INSTALL_DOCDIR "." CACHE PATH "Documentation root")
endif()
include(CheckCCompilerFlag)
include(GNUInstallDirs)
include(TestBigEndian)
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")
@ -18,6 +22,9 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/VERSION")
else()
include(GetGitRevisionDescription)
git_describe(DETHRACE_VERSION)
if(NOT DETHRACE_VERSION)
set(DETHRACE_VERSION "unknown")
endif()
endif()
message(STATUS "dethrace version ${DETHRACE_VERSION}")
@ -82,39 +89,39 @@ endif()
if(DETHRACE_INSTALL)
install(FILES LICENSE
DESTINATION "${CMAKE_INSTALL_DOCDIR}"
DESTINATION "."
)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^([xX]86|[xX]86_64|[iI].86|AMD64)$")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(DETHRACE_ARCH x86)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(DETHRACE_ARCH amd64)
else()
message(SEND_ERROR "Unknown CMAKE_SIZEOF_VOID_P (${CMAKE_SIZEOF_VOID_P})")
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(ARM|arm|ARM64|aarch64)$")
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(DETHRACE_ARCH arm)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(DETHRACE_ARCH aarch64)
else()
message(SEND_ERROR "Unknown CMAKE_SIZEOF_VOID_P (${CMAKE_SIZEOF_VOID_P})")
endif()
else()
message(SEND_ERROR "Unknown CMAKE_SYSTEM_PROCESSOR (${CMAKE_SYSTEM_PROCESSOR})")
set(DETHRACE_PACKAGE_PLATFORM "" CACHE STRING "Dethrace binary package platform")
set(DETHRACE_PACKAGE_ARCH "" CACHE STRING "Dethrace binary package architecture")
if(NOT DETHRACE_PACKAGE_PLATFORM)
set(DETHRACE_PACKAGE_PLATFORM "${CMAKE_SYSTEM_NAME}")
endif()
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VERSION "${DETHRACE_VERSION}")
string(TOLOWER "${CMAKE_SYSTEM_NAME}-${DETHRACE_ARCH}" CPACK_SYSTEM_NAME)
string(TOLOWER "${DETHRACE_PACKAGE_PLATFORM}" DETHRACE_PACKAGE_PLATFORM)
string(TOLOWER "${DETHRACE_PACKAGE_ARCH}" DETHRACE_PACKAGE_ARCH)
set(CPACK_PACKAGE_NAME "dethrace")
set(CPACK_SYSTEM_NAME "${DETHRACE_PACKAGE_PLATFORM}")
set(CPACK_PACKAGE_FILE_NAME "dethrace-${DETHRACE_VERSION}-${DETHRACE_PACKAGE_PLATFORM}")
if(DETHRACE_PACKAGE_ARCH)
string(APPEND CPACK_PACKAGE_FILE_NAME "-${DETHRACE_PACKAGE_ARCH}")
endif()
set(CPACK_PACKAGE_DIRECTORY dist)
if(MSVC)
set(CPACK_GENERATOR ZIP)
set(ext ".zip")
else()
set(CPACK_GENERATOR TGZ)
set(ext ".tar.gz")
endif()
if(EXISTS "$ENV{GITHUB_OUTPUT}")
file(APPEND "$ENV{GITHUB_OUTPUT}" "filename=${CPACK_PACKAGE_FILE_NAME}${ext}")
endif()
include(CPack)

View File

@ -205,11 +205,17 @@ endif()
if (DETHRACE_INSTALL)
install(TARGETS dethrace
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}"
RUNTIME DESTINATION "."
)
if(MSVC)
INSTALL(FILES $<TARGET_PDB_FILE:dethrace>
DESTINATION "${CMAKE_INSTALL_BINDIR}"
DESTINATION "."
OPTIONAL
)
endif()
if(WIN32)
INSTALL(FILES $<TARGET_RUNTIME_DLLS:dethrace>
DESTINATION "."
OPTIONAL
)
endif()

View File

@ -14,6 +14,10 @@ static int null_set_window_pos(void* hWnd, int x, int y, int nWidth, int nHeight
static void null_destroy_window(void* hWnd) {
}
static int null_show_error_message(void* window, char* text, char* caption) {
return 0;
}
static int null_get_and_handle_message(MSG_* msg) {
return 0;
}
@ -83,6 +87,7 @@ void Null_Platform_Init(tHarness_platform* platform) {
platform->GetMousePosition = null_get_mouse_position;
platform->GetMouseButtons = null_get_mouse_buttons;
platform->DestroyWindow = null_destroy_window;
platform->ShowErrorMessage = null_show_error_message;
platform->Renderer_BufferModel = NullRenderer_BufferModel;
platform->Renderer_BufferMaterial = NullRenderer_BufferMaterial;

View File

@ -74,7 +74,8 @@ static void test_resource_BrResFree_Child() {
header = UserToRes(r);
BrResFree(r);
#ifndef _DEBUG
/* Accessing freed memory is undefined behavior. So only do this on platforms that don't use an MMU. */
#if defined(__DOS__)
// when the res is free'd, magic_num is set to 1. We make sure the child was free'd when the parent was
TEST_ASSERT_EQUAL_INT(1, header->magic_num);