Skip to content

Commit 977d721

Browse files
committed
ci: add github actions jobs testing gcc, clang-20, clang-tidy, and iwyu
1 parent 0d5f1fa commit 977d721

File tree

9 files changed

+119
-4
lines changed

9 files changed

+119
-4
lines changed

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
config: [default, llvm]
15+
16+
name: build • ${{ matrix.config }}
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Install Nix
22+
uses: cachix/install-nix-action@v31 # 2025-05-27, from https://github.com/cachix/install-nix-action/tags
23+
with:
24+
nix_path: nixpkgs=channel:nixos-25.05 # latest release
25+
26+
- name: Run CI script
27+
env:
28+
CI_CONFIG: ci/configs/${{ matrix.config }}.sh
29+
run: ci/scripts/run.sh

CMakeLists.txt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,32 @@ include("cmake/compat_find.cmake")
1515
find_package(CapnProto REQUIRED)
1616
find_package(Threads REQUIRED)
1717

18-
option(Libmultiprocess_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
19-
if(Libmultiprocess_ENABLE_CLANG_TIDY)
18+
set(MPGEN_EXECUTABLE "" CACHE FILEPATH "If specified, should be full path to an external mpgen binary to use rather than the one built internally.")
19+
20+
option(MP_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
21+
if(MP_ENABLE_CLANG_TIDY)
2022
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy)
2123
if(NOT CLANG_TIDY_EXECUTABLE)
22-
message(FATAL_ERROR "Libmultiprocess_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.")
24+
message(FATAL_ERROR "MP_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.")
2325
endif()
2426
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")
27+
28+
# Workaround for nix from https://gitlab.kitware.com/cmake/cmake/-/issues/20912#note_793338
29+
# Nix injects header paths via $NIX_CFLAGS_COMPILE; CMake tags these as
30+
# CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES and omits them from the compile
31+
# database, so clang-tidy, which ignores $NIX_CFLAGS_COMPILE, can't find capnp
32+
# headers. Setting them as standard passes them to clang-tidy.
33+
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
2534
endif()
2635

27-
set(MPGEN_EXECUTABLE "" CACHE FILEPATH "If specified, should be full path to an external mpgen binary to use rather than the one built internally.")
36+
option(MP_ENABLE_IWYU "Run include-what-you-use with the compiler." OFF)
37+
if(MP_ENABLE_IWYU)
38+
find_program(IWYU_EXECUTABLE NAMES include-what-you-use iwyu)
39+
if(NOT IWYU_EXECUTABLE)
40+
message(FATAL_ERROR "MP_ENABLE_IWYU is ON but include-what-you-use was not found.")
41+
endif()
42+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXECUTABLE};-Xiwyu;--error")
43+
endif()
2844

2945
include("cmake/compat_config.cmake")
3046
include("cmake/pthread_checks.cmake")
@@ -51,6 +67,7 @@ configure_file(include/mp/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/mp/co
5167

5268
# Generated C++ Capn'Proto schema files
5369
capnp_generate_cpp(MP_PROXY_SRCS MP_PROXY_HDRS include/mp/proxy.capnp)
70+
set_source_files_properties("${MP_PROXY_SRCS}" PROPERTIES SKIP_LINTING TRUE) # Ignored before cmake 3.27
5471

5572
# util library
5673
add_library(mputil OBJECT src/mp/util.cpp)

ci/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
### CI quick-reference
2+
3+
All CI is just bash and nix.
4+
5+
* **Workflow**:
6+
- `.github/workflows/ci.yml` – lists the jobs (`default`, `llvm`, …).
7+
* **Scripts**:
8+
- `ci/scripts/run.sh` – spins up the Nix shell then calls…
9+
- `ci/scripts/ci.sh` – …to configure, build, and test.
10+
* **Configuration**:
11+
- `ci/configs/*.sh` – defines flags for each job.
12+
- `shell.nix` – defines build environment (compilers, tools, libraries).
13+
* **Build directories**:
14+
- `build-*/` – separate build directories (like `build-default`, `build-llvm`) will be created for each job.
15+
16+
To run jobs locally:
17+
18+
```bash
19+
CI_CONFIG=ci/configs/default.sh ci/scripts/run.sh
20+
CI_CONFIG=ci/configs/llvm.sh ci/scripts/run.sh
21+
```
22+
23+
By default CI jobs will reuse their build directories. `CI_CLEAN=1` can be specified to delete them before running instead.

ci/configs/default.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
CI_DESC="CI job using default libraries and tools"
2+
CI_DIR=build-default
3+
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter"
4+
BUILD_ARGS=(-k)

ci/configs/llvm.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CI_DESC="CI job using LLVM-based tools (clang, clang-tidy, iwyu) and testing Ninja"
2+
CI_DIR=build-llvm
3+
export CXX=clang++
4+
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wthread-safety-analysis -Wno-unused-parameter"
5+
CMAKE_ARGS=(
6+
-G Ninja
7+
-DMP_ENABLE_CLANG_TIDY=ON
8+
-DMP_ENABLE_IWYU=ON
9+
)
10+
BUILD_ARGS=(-k 0)

ci/scripts/ci.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset -o pipefail -o xtrace
3+
4+
[ "${CI_CONFIG+x}" ] && source "$CI_CONFIG"
5+
6+
: "${CI_DIR:=build}"
7+
8+
[ -n "${CI_CLEAN-}" ] && rm -rf "${CI_DIR}"
9+
10+
cmake -B "$CI_DIR" "${CMAKE_ARGS[@]+"${CMAKE_ARGS[@]}"}"
11+
cmake --build "$CI_DIR" -t all tests mpexamples -- "${BUILD_ARGS[@]+"${BUILD_ARGS[@]}"}"
12+
ctest --test-dir "$CI_DIR" --output-on-failure

ci/scripts/run.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset -o pipefail -o xtrace
3+
4+
nix-shell --pure --keep CI_CONFIG --keep CI_CLEAN --run ci/scripts/ci.sh shell.nix

cmake/TargetCapnpSources.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function(target_capnp_sources target include_prefix)
8181
DEPENDS ${capnp_file}
8282
VERBATIM
8383
)
84+
# Skip linting for capnp-generated files but keep it for mpgen-generated ones
85+
set_source_files_properties(${capnp_file}.c++ PROPERTIES SKIP_LINTING TRUE) # Ignored before cmake 3.27
8486
target_sources(${target} PRIVATE
8587
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.c++
8688
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-client.c++

shell.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{ pkgs ? import <nixpkgs> {} }:
2+
3+
pkgs.mkShell {
4+
buildInputs = with pkgs; [
5+
capnproto
6+
];
7+
nativeBuildInputs = with pkgs; [
8+
cmake
9+
include-what-you-use
10+
llvmPackages_20.clang
11+
llvmPackages_20.clang-tools
12+
ninja
13+
];
14+
}

0 commit comments

Comments
 (0)