Files
Cory Benfield 5f212faeb0 Enable CMake testing with a wider range of compilers. (#3796)
Motivation:

On Linux and Darwin we may use different compilers with CMake. It's
helpful to be able to test a wide range, and it is necessary for some CI
testing.

Modifications:

Enable overriding the compilers in the CMake test jobs.

Result:

Better testability.
2026-11-23 17:39:41 +00:00

72 lines
2.9 KiB
YAML

name: CMake build
permissions:
contents: read
on:
workflow_call:
inputs:
update_cmake_lists_config:
type: string
description: "The configuration used when updating the CMake lists."
required: true
cmake_build_target_directory:
type: string
description: "The directory to pass to `cmake build`."
default: "."
cmake_version:
type: string
description: "The version of CMake to install."
default: ""
image:
type: string
description: "The docker image to run the checks in."
default: "swift:6.0-jammy"
c_compiler:
type: string
description: "The C compiler to use for the CMake build, exported as `CC`. If empty, `CC` is left as it is."
default: ""
cxx_compiler:
type: string
description: "The C++ compiler to use for the CMake build, exported as `CXX`. If empty, `CXX` is left as it is."
default: ""
jobs:
cmake-checks:
name: CMake checks
runs-on: ubuntu-latest
container:
image: ${{ inputs.image }}
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
submodules: true
- name: Mark the workspace as safe
# https://github.com/actions/checkout/issues/766
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: Check CMakeLists files
run: |
which curl jq || apt -q update
which curl || apt -yq install curl
which jq || apt -yq install jq
curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/update-cmake-lists.sh | CONFIG_JSON="$INPUT_UPDATE_CMAKE_LISTS_CONFIG" FAIL_ON_CHANGES=true bash
env:
INPUT_UPDATE_CMAKE_LISTS_CONFIG: ${{ inputs.update_cmake_lists_config }}
- name: CMake build
run: |
# Only override CC and CXX when a compiler was requested: they may be set by the image.
if [ -n "$INPUT_C_COMPILER" ]; then export CC="$INPUT_C_COMPILER"; fi
if [ -n "$INPUT_CXX_COMPILER" ]; then export CXX="$INPUT_CXX_COMPILER"; fi
which curl cmake ninja || apt -q update
which curl || apt -yq install curl
which cmake || apt -yq install cmake
which ninja || apt -yq install ninja-build
curl -s --retry 3 https://raw.githubusercontent.com/apple/swift-nio/main/scripts/cmake-build.sh | TARGET_DIRECTORY="$INPUT_CMAKE_BUILD_TARGET_DIRECTORY" CMAKE_VERSION="$INPUT_CMAKE_VERSION" bash
env:
INPUT_CMAKE_BUILD_TARGET_DIRECTORY: ${{ inputs.cmake_build_target_directory }}
INPUT_CMAKE_VERSION: ${{ inputs.cmake_version }}
INPUT_C_COMPILER: ${{ inputs.c_compiler }}
INPUT_CXX_COMPILER: ${{ inputs.cxx_compiler }}