Skip to content

CMake Support

CMake Support #211

Workflow file for this run

---
name: Test
on:
push:
branches: [ main ]
paths-ignore:
- "**.md"
- "LICENSE"
- ".gitignore"
pull_request:
branches: [ "**" ]
paths-ignore:
- "**.md"
- "LICENSE"
- ".gitignore"
env:
swift-version: '5.9'
jobs:
dev-container:
name: "Dev container: ${{ matrix.cmake_build_type }}"
strategy:
fail-fast: false
matrix:
cmake_build_type: [Debug, Release]
include:
- cmake_build_type: Debug
spm_configuration: debug
HYLO_LLVM_BUILD_TYPE: Debug
- cmake_build_type: Release
spm_configuration: release
HYLO_LLVM_BUILD_TYPE: MinSizeRel
runs-on: ubuntu-latest
steps:
- name: Checkout (GitHub)
uses: actions/checkout@v4
with:
submodules: true
show-progress: false
- name: Build and run via SPM
uses: devcontainers/[email protected]
env:
HYLO_LLVM_BUILD_TYPE: ${{ matrix.HYLO_LLVM_BUILD_TYPE }}
with:
runCmd: swift test --parallel -c ${{ matrix.spm_configuration }}
push: never
- name: Build and run via CMake
uses: devcontainers/[email protected]
env:
HYLO_LLVM_BUILD_TYPE: ${{ matrix.HYLO_LLVM_BUILD_TYPE }}
with:
runCmd: >-
cmake -GNinja -S . -B .cmake-build
-DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }}
-DENABLE_TESTING=YES
-DLLVM_DIR=/opt/llvm-${{ matrix.HYLO_LLVM_BUILD_TYPE }}/lib/cmake/llvm
cmake --build .cmake-build
ctest -V --test-dir .cmake-build
push: never
native:
name: "Native: ${{ matrix.os }}/${{ matrix.spm_configuration }}"
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]
spm_configuration: [debug, release]
include:
- HYLO_LLVM_DOWNLOAD_URL: https://github.com/hylo-lang/llvm-build/releases/download
- HYLO_LLVM_BUILD_RELEASE: 20240303-215025
- HYLO_LLVM_VERSION: 17.0.6
- swift_test_options:
- unpackage_command: tar -x --zstd -f
- package_suffix: .tar.zst
- spm_configuration: debug
cmake_build_type: Debug
HYLO_LLVM_BUILD_TYPE: Debug
- spm_configuration: release
cmake_build_type: Release
HYLO_LLVM_BUILD_TYPE: MinSizeRel
- os: windows-latest
unpackage_command: 7z x -t7z
package_suffix: .7z
triple_suffix: unknown-windows-msvc17
- os: ubuntu-latest
triple_suffix: unknown-linux-gnu
- os: macos-latest
triple_suffix: apple-darwin23.3.0
- os: ubuntu-latest
spm_configuration: release
swift_test_options: --enable-code-coverage
runs-on: ${{ matrix.os }}
env:
url_prefix: ${{ matrix.HYLO_LLVM_DOWNLOAD_URL }}/${{ matrix.HYLO_LLVM_BUILD_RELEASE }}
package_basename: llvm-${{ matrix.HYLO_LLVM_VERSION }}-x86_64-${{ matrix.triple_suffix }}-${{ matrix.HYLO_LLVM_BUILD_TYPE }}
steps:
- name: Prerequisites (macOS)
if: ${{ matrix.os == 'macos-latest' }}
run: brew install zstd
- name: Prerequisites (Linux)
if: ${{ matrix.os == 'ubuntu-latest' }}
run: sudo apt update && sudo apt install -y ninja-build
- name: 'Set up swift (*nix)'
if: ${{ matrix.os != 'windows-latest' }}
uses: swift-actions/setup-swift@v1
with:
swift-version: ${{ env.swift-version }}
- name: Set up swift (Windows)
if: ${{ matrix.os == 'windows-latest' }}
uses: compnerd/[email protected]
with:
branch: swift-${{ env.swift-version }}-release
tag: ${{ env.swift-version }}-RELEASE
- name: Install LLVM
# 7z doesn't support decompressing from a stream or we'd do
# this all as one statement. Maybe we should find a way to use
# zstd on windows.
run: >-
curl --no-progress-meter -L -O
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}"
${{ env.url_prefix }}/${{ env.package_basename }}${{ matrix.package_suffix }}
${{ matrix.unpackage_command }} ${{ env.package_basename }}${{ matrix.package_suffix }}
- name: Checkout (GitHub)
uses: actions/checkout@v4
with:
submodules: true
show-progress: false
path: Swifty-LLVM
- name: Create LLVM pkgconfig file and make it findable
run: >-
set -ex -o pipefail
mkdir pkg-config
PATH="${{ github.workspace }}/${{ env.package_basename }}/bin:$PATH"
Swifty-LLVM/Tools/make-pkgconfig.sh pkg-config/llvm.pc
echo 'PKG_CONFIG_PATH=${{ github.workspace }}/pkg-config' >> $GITHUB_ENV
shell: bash
- name: Build and Test via SPM
run: swift test -v ${{ matrix.swift_test_options }} -c ${{ matrix.spm_configuration }}
working-directory: Swifty-LLVM
- name: Export Coverage
if: ${{ contains(matrix.swift_test_options, '--enable-code-coverage') }}
working-directory: Swifty-LLVM
run: |
dot_os=(.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: Build and Test via CMake
run: >-
cmake -GNinja -S . -B .cmake-build
-DCMAKE_BUILD_TYPE=${{ matrix.cmake_build_type }}
-DENABLE_TESTING=YES
-DLLVM_DIR=/opt/llvm-${{ matrix.HYLO_LLVM_BUILD_TYPE }}/lib/cmake/llvm
cmake --build .cmake-build
ctest -V --test-dir .cmake-build
working-directory: Swifty-LLVM
- 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
directory: ${{ github.workspace }}/Swifty-LLVM
working-directory: ${{ github.workspace }}/Swifty-LLVM
root_dir: ${{ github.workspace }}/Swifty-LLVM