Skip to content

migrate to c++20 compiler #1588

migrate to c++20 compiler

migrate to c++20 compiler #1588

Workflow file for this run

name: build-test
on:
push:
branches:
- master
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event_name == 'pull_request' && github.head_ref || github.sha }}
cancel-in-progress: true
jobs:
build:
runs-on: ${{ matrix.os }}
continue-on-error: false
permissions:
id-token: write
contents: read
strategy:
fail-fast: false
matrix:
os: [windows-2022, macos-latest, ubuntu-latest]
compiler: ['clang', 'gcc', 'msvc']
exclude:
- os: ubuntu-latest
compiler: 'msvc'
- os: macos-latest
compiler: 'gcc'
- os: macos-latest
compiler: 'msvc'
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0
submodules: true
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
create-symlink: ${{ runner.os != 'Windows' }}
key: ${{ github.job }}-${{ matrix.os }}-${{ matrix.compiler }}
variant: ${{ matrix.compiler == 'msvc' && 'sccache' || 'ccache' }}
- if: runner.os == 'Windows' || runner.os == 'macOS'
uses: lukka/get-cmake@latest
- if: matrix.compiler == 'msvc'
uses: ilammy/msvc-dev-cmd@v1
#
# Install Packages (Ubuntu)
#
- if: runner.os == 'Linux'
name: Install Packages for Ubuntu
run: |
sudo apt update -qq
sudo apt install -y \
qt6-base-dev qt6-base-dev-tools libqt6opengl6-dev libqt6websockets6-dev \
qt6-multimedia-dev libqt6multimedia6 qt6-svg-dev \
libgl1-mesa-dev qtkeychain-qt6-dev build-essential cmake ninja-build mold git \
zlib1g-dev libssl-dev
- if: runner.os == 'Linux' && matrix.compiler == 'gcc'
name: Install GCC for Ubuntu
run: |
sudo apt install -y gcc-13 g++-13 lcov
echo "QMAKESPEC=linux-g++" >> $GITHUB_ENV
echo "CC=gcc-13" >> $GITHUB_ENV
echo "CXX=g++-13" >> $GITHUB_ENV
echo "MMAPPER_CMAKE_EXTRA=-DUSE_CODE_COVERAGE=true -DUSE_MOLD=true -DPACKAGE_TYPE=Deb" >> $GITHUB_ENV
echo "COVERAGE=true" >> $GITHUB_ENV
echo "GCOV_TOOL=gcov-13" >> $GITHUB_ENV
- if: runner.os == 'Linux' && matrix.compiler == 'clang'
name: Install Clang for Ubuntu
run: |
sudo apt install -y clang-18 binutils
echo "QMAKESPEC=linux-clang" >> $GITHUB_ENV
echo "CC=clang-18" >> $GITHUB_ENV
echo "CXX=clang++-18" >> $GITHUB_ENV
echo "STYLE=true" >> $GITHUB_ENV
echo "MMAPPER_CMAKE_EXTRA=-DUSE_MOLD=true -DPACKAGE_TYPE=Deb" >> $GITHUB_ENV
#
# Install Packages (Mac)
#
- if: runner.os == 'macOS'
name: Install Qt for Mac
uses: jurplel/install-qt-action@v4
with:
version: 6.8.3
arch: clang_64
cache: true
modules: 'qtwebsockets qtmultimedia'
- if: runner.os == 'macOS'
name: Install Packages for Mac
run: |
brew install lcov
echo "MMAPPER_CMAKE_EXTRA=-DCMAKE_PREFIX_PATH=$QT_ROOT_DIR -DUSE_CODE_COVERAGE=true -DPACKAGE_TYPE=Dmg" >> $GITHUB_ENV
#
# Install Packages (Windows)
#
- if: runner.os == 'Windows' && matrix.compiler == 'msvc'
name: Install Qt for Windows (MSVC)
uses: jurplel/install-qt-action@v4
with:
version: '6.8.3'
dir: 'C:\'
arch: win64_msvc2022_64
cache: true
modules: 'qtwebsockets qtmultimedia'
- if: runner.os == 'Windows' && matrix.compiler == 'gcc'
name: Install Qt for Windows (MinGW)
uses: jurplel/install-qt-action@v4
with:
version: '6.8.3'
dir: 'C:\'
arch: win64_mingw
cache: true
modules: 'qtwebsockets qtmultimedia'
tools: 'tools_mingw1310'
- if: runner.os == 'Windows' && matrix.compiler == 'clang'
name: Install Qt for Windows (LLVM-MinGW)
uses: jurplel/install-qt-action@v4
with:
version: '6.8.3'
dir: 'C:\'
arch: win64_llvm_mingw
cache: true
modules: 'qtwebsockets qtmultimedia'
tools: 'tools_llvm_mingw1706'
#
# Build
#
- if: runner.os == 'Windows'
name: Build MMapper for Windows
shell: pwsh
run: |
mkdir ${{ github.workspace }}/artifact
mkdir build
cd build
cmake --version
if ('${{ matrix.compiler }}' -eq 'gcc') {
echo "C:/Qt/Tools/mingw1310_64/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
$env:PATH = "C:\Qt\Tools\mingw1310_64\bin;$env:PATH"
}
if ('${{ matrix.compiler }}' -eq 'clang') {
$llvmDir = Get-ChildItem -Path "C:\Qt\Tools" -Filter "llvm-mingw*" -Directory | Sort-Object Name -Descending | Select-Object -First 1
if ($null -ne $llvmDir) {
$llvmBin = Join-Path $llvmDir.FullName "bin"
echo "$($llvmBin.Replace('\', '/'))" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
$env:PATH = "$llvmBin;$env:PATH"
$env:CC = Join-Path $llvmBin "clang.exe"
$env:CXX = Join-Path $llvmBin "clang++.exe"
} else {
Write-Error "LLVM-MinGW toolchain not found"
exit 1
}
}
$packageDir = ($env:GITHUB_WORKSPACE -replace '\\', '/') + "/artifact"
$launcher = ${{ matrix.compiler == 'msvc' && 'sccache' || 'ccache' }}
cmake -DCMAKE_BUILD_TYPE=Debug -G 'Ninja' -DWITH_MAP=OFF -DCPACK_PACKAGE_DIRECTORY="$packageDir" -DCMAKE_PREFIX_PATH=$env:QT_ROOT_DIR -DWITH_WEBSOCKET=ON -DWITH_QTKEYCHAIN=ON -DPACKAGE_TYPE=Nsis -DCMAKE_C_COMPILER_LAUNCHER="$launcher" -DCMAKE_CXX_COMPILER_LAUNCHER="$launcher" -S .. || exit 1
cmake --build . --parallel
- if: runner.os == 'Linux' || runner.os == 'macOS'
name: Build MMapper for Linux and Mac
run: |
mkdir -p build ${{ github.workspace }}/artifact
cd build
cmake --version
cmake -DCMAKE_BUILD_TYPE=Debug -G 'Ninja' -DWITH_MAP=OFF -DCPACK_PACKAGE_DIRECTORY=${{ github.workspace }}/artifact $MMAPPER_CMAKE_EXTRA -DWITH_WEBSOCKET=ON -DWITH_QTKEYCHAIN=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -S .. || exit -1
cmake --build . --parallel
#
# Run tests
#
- name: Run unit tests
run: cd build && ctest -V --no-compress-output -T test --output-junit ../ctest-to-junit-results.xml
env:
QT_QPA_PLATFORM: offscreen
ASAN_OPTIONS: detect_leaks=0
- name: Upload test results
uses: actions/upload-artifact@v7
with:
name: test-results ${{ matrix.os }} ${{ matrix.compiler }}
path: ctest-to-junit-results.xml
- if: env.COVERAGE == 'true' && !cancelled()
name: Run lcov
run: |
lcov --version
gcov --version
lcov --directory build --capture --base-directory $(pwd) --output-file build/coverage.info --gcov-tool ${GCOV_TOOL:-gcov} --no-external --ignore-errors mismatch --ignore-errors negative --ignore-errors gcov --ignore-errors inconsistent --rc geninfo_unexecuted_blocks=1
lcov --list build/coverage.info --ignore-errors inconsistent
lcov --remove build/coverage.info '*/tests/*' '*/external/*' '*/build/*' --output-file build/filtered.info --ignore-errors unused --ignore-errors inconsistent
- if: env.COVERAGE == 'true' && !cancelled()
uses: codecov/codecov-action@v7
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./build/filtered.info
fail_ci_if_error: false
continue-on-error: true
- if: env.STYLE == 'true'
name: Text Encoding Sanity Check
run: |
cd build
if [[ -n $(nm -C src/mmapper | grep -w 'QString::\(to\|from\)StdString') ]]; then
nm -C src/mmapper | grep -w 'QString::\(to\|from\)StdString'
echo
echo
echo "Please avoid using QString::fromStdString() and QString::toStdString()"
echo
echo "Both functions assume the user wants utf8, but MMapper almost always expects"
echo "std::string to have latin1 encoding."
echo
echo "Convert any uses to corresponding functions in TextUtils e.g. ::toQStringUtf8()"
exit -1
fi
#
# Package
#
- name: Package MMapper
run: cd build && cpack
- if: runner.os == 'Linux'
name: Get Linux package file base name
id: get_linux_package_name
run: |
PACKAGE_FILE=$(ls ${{ github.workspace }}/artifact/*.deb)
PACKAGE_BASENAME=$(basename "$PACKAGE_FILE" | sed 's/\./-/g')
echo "PACKAGE_BASENAME=$PACKAGE_BASENAME" >> $GITHUB_OUTPUT
- if: runner.os == 'macOS'
name: Get Mac package file base name
id: get_mac_package_name
run: |
PACKAGE_FILE=$(ls ${{ github.workspace }}/artifact/*.dmg)
PACKAGE_BASENAME=$(basename "$PACKAGE_FILE" | sed 's/\./-/g')
echo "PACKAGE_BASENAME=$PACKAGE_BASENAME" >> $GITHUB_OUTPUT
- if: runner.os == 'Windows'
name: Get Windows package file base name
id: get_windows_package_name
shell: pwsh
run: |
$packageFile = Get-ChildItem -Path "${{ github.workspace }}/artifact/*.exe" | Select-Object -First 1
$packageBasename = $packageFile.BaseName -replace '\.', '-'
"PACKAGE_BASENAME=$packageBasename" >> $env:GITHUB_OUTPUT
- if: runner.os == 'macOS'
name: Upload Package for Mac
uses: actions/upload-artifact@v7
with:
name: debug-${{ steps.get_mac_package_name.outputs.PACKAGE_BASENAME }}
path: ${{ github.workspace }}/artifact/*.dmg*
- if: runner.os == 'Linux'
name: Upload Package for Ubuntu
uses: actions/upload-artifact@v7
with:
name: debug-${{ matrix.compiler }}-${{ steps.get_linux_package_name.outputs.PACKAGE_BASENAME }}
path: ${{ github.workspace }}/artifact/*.deb*
- if: runner.os == 'Windows'
name: Upload Package for Windows
uses: actions/upload-artifact@v7
with:
name: debug-${{ matrix.compiler }}-${{ steps.get_windows_package_name.outputs.PACKAGE_BASENAME }}
path: ${{ github.workspace }}/artifact/*.exe*
report:
name: Test Report
runs-on: ubuntu-latest
needs: build
steps:
- uses: dorny/test-reporter@v3
with:
artifact: /test-results (.*)/
name: Test Report $1
path: '*.xml'
reporter: java-junit