Files
Rick Newton-Rogers 4582f55c0d A re-usable CMake check workflow (#3144)
### Motivation

A few repositories have custom workflows for checking CMake, we would
like to unify this for maintenance and adoption simplicity.

Further to this at the moment they only check that the scripts are
up-to-date, we'd also like to have them build using CMake.

### Modifications

Add the re-usable workflow and supporting scripts

### Result:

Repositories using CMake can switch to the centralised workflow.

An example of it in action
https://github.com/apple/swift-crypto/actions/runs/13837092514/job/38782284575
2025-03-14 15:09:21 +00:00

42 lines
1.5 KiB
Bash
Executable File

#!/bin/bash
##===----------------------------------------------------------------------===##
##
## This source file is part of the SwiftNIO open source project
##
## Copyright (c) 2025 Apple Inc. and the SwiftNIO project authors
## Licensed under Apache License v2.0
##
## See LICENSE.txt for license information
## See CONTRIBUTORS.txt for the list of SwiftNIO project authors
##
## SPDX-License-Identifier: Apache-2.0
##
##===----------------------------------------------------------------------===##
set -uo pipefail
log() { printf -- "** %s\n" "$*" >&2; }
error() { printf -- "** ERROR: %s\n" "$*" >&2; }
fatal() { error "$@"; exit 1; }
target_dir="${TARGET_DIRECTORY:=""}"
if [ -z "$target_dir" ]; then
fatal "Target directory must be specified."
fi
CURL_BIN="${CURL_BIN:-$(which curl)}" || fatal "CURL_BIN unset and no curl on PATH"
TAR_BIN="${TAR_BIN:-$(which tar)}" || fatal "TAR_BIN unset and no tar on PATH"
CMAKE_BIN="${CMAKE_BIN:-$(which cmake)}" || fatal "CMAKE_BIN unset and no cmake on PATH"
NINJA_BIN="${NINJA_BIN:-$(which ninja)}" || fatal "NINJA_BIN unset and no ninja on PATH"
ASSEMBLY_COMPILER_BIN="${ASSEMBLY_COMPILER_BIN:-$(which clang)}" || fatal "ASSEMBLY_COMPILER_BIN unset and no clang on PATH"
log "Building Ninja build files for target"
build_dir="${target_dir}/build"
mkdir -p "$build_dir"
cd "${build_dir}" || fatal "Could not 'cd' to ${build_dir}"
ASM="$ASSEMBLY_COMPILER_BIN" "$CMAKE_BIN" build -G Ninja -S ..
log "Building target"
"$NINJA_BIN"