Update compile.sh

This commit is contained in:
tooomm 2026-08-29 16:49:37 +02:00
parent 704611fc1f
commit 6fe8ba59b7

View file

@ -122,51 +122,53 @@ done
set -e set -e
# Setup # Schema version consistency
./servatrice/check_schema_version.sh if [[ $MAKE_SERVER == "1" ]]; then
if [[ ! $BUILDTYPE ]]; then ./servatrice/check_schema_version.sh
fi
# Use default values if unset
if [[ -z $BUILDTYPE ]]; then
BUILDTYPE=Release BUILDTYPE=Release
fi fi
if [[ ! $BUILD_DIR ]]; then if [[ -z $BUILD_DIR ]]; then
BUILD_DIR="build" BUILD_DIR="build"
fi fi
mkdir -p "$BUILD_DIR" mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR" cd "$BUILD_DIR"
# Set minimum CMake Version # CMake options
export CMAKE_POLICY_VERSION_MINIMUM=3.10
# Add cmake flags
flags=("-DCMAKE_BUILD_TYPE=$BUILDTYPE") flags=("-DCMAKE_BUILD_TYPE=$BUILDTYPE")
if [[ $MAKE_SERVER ]]; then if [[ $MAKE_SERVER == "1" ]]; then
flags+=("-DWITH_SERVER=1") flags+=("-DWITH_SERVER=1")
fi fi
if [[ $MAKE_NO_CLIENT ]]; then if [[ $MAKE_NO_CLIENT == "1" ]]; then
flags+=("-DWITH_CLIENT=0" "-DWITH_ORACLE=0") flags+=("-DWITH_CLIENT=0" "-DWITH_ORACLE=0")
fi fi
if [[ $MAKE_TEST ]]; then if [[ $MAKE_TEST == "1" ]]; then
flags+=("-DTEST=1") flags+=("-DTEST=1")
fi fi
if [[ $USE_CCACHE ]]; then if [[ $USE_CCACHE == "1" ]]; then
flags+=("-DUSE_CCACHE=1") flags+=("-DUSE_CCACHE=1")
if [[ $CCACHE_SIZE ]]; then if [[ -n $CCACHE_SIZE ]]; then
# note, this setting persists after running the script # This setting persists after running the script
ccache --max-size "$CCACHE_SIZE" ccache --max-size "$CCACHE_SIZE"
fi fi
fi fi
if [[ $PACKAGE_TYPE ]]; then if [[ -n $PACKAGE_TYPE ]]; then
flags+=("-DCPACK_GENERATOR=$PACKAGE_TYPE") flags+=("-DCPACK_GENERATOR=$PACKAGE_TYPE")
fi fi
if [[ $USE_VCPKG ]]; then if [[ $USE_VCPKG == "1" ]]; then
flags+=("-DUSE_VCPKG=1") flags+=("-DUSE_VCPKG=1")
flags+=("-DVCPKG_INSTALL_OPTIONS=--x-abi-tools-use-exact-versions") flags+=("-DVCPKG_INSTALL_OPTIONS=--x-abi-tools-use-exact-versions")
fi fi
# Add cmake --build flags # CMake --build options
buildflags=(--config "$BUILDTYPE") buildflags=(--config "$BUILDTYPE")
function ccachestatsverbose() { function ccachestatsverbose() {
# note, verbose only works on newer ccache, discard the error ccache --version
# Verbose only works on newer ccache, discard the error
local got local got
if got="$(ccache --show-stats --verbose 2>/dev/null)"; then if got="$(ccache --show-stats --verbose 2>/dev/null)"; then
echo "$got" echo "$got"
@ -175,8 +177,8 @@ function ccachestatsverbose() {
fi fi
} }
# Compile # Prepare compilation
if [[ $RUNNER_OS == macOS ]]; then if [[ $RUNNER_OS == "macOS" ]]; then
# QTDIR is needed for macOS since we actually only use the cached thin Qt binaries instead of the install-qt-action, # QTDIR is needed for macOS since we actually only use the cached thin Qt binaries instead of the install-qt-action,
# which sets a few environment variables # which sets a few environment variables
if QTDIR=$(find "$GITHUB_WORKSPACE/Qt" -depth -maxdepth 2 -name macos -type d -print -quit); then if QTDIR=$(find "$GITHUB_WORKSPACE/Qt" -depth -maxdepth 2 -name macos -type d -print -quit); then
@ -185,42 +187,51 @@ if [[ $RUNNER_OS == macOS ]]; then
echo "could not find QTDIR!" echo "could not find QTDIR!"
exit 2 exit 2
fi fi
# the qtdir is located at Qt/[qtversion]/macos # QTDIR is located at Qt/<QtVersion>/macos
# we use find to get the first subfolder with the name "macos" # We use find to get the first subfolder with the name "macos"
# this works independent of the qt version as there should be only one version installed on the runner at a time # This works independent of the Qt version as there should be only one version installed on the runner at a time
export QTDIR export QTDIR
if [[ $TARGET_MACOS_VERSION ]]; then if [[ -n $TARGET_MACOS_VERSION ]]; then
# CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla cmake flag needed to compile to target macOS version # CMAKE_OSX_DEPLOYMENT_TARGET is a vanilla CMake option needed to compile to target macOS version
flags+=("-DCMAKE_OSX_DEPLOYMENT_TARGET=$TARGET_MACOS_VERSION") flags+=("-DCMAKE_OSX_DEPLOYMENT_TARGET=$TARGET_MACOS_VERSION")
# vcpkg dependencies need a vcpkg triplet file to compile to the target macOS version if [[ $USE_VCPKG == "1" ]]; then
# an easy way is to copy the x64-osx.cmake file and modify it # vcpkg dependencies need a vcpkg triplet file to compile to the target macOS version
triplets_dir="/tmp/cmake/triplets" # An easy way is to copy the x64-osx.cmake file and modify it
triplet_version="custom-triplet" echo "::group::vcpkg triplet"
triplet_file="$triplets_dir/$triplet_version.cmake" triplets_dir="/tmp/cmake/triplets"
arch=$(uname -m) triplet_version="custom-triplet"
if [[ $arch == x86_64 ]]; then triplet_file="$triplets_dir/$triplet_version.cmake"
arch="x64" arch=$(uname -m)
if [[ $arch == x86_64 ]]; then
arch="x64"
fi
mkdir -p "$triplets_dir"
triplet_source="../vcpkg/triplets/$arch-osx.cmake"
if [[ ! -f "$triplet_source" ]]; then
triplet_source="../vcpkg/triplets/community/$arch-osx.cmake"
fi
cp "$triplet_source" "$triplet_file"
echo "set(VCPKG_CMAKE_SYSTEM_VERSION $TARGET_MACOS_VERSION)" >>"$triplet_file"
echo "set(VCPKG_OSX_DEPLOYMENT_TARGET $TARGET_MACOS_VERSION)" >>"$triplet_file"
flags+=("-DVCPKG_OVERLAY_TRIPLETS=$triplets_dir")
flags+=("-DVCPKG_HOST_TRIPLET=$triplet_version")
flags+=("-DVCPKG_TARGET_TRIPLET=$triplet_version")
echo "::endgroup::"
echo "::group::Generated triplet $triplet_file"
cat "$triplet_file"
echo "::endgroup::"
fi fi
mkdir -p "$triplets_dir"
triplet_source="../vcpkg/triplets/$arch-osx.cmake"
if [[ ! -f "$triplet_source" ]]; then
triplet_source="../vcpkg/triplets/community/$arch-osx.cmake"
fi
cp "$triplet_source" "$triplet_file"
echo "set(VCPKG_CMAKE_SYSTEM_VERSION $TARGET_MACOS_VERSION)" >>"$triplet_file"
echo "set(VCPKG_OSX_DEPLOYMENT_TARGET $TARGET_MACOS_VERSION)" >>"$triplet_file"
flags+=("-DVCPKG_OVERLAY_TRIPLETS=$triplets_dir")
flags+=("-DVCPKG_HOST_TRIPLET=$triplet_version")
flags+=("-DVCPKG_TARGET_TRIPLET=$triplet_version")
echo "::group::Generated triplet $triplet_file"
cat "$triplet_file"
echo "::endgroup::"
fi fi
echo "::group::Signing Certificate" echo "::group::Setup signing certificate"
if [[ -n "$MACOS_CERTIFICATE_NAME" ]]; then if [[ -n $MACOS_CERTIFICATE_NAME ]]; then
echo "$MACOS_CERTIFICATE" | base64 --decode >"certificate.p12" echo "$MACOS_CERTIFICATE" | base64 --decode >"certificate.p12"
security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain security create-keychain -p "$MACOS_CI_KEYCHAIN_PWD" build.keychain
security default-keychain -s build.keychain security default-keychain -s build.keychain
@ -234,9 +245,9 @@ if [[ $RUNNER_OS == macOS ]]; then
fi fi
echo "::endgroup::" echo "::endgroup::"
if [[ $MAKE_PACKAGE ]]; then if [[ $MAKE_PACKAGE == "1" ]]; then
# Workaround https://github.com/actions/runner-images/issues/7522 # Workaround https://github.com/actions/runner-images/issues/7522
# have hdiutil repeat the command 10 times in hope of success # Have hdiutil repeat the command 10 times in hope of success
hdiutil_script="/tmp/hdiutil.sh" hdiutil_script="/tmp/hdiutil.sh"
# shellcheck disable=SC2016 # shellcheck disable=SC2016
echo '#!/bin/bash echo '#!/bin/bash
@ -252,43 +263,46 @@ if [[ $RUNNER_OS == macOS ]]; then
flags+=(-DCPACK_COMMAND_HDIUTIL="$hdiutil_script") flags+=(-DCPACK_COMMAND_HDIUTIL="$hdiutil_script")
fi fi
elif [[ $RUNNER_OS == Windows ]]; then elif [[ $RUNNER_OS == "Windows" ]]; then
# Enable MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/ # Enable MSBuild switches for MTT, see https://devblogs.microsoft.com/cppblog/improved-parallelism-in-msbuild/
# and https://devblogs.microsoft.com/cppblog/cpp-build-throughput-investigation-and-tune-up/#multitooltask-mtt # and https://devblogs.microsoft.com/cppblog/cpp-build-throughput-investigation-and-tune-up/#multitooltask-mtt
buildflags+=(-- -p:UseMultiToolTask=true -p:EnableClServerMode=true) buildflags+=(-- -p:UseMultiToolTask=true -p:EnableClServerMode=true)
fi fi
if [[ $USE_CCACHE ]]; then if [[ $USE_CCACHE == "1" ]]; then
echo "::group::Show ccache stats" echo "::group::Show ccache stats"
ccachestatsverbose ccachestatsverbose
echo "::endgroup::" echo "::endgroup::"
fi fi
echo "::group::Configure cmake" # Configure CMake
echo "::group::Generate build system"
cmake --version cmake --version
echo "Running cmake with flags: ${flags[*]}" echo "Running CMake configuration with following flags: ${flags[*]}"
cmake .. "${flags[@]}" cmake .. "${flags[@]}"
echo "::endgroup::" echo "::endgroup::"
# Build
echo "::group::Build project" echo "::group::Build project"
echo "Running cmake --build with flags: ${buildflags[*]}" echo "Running CMake with following build flags: ${buildflags[*]}"
cmake --build . "${buildflags[@]}" cmake --build . "${buildflags[@]}"
echo "::endgroup::" echo "::endgroup::"
if [[ $USE_CCACHE ]]; then # Post-build
if [[ $CCACHE_EVICTION_AGE ]]; then if [[ $USE_CCACHE == "1" ]]; then
echo "::group::evict ccache files older than $CCACHE_EVICTION_AGE" if [[ -n $CCACHE_EVICTION_AGE ]]; then
echo "::group::Evict ccache files older than $CCACHE_EVICTION_AGE"
ccache --evict-older-than "$CCACHE_EVICTION_AGE" ccache --evict-older-than "$CCACHE_EVICTION_AGE"
echo "::endgroup::" echo "::endgroup::"
fi fi
echo "::group::Show ccache stats again" echo "::group::Show ccache stats again"
ccachestatsverbose ccachestatsverbose
echo "::endgroup::" echo "::endgroup::"
elif [[ $CCACHE_EVICTION_AGE ]]; then elif [[ -n $CCACHE_EVICTION_AGE ]]; then
echo "::error file=$0::ccache eviction is enabled while ccache is disabled!" echo "::error file=$0::ccache eviction is enabled while ccache is disabled!"
fi fi
if [[ $RUNNER_OS == macOS ]]; then if [[ $RUNNER_OS == "macOS" ]]; then
echo "::group::Inspect Mach-O binaries" echo "::group::Inspect Mach-O binaries"
for app in cockatrice oracle servatrice; do for app in cockatrice oracle servatrice; do
binary="$GITHUB_WORKSPACE/build/$app/$app.app/Contents/MacOS/$app" binary="$GITHUB_WORKSPACE/build/$app/$app.app/Contents/MacOS/$app"
@ -301,24 +315,29 @@ if [[ $RUNNER_OS == macOS ]]; then
echo "::endgroup::" echo "::endgroup::"
fi fi
if [[ $MAKE_TEST ]]; then # Test
if [[ $MAKE_TEST == "1" ]]; then
echo "::group::Run tests" echo "::group::Run tests"
ctest --version
ctest -C "$BUILDTYPE" --output-on-failure ctest -C "$BUILDTYPE" --output-on-failure
echo "::endgroup::" echo "::endgroup::"
fi fi
if [[ $MAKE_INSTALL ]]; then # Install
if [[ $MAKE_INSTALL == "1" ]]; then
echo "::group::Install" echo "::group::Install"
cmake --build . --target install --config "$BUILDTYPE" cmake --build . --target install --config "$BUILDTYPE"
echo "::endgroup::" echo "::endgroup::"
fi fi
if [[ $MAKE_PACKAGE ]]; then # Package
if [[ $MAKE_PACKAGE == "1" ]]; then
echo "::group::Create package" echo "::group::Create package"
cpack --version
cmake --build . --target package --config "$BUILDTYPE" cmake --build . --target package --config "$BUILDTYPE"
echo "::endgroup::" echo "::endgroup::"
if [[ $PACKAGE_SUFFIX ]]; then if [[ -n $PACKAGE_SUFFIX ]]; then
echo "::group::Update package name" echo "::group::Update package name"
cd .. cd ..
BUILD_DIR="$BUILD_DIR" .ci/name_build.sh "$PACKAGE_SUFFIX" BUILD_DIR="$BUILD_DIR" .ci/name_build.sh "$PACKAGE_SUFFIX"