Skip to content

Commit 6d7b261

Browse files
committed
ci: add github actions job testing clang-20, clang-tidy, and iwyu
1 parent 996281b commit 6d7b261

File tree

7 files changed

+78
-4
lines changed

7 files changed

+78
-4
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Install Nix
15+
uses: cachix/install-nix-action@v31 # 2025-05-27, from https://github.com/cachix/install-nix-action/tags
16+
with:
17+
nix_path: nixpkgs=channel:nixos-25.05 # latest release
18+
19+
- name: Configure, build, test
20+
run: |
21+
nix-shell --pure --run "ci/scripts/configure.sh"
22+
nix-shell --pure --run "ci/scripts/build.sh"
23+
nix-shell --pure --run "ci/scripts/test.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)
5471

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

ci/scripts/build.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 -euo pipefail
3+
4+
cmake --build build -t all tests mpexamples -- -k 0

ci/scripts/configure.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cmake -B build -G Ninja \
5+
-DCMAKE_BUILD_TYPE=Debug \
6+
-DCMAKE_CXX_COMPILER=clang++ \
7+
-DCMAKE_CXX_FLAGS="-Wall -Wextra -Wpedantic -Wthread-safety-analysis -Wno-unused-parameter" \
8+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
9+
-DMP_ENABLE_CLANG_TIDY=ON \
10+
-DMP_ENABLE_IWYU=ON

ci/scripts/test.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 -euo pipefail
3+
4+
ctest --test-dir build --output-on-failure

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)
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)