Skip to content

Commit

Permalink
build with vcpkg on Windows & macOS; add Qt6 builds to CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Be-ing committed Mar 8, 2022
1 parent 9795787 commit e6a49b5
Show file tree
Hide file tree
Showing 7 changed files with 380 additions and 37 deletions.
247 changes: 210 additions & 37 deletions .github/workflows/github-cxx-qt-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,214 @@
name: cxx-qt tests
on: [push, pull_request]
jobs:
ctest:
runs-on: ubuntu-20.04
build:
strategy:
fail-fast: false
matrix:
include:
- name: Ubuntu 20.04 (gcc) Qt5
os: ubuntu-20.04
rust_triple: x86_64-unknown-linux-gnu
cmake_args: >-
-D QT6=OFF
qt_select_version: qt5
qt_qpa_platform: offscreen
compiler_cache_path: ~/.cache/sccache
cargo_dir: ~/.cargo
# TODO: Remove PPA for Qt 5.15 when Ubuntu 22.04 is available
ppa: ppa:savoury1/qt-5-15
packages-extra: >-
qtbase5-dev
qtdeclarative5-dev
qtquickcontrols2-5-dev
qml-module-qtquick2
qml-module-qtquick-controls2
qml-module-qttest
workspace: /home/runner/cxx-qt
- name: Ubuntu 20.04 (gcc) Qt6
os: ubuntu-20.04
rust_triple: x86_64-unknown-linux-gnu
cmake_args: >-
-D QT6=ON
# FIXME: fix valgrind failures
ctest_args: --exclude-regex '^.*valgrind$'
qt_select_version: qt6
qt_qpa_platform: offscreen
compiler_cache_path: ~/.cache/sccache
cargo_dir: ~/.cargo
# TODO: Remove PPA for Qt 6 when Ubuntu 22.04 is available
ppa: ppa:daschuer/qt6-backports
packages-extra: >-
qt6-base-dev
qt6-declarative-dev
qt6-declarative-dev-tools
qml6-module-qtquick-controls
qml6-module-qtquick-window
qml6-module-qttest
qml6-module-qtqml-workerscript
libgl1-mesa-dev
libvulkan-dev
libxkbcommon-dev
workspace: /home/runner/cxx-qt
- name: macOS 11 (clang) Qt5
os: macos-11
rust_triple: x86_64-apple-darwin
cmake_args: >-
-D QT6=OFF
# FIXME: qmltestrunner fails to import QtQuick module
ctest_args: --exclude-regex '^(example_qml_extension_plugin_test|reuse_lint|.*valgrind)$'
qt_qpa_platform: cocoa
compiler_cache_path: ~/.cache/sccache
cargo_dir: ~/.cargo
workspace: /Users/runner/cxx-qt
- name: macOS 11 (clang) Qt6
os: macos-11
rust_triple: x86_64-apple-darwin
cmake_args: >-
-D QT6=ON
# FIXME: qmltestrunner fails to import QtQuick module
ctest_args: --exclude-regex '^(example_qml_extension_plugin_test|reuse_lint|.*valgrind)$'
qt_qpa_platform: cocoa
compiler_cache_path: ~/.cache/sccache
cargo_dir: ~/.cargo
workspace: /Users/runner/cxx-qt
- name: Windows 2022 (MSVC) Qt5
os: windows-2022
rust_triple: x86_64-pc-windows-msvc
cmake_args: >-
-D QT6=OFF
ctest_args: --exclude-regex '^(reuse_lint|.*valgrind)$'
exe_suffix: .exe
qt_qpa_platform: windows
compiler_cache_path: C:\Users\runneradmin\AppData\Local\Mozilla\sccache\cache
cargo_dir: C:\Users\runneradmin\.cargo
cc: cl
cxx: cl
# The D drive runs out of space when building dependencies with vcpkg.
workspace: C:\cxx-qt
- name: Windows 2022 (MSVC) Qt6
os: windows-2022
rust_triple: x86_64-pc-windows-msvc
cmake_args: >-
-D QT6=ON
ctest_args: --exclude-regex '^(reuse_lint|.*valgrind)$'
exe_suffix: .exe
qt_qpa_platform: windows
compiler_cache_path: C:\Users\runneradmin\AppData\Local\Mozilla\sccache\cache
cargo_dir: C:\Users\runneradmin\.cargo
cc: cl
cxx: cl
# The D drive runs out of space when building dependencies with vcpkg.
workspace: C:\cxx-qt

runs-on: ${{ matrix.os }}
name: ${{ matrix.name }}

steps:
- uses: actions/checkout@v2
# Install Rust toolchain
- uses: actions-rs/toolchain@v1
with:
components: clippy, rustfmt
toolchain: stable
# Instal mdbook and mdbook-linkcheck
- name: Install mdbook and mdbook-linkcheck from binaries
run: |
mkdir mdbook
curl -sSL https://github.com/rust-lang/mdBook/releases/download/v0.4.14/mdbook-v0.4.14-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
echo `pwd`/mdbook >> $GITHUB_PATH
curl -sSL https://github.com/Michael-F-Bryan/mdbook-linkcheck/releases/latest/download/mdbook-linkcheck.x86_64-unknown-linux-gnu.zip -o mdbook-linkcheck.zip
unzip mdbook-linkcheck.zip -d mdbook-linkcheck/
rm mdbook-linkcheck.zip
chmod +x ./mdbook-linkcheck/mdbook-linkcheck
echo `pwd`/mdbook-linkcheck >> $GITHUB_PATH
# FIXME: FUTURE: Remove PPA for Qt 5.15 once 22.04 is available
# https://launchpad.net/~savoury1/+archive/ubuntu/qt-5-15
- run: sudo add-apt-repository ppa:savoury1/qt-5-15
# Install clang-format, Qt, reuse, valgrind
- run: sudo apt-get update
- run: sudo apt-get install -y clang-format-12 libssl-dev pkg-config python3-pip qtbase5-dev qtdeclarative5-dev qtquickcontrols2-5-dev qml-module-qtquick2 qml-module-qtquick-controls2 qml-module-qttest valgrind
- run: sudo ln -s /usr/bin/clang-format-12 /usr/local/bin/clang-format
- run: pip3 install reuse
# Ensure we have a clean build folder
- run: rm -rf build/
- run: mkdir -p build/
# Configure and build CMake then run ctest
#
# Note that each github action run command is executed from the same directory even after
# performing cd so for the ctest line we need to cd within the same command
- run: cmake -S. -Bbuild/ -G "Unix Makefiles"
- run: cmake --build build/ --config Debug --target all -j$(nproc)
- run: (cd build/ && QT_QPA_PLATFORM=offscreen ctest -j$(nproc) -C Debug -T test --output-on-failure)
- name: "Clone Git repository"
uses: LebedevRI/checkout@issue197
with:
path: ${{ matrix.workspace }}
- name: "Install Rust toolchain"
uses: actions-rs/toolchain@v1
with:
components: clippy, rustfmt
toolchain: stable

- name: "Rust tools cache"
uses: actions/cache@v2
id: rust-tools-cache
with:
path: |
${{ matrix.cargo_dir }}/bin/sccache${{ matrix.exe_suffix }}
${{ matrix.cargo_dir }}/bin/mdbook${{ matrix.exe_suffix }}
${{ matrix.cargo_dir }}/bin/mdbook-linkcheck${{ matrix.exe_suffix }}
key: ${{ matrix.os }}_sccache-0.2.15_mdbook-0.4.15_mdbook-linkcheck-0.2.8

- name: "Build Rust tools"
if: steps.rust-tools-cache.outputs.cache-hit != 'true'
run: cargo install sccache mdbook mdbook-linkcheck

- name: "Compiler cache"
uses: actions/cache@v2
with:
path: ${{ matrix.compiler_cache_path }}
key: ${{ matrix.name }}-${{ github.head_ref }}-${{ github.run_number }}
restore-keys: |
${{ matrix.name }}-${{ github.head_ref }}
${{ matrix.name }}
- name: "[Ubuntu] Install dependencies"
if: runner.os == 'Linux'
run: >-
sudo add-apt-repository ${{ matrix.ppa }} &&
sudo apt-get update &&
sudo apt-get install -y
ninja-build
clang-format-12
libssl-dev
pkg-config
python3-pip
valgrind
${{ matrix.packages-extra }}
- name: "[macOS] Install dependencies"
if: runner.os == 'macOS'
# automake is needed for building libicu which is a dependency of Qt
run: |
brew install automake ninja clang-format
- name: "Install reuse"
if: runner.os == 'Linux'
run: pip3 install reuse

- name: "Authenticate to GitHub Packages"
# TODO: replace 'Be-ing' with 'KDAB'
if: runner.os != 'Linux' && github.repository_owner == 'Be-ing'
shell: bash
run: |
nuget sources add -Name cxx-qt-github-packages -Source https://nuget.pkg.github.com/Be-ing/index.json -Username Be-ing -Password ${{ secrets.GITHUB_TOKEN }} -NonInteractive
nuget setapikey ${{ secrets.GITHUB_TOKEN }} -Source cxx-qt-github-packages -NonInteractive
echo "VCPKG_BINARY_SOURCES=clear;nuget,cxx-qt-github-packages,readwrite;" >> "${GITHUB_ENV}"
# Required for CMake to find Ninja
- name: "[Windows] Set up MSVC Developer Command Prompt"
if: runner.os == 'Windows'
uses: seanmiddleditch/gha-setup-vsdevenv@v3

# Ninja is required on Windows for CMAKE_CXX_COMPILER_LAUNCHER to have an effect.
- name: "Configure"
run: >-
cmake
${{ matrix.cmake_args}}
-D CMAKE_BUILD_TYPE=Debug
-G Ninja
-S . -B build
working-directory: ${{ matrix.workspace }}
env:
RUSTC_WRAPPER: sccache
CC: ${{ matrix.cc }}
CXX: ${{ matrix.cxx }}
- name: "Build"
run: cmake --build build --config Debug --parallel 2
working-directory: ${{ matrix.workspace }}
env:
RUSTC_WRAPPER: sccache
CMAKE_C_COMPILER_LAUNCHER: sccache
CMAKE_CXX_COMPILER_LAUNCHER: sccache
- name: "Test"
run: ctest ${{ matrix.ctest_args }} -C Debug -T test --output-on-failure --parallel 2
working-directory: ${{ matrix.workspace }}/build
env:
RUSTC_WRAPPER: sccache
QT_QPA_PLATFORM: ${{ matrix.qt_qpa_platform }}
QT_SELECT: ${{ matrix.qt_select_version }}

- name: Upload GitHub Actions artifacts of vcpkg logs
if: always()
uses: actions/upload-artifact@v2
with:
name: vcpkg-logs-${{ matrix.name }}
path: |
${{ matrix.workspace }}/vcpkg/buildtrees/**/*.log
${{ matrix.workspace }}/build/vcpkg-bootstrap.log
${{ matrix.workspace }}/build/vcpkg-manifest-install.log
if-no-files-found: ignore
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# SPDX-FileCopyrightText: Be <[email protected]>
# SPDX-License-Identifier: MIT OR Apache-2.0
[submodule "vcpkg"]
path = vcpkg
url = https://github.com/microsoft/vcpkg.git
86 changes: 86 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,92 @@ cmake_minimum_required(VERSION 3.16)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option(QT6 "Build with Qt6" OFF)

# Set up vcpkg
if(WIN32 OR APPLE)
option(VCPKG "Use vcpkg for dependencies" ON)
else()
option(VCPKG "Use vcpkg for dependencies" OFF)
endif()

if(VCPKG)
if(QT6)
set(VCPKG_MANIFEST_FEATURES "qt6")
else()
set(VCPKG_MANIFEST_FEATURES "qt5")
endif()

include(InitializeVcpkg)

# These are required for binary caching to work reliably across machines.
set(VCPKG_FEATURE_FLAGS "-compilertracking")
set(VCPKG_INSTALL_OPTIONS "--x-abi-tools-use-exact-versions")

if(NOT DEFINED ENV{VCPKG_BINARY_SOURCES})
if(WIN32)
set(COMMAND_PREIFX "")
set(EXE_SUFFIX ".exe")
set(SCRIPT_SUFFIX ".bat")
set(DOTNET_RUNTIME "")
else()
set(COMMAND_PREFIX "./")
set(EXE_SUFFIX "")
set(SCRIPT_SUFFIX ".sh")
set(DOTNET_RUNTIME "mono")
endif()

# vcpkg can download NuGet, so bootstrap vcpkg if the executable is not found.
if(NOT EXISTS "${VCPKG_ROOT}/vcpkg${EXE_SUFFIX}")
message(STATUS "Bootstrapping vcpkg")
execute_process(
COMMAND "${COMMAND_PREFIX}bootstrap-vcpkg${SCRIPT_SUFFIX}"
WORKING_DIRECTORY ${VCPKG_ROOT}
)
endif()

message(STATUS "Setting up vcpkg binary caching with read-only access to GitHub Packages NuGet source")

execute_process(
COMMAND "${COMMAND_PREFIX}vcpkg${EXE_SUFFIX}" fetch nuget
WORKING_DIRECTORY ${VCPKG_ROOT}
OUTPUT_VARIABLE NUGET_FETCH_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REPLACE "\n" ";" NUGET_FETCH_OUTPUT "${NUGET_FETCH_OUTPUT}")
list(POP_BACK NUGET_FETCH_OUTPUT NUGET_EXECUTABLE)

# NuGet will fail with an error when trying to add a source with the same name
# as one that already exists, so check that the NuGet source has not been added yet.
execute_process(
COMMAND ${DOTNET_RUNTIME} ${NUGET_EXECUTABLE} sources list
OUTPUT_VARIABLE NUGET_SOURCES_LIST
)
string(FIND "${NUGET_SOURCES_LIST}" "cxx-qt-github-packages" SEARCH_RESULT)
if(SEARCH_RESULT EQUAL -1)
# GitHub will deactivate a personal access token that gets committed to the repository.
# Hack around this by splitting up the PAT.
# This is safe because this PAT only has read:packages permission.
# TODO: create read-only personal access token for KDAB
set(GITHUB_PAT_READ_PACKAGES_SUFFIX DX2hOAAmXO4JGuT4WK5LQLBIGLSAdo13PDC1)
execute_process(
COMMAND ${DOTNET_RUNTIME} ${NUGET_EXECUTABLE} sources add
-name mixxx-github-packages
-source https://nuget.pkg.github.com/Be-ing/index.json
-username Be-ing
-password ghp_${GITHUB_PAT_READ_PACKAGES_SUFFIX}
)
endif()

set(ENV{VCPKG_BINARY_SOURCES} "clear;default,readwrite;nuget,cxx-qt-github-packages,read;")
endif()
else()
message(STATUS "Using dependencies from system without vcpkg")
endif()

project(cxx_qt)

set(CMAKE_CXX_STANDARD 17)
Expand Down
Loading

0 comments on commit e6a49b5

Please sign in to comment.