Skip to content

Add CMake support and CI #26

Add CMake support and CI

Add CMake support and CI #26

Workflow file for this run

---
name: Build and test
on:
push:
branches: [ main ]
paths-ignore:
- "**.md"
- "LICENSE"
- ".gitignore"
- ".editorconfig"
pull_request:
branches: [ "**" ]
paths-ignore:
- "**.md"
- "LICENSE"
- ".gitignore"
- ".editorconfig"
env:
swift-version: '5.9'
jobs:
build-and-test:
name: "${{ matrix.os }}/${{ matrix.spm_configuration }}"
strategy:
fail-fast: false
matrix:
# macos-latest is apparently not the latest.
os: [macos-13, ubuntu-latest, windows-latest]
spm_configuration: [debug, release]
include:
- swift_test_options:
- spm_configuration: debug
cmake_build_type: Debug
- spm_configuration: release
cmake_build_type: Release
- os: ubuntu-latest
spm_configuration: debug
swift_test_options: --enable-code-coverage
runs-on: ${{ matrix.os }}
steps:
- uses: maxim-lobanov/setup-xcode@v1
if: ${{ matrix.os == 'macos-13' }}
with:
xcode-version: latest-stable
- name: 'Set up swift'
uses: SwiftyLab/setup-swift@latest
with:
swift-version: ${{ env.swift-version }}
- name: Verify swift version
run: swift --version && swift --version | grep -q ${{ env.swift-version }}
shell: bash
# Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if
# not already: on subsequent runs both will be quickly restored from GitHub cache service.
- uses: lukka/get-cmake@latest
- name: Checkout (GitHub)
uses: actions/checkout@v4
with:
submodules: true
show-progress: false
- name: Configure (CMake)
# We explicitly point to swiftc in the PATH because otherwise CMake picks up the one in XCode.
run: >-
cmake -GNinja -S . -B .cmake-build
-DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }}
-DBUILD_TESTING=YES
${{ matrix.os == 'macos-13' && '-D CMAKE_Swift_COMPILER=swiftc' || '' }}
- name: Build (CMake)
run: cmake --build .cmake-build
- name: Test (CMake)
run: ctest -V --test-dir .cmake-build
- name: CMake => Xcode
if: ${{ matrix.os == 'macos-13' }}
# We explicitly point to swiftc in the PATH because otherwise CMake picks up the one in XCode.
run: >-
cmake -GXcode -S . -B .xcode-build
-DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }}
-DBUILD_TESTING=YES
${{ matrix.os == 'macos-13' && '-D CMAKE_Swift_COMPILER=swiftc' || '' }}
cd .xcode-build
xcrun xcodebuild -configuration ${{ matrix.spm_configuration }} -scheme Durian -destination 'platform=macOS' test
- name: Build and Test via SPM
run: swift test -v ${{ matrix.swift_test_options }} -c ${{ matrix.spm_configuration }}
- name: Export Coverage
if: ${{ contains(matrix.swift_test_options, '--enable-code-coverage') }}
run: |
shopt -s nullglob
dot_os=(.build/${{ matrix.spm_configuration }}/*.build/*.o .build/${{ matrix.spm_configuration }}/*.build/**/*.o)
bin_params=("${dot_os[0]}")
for o in "${dot_os[@]:1}"; do
bin_params+=("-object" "${o}")
done
# Note: on mac this command might require a leading xcrun.
llvm-cov export -format="lcov" -instr-profile "$(swift test -c ${{ matrix.spm_configuration }} --show-codecov-path | xargs dirname)"/default.profdata "${bin_params[@]}" > info.lcov
- name: Upload coverage reports to Codecov
if: ${{ contains(matrix.swift_test_options, '--enable-code-coverage') }}
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true